Compare commits
10 Commits
1913d7d7d4
...
b3158bdc37
| Author | SHA1 | Date | |
|---|---|---|---|
| b3158bdc37 | |||
| 4907c9cadf | |||
| 45f2e746d6 | |||
| 8e8d181c34 | |||
| 5379e30cf3 | |||
| d3fb12703c | |||
| f9c539a854 | |||
| a777241d7a | |||
| 34340d9664 | |||
| 6a39128962 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
mranderson.lua
|
||||
impostor.lua
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
environment: &environment
|
||||
GAME_NAME: mranderson
|
||||
GAME_NAME: impostor
|
||||
GAME_LANG: lua
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: gitea.vps.teletype.hu/games/tic80pro:latest
|
||||
image: git.teletype.hu/internal/tic80pro:latest
|
||||
environment:
|
||||
<<: *environment
|
||||
XDG_RUNTIME_DIR: /tmp
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# TIC-80 Lua Code Regularities
|
||||
|
||||
Based on the analysis of `mranderson.lua`, the following regularities and conventions should be followed for future modifications and development within this project:
|
||||
Based on the analysis of `impostor.lua`, the following regularities and conventions should be followed for future modifications and development within this project:
|
||||
|
||||
## General Structure & Lifecycle
|
||||
|
||||
@@ -39,7 +39,7 @@ Based on the analysis of `mranderson.lua`, the following regularities and conven
|
||||
|
||||
11. **`spr()` for Sprites:** Individual sprites should be rendered using the `spr()` function.
|
||||
12. **`map()` for Maps:** Tilemaps should be drawn using the `map()` function.
|
||||
13. **`print()` for Text:** Text display should utilize the `print()` function.
|
||||
13. **`Print.text()` for Text:** Text display should utilize the `Print.text()` function.
|
||||
|
||||
## Code Style
|
||||
|
||||
|
||||
8
Makefile
8
Makefile
@@ -1,10 +1,10 @@
|
||||
# -----------------------------------------
|
||||
# Makefile – TIC-80 project builder
|
||||
# Usage:
|
||||
# make PROJECT=mranderson
|
||||
# make build PROJECT=mranderson
|
||||
# make watch PROJECT=mranderson
|
||||
# make export PROJECT=mranderson
|
||||
# make PROJECT=impostor
|
||||
# make build PROJECT=impostor
|
||||
# make watch PROJECT=impostor
|
||||
# make export PROJECT=impostor
|
||||
# -----------------------------------------
|
||||
|
||||
ifndef PROJECT
|
||||
|
||||
@@ -8,7 +8,7 @@ This game is designed for the TIC-80 fantasy computer. To play, follow these ste
|
||||
2. **Clone this repository** Clone this repository to tic80's cartridge folder (MacOS: ~Library/Application Support/com.nesbox.tic/TIC-80)
|
||||
2. **Launch TIC-80:** Start the TIC-80 application.
|
||||
3. **Load the Game:**
|
||||
* Navigate to the directory where `game.lua` is located using the TIC-80 command line (`cd mranderson`).
|
||||
* Navigate to the directory where `game.lua` is located using the TIC-80 command line (`cd impostor`).
|
||||
* Type `load game.lua` and press Enter.
|
||||
* Once loaded, type `run` and press Enter to start the game.
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
meta/meta.header.lua
|
||||
init/init.modules.lua
|
||||
init/init.config.lua
|
||||
init/init.windows.lua
|
||||
init/init.modules.lua
|
||||
init/init.context.lua
|
||||
system/system.print.lua
|
||||
entity/entity.npc.lua
|
||||
entity/entity.item.lua
|
||||
entity/entity.player.lua
|
||||
system/system.input.lua
|
||||
system/system.ui.lua
|
||||
map/map.bedroom.lua
|
||||
window/window.splash.lua
|
||||
window/window.intro.lua
|
||||
window/window.menu.lua
|
||||
@@ -1,5 +1,5 @@
|
||||
function Item.use()
|
||||
print("Used item: " .. Context.dialog.active_entity.name)
|
||||
Print.text("Used item: " .. Context.dialog.active_entity.name)
|
||||
GameWindow.set_state(WINDOW_INVENTORY)
|
||||
end
|
||||
function Item.look_at()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local Config = {
|
||||
local DEFAULT_CONFIG = {
|
||||
screen = {
|
||||
width = 240,
|
||||
height = 136
|
||||
@@ -30,3 +30,44 @@ local Config = {
|
||||
splash_duration = 120
|
||||
}
|
||||
}
|
||||
|
||||
local Config = {
|
||||
-- Copy default values initially
|
||||
screen = DEFAULT_CONFIG.screen,
|
||||
colors = DEFAULT_CONFIG.colors,
|
||||
player = DEFAULT_CONFIG.player,
|
||||
physics = DEFAULT_CONFIG.physics,
|
||||
timing = DEFAULT_CONFIG.timing,
|
||||
}
|
||||
|
||||
local CONFIG_SAVE_BANK = 7
|
||||
local CONFIG_SAVE_ADDRESS_MOVE_SPEED = 0
|
||||
local CONFIG_SAVE_ADDRESS_MAX_JUMPS = 1
|
||||
local CONFIG_MAGIC_VALUE_ADDRESS = 2
|
||||
local CONFIG_MAGIC_VALUE = 0xDE -- A magic number to check if config is saved
|
||||
|
||||
function Config.save()
|
||||
-- Save physics settings
|
||||
mset(Config.physics.move_speed * 10, CONFIG_SAVE_ADDRESS_MOVE_SPEED, CONFIG_SAVE_BANK)
|
||||
mset(Config.physics.max_jumps, CONFIG_SAVE_ADDRESS_MAX_JUMPS, CONFIG_SAVE_BANK)
|
||||
mset(CONFIG_MAGIC_VALUE, CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) -- Mark as saved
|
||||
end
|
||||
|
||||
function Config.load()
|
||||
-- Check if config has been saved before using a magic value
|
||||
if mget(CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) == CONFIG_MAGIC_VALUE then
|
||||
Config.physics.move_speed = mget(CONFIG_SAVE_ADDRESS_MOVE_SPEED, CONFIG_SAVE_BANK) / 10
|
||||
Config.physics.max_jumps = mget(CONFIG_SAVE_ADDRESS_MAX_JUMPS, CONFIG_SAVE_BANK)
|
||||
else
|
||||
Config.restore_defaults()
|
||||
end
|
||||
end
|
||||
|
||||
function Config.restore_defaults()
|
||||
Config.physics.move_speed = DEFAULT_CONFIG.physics.move_speed
|
||||
Config.physics.max_jumps = DEFAULT_CONFIG.physics.max_jumps
|
||||
-- Any other configurable items should be reset here
|
||||
end
|
||||
|
||||
-- Load configuration on startup
|
||||
Config.load()
|
||||
|
||||
@@ -1,4 +1,32 @@
|
||||
local Context = {
|
||||
local SAVE_GAME_BANK = 6
|
||||
local SAVE_GAME_MAGIC_VALUE_ADDRESS = 0
|
||||
local SAVE_GAME_MAGIC_VALUE = 0xCA
|
||||
|
||||
local SAVE_GAME_PLAYER_X_ADDRESS = 1
|
||||
local SAVE_GAME_PLAYER_Y_ADDRESS = 2
|
||||
local SAVE_GAME_PLAYER_VX_ADDRESS = 3
|
||||
local SAVE_GAME_PLAYER_VY_ADDRESS = 4
|
||||
local SAVE_GAME_PLAYER_JUMPS_ADDRESS = 5
|
||||
local SAVE_GAME_CURRENT_SCREEN_ADDRESS = 6
|
||||
|
||||
local VX_VY_OFFSET = 128 -- Offset for negative velocities
|
||||
|
||||
-- Helper for deep copying tables
|
||||
local function clone_table(t)
|
||||
local copy = {}
|
||||
for k, v in pairs(t) do
|
||||
if type(v) == "table" then
|
||||
copy[k] = clone_table(v)
|
||||
else
|
||||
copy[k] = v
|
||||
end
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
-- This function returns a table containing only the initial *data* for Context
|
||||
local function get_initial_data()
|
||||
return {
|
||||
active_window = WINDOW_SPLASH,
|
||||
inventory = {},
|
||||
intro = {
|
||||
@@ -35,8 +63,8 @@ local Context = {
|
||||
menu_items = {},
|
||||
selected_menu_item = 1,
|
||||
selected_inventory_item = 1,
|
||||
-- Screen data
|
||||
screens = {
|
||||
game_in_progress = false, -- New flag
|
||||
screens = clone_table({
|
||||
{
|
||||
-- Screen 1
|
||||
name = "Screen 1",
|
||||
@@ -125,7 +153,7 @@ local Context = {
|
||||
{label = "I guess I am.", next_node = "you_are"}
|
||||
}
|
||||
},
|
||||
who_are_you = {
|
||||
who_are_are = {
|
||||
text = "I'm the Oracle. And you're right on time. Want a cookie?",
|
||||
options = {
|
||||
{label = "Sure.", next_node = "cookie"},
|
||||
@@ -428,5 +456,66 @@ local Context = {
|
||||
},
|
||||
items = {}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
Context = {}
|
||||
|
||||
local function reset_context_to_initial_state()
|
||||
local initial_data = get_initial_data()
|
||||
|
||||
-- Clear existing data properties from Context (but not methods)
|
||||
for k in pairs(Context) do
|
||||
if type(Context[k]) ~= "function" then -- Only clear data, leave functions
|
||||
Context[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Copy all initial data properties into Context
|
||||
for k, v in pairs(initial_data) do
|
||||
Context[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
-- Initially populate Context with data
|
||||
reset_context_to_initial_state()
|
||||
|
||||
-- Now define the methods for Context
|
||||
function Context.new_game()
|
||||
reset_context_to_initial_state()
|
||||
Context.game_in_progress = true
|
||||
MenuWindow.refresh_menu_items()
|
||||
end
|
||||
|
||||
function Context.save_game()
|
||||
if not Context.game_in_progress then return end
|
||||
|
||||
mset(SAVE_GAME_MAGIC_VALUE, SAVE_GAME_MAGIC_VALUE_ADDRESS, SAVE_GAME_BANK)
|
||||
mset(Context.player.x * 10, SAVE_GAME_PLAYER_X_ADDRESS, SAVE_GAME_BANK)
|
||||
mset(Context.player.y * 10, SAVE_GAME_PLAYER_Y_ADDRESS, SAVE_GAME_BANK)
|
||||
mset( (Context.player.vx * 100) + VX_VY_OFFSET, SAVE_GAME_PLAYER_VX_ADDRESS, SAVE_GAME_BANK)
|
||||
mset( (Context.player.vy * 100) + VX_VY_OFFSET, SAVE_GAME_PLAYER_VY_ADDRESS, SAVE_GAME_BANK)
|
||||
mset(Context.player.jumps, SAVE_GAME_PLAYER_JUMPS_ADDRESS, SAVE_GAME_BANK)
|
||||
mset(Context.current_screen, SAVE_GAME_CURRENT_SCREEN_ADDRESS, SAVE_GAME_BANK)
|
||||
end
|
||||
|
||||
function Context.load_game()
|
||||
if mget(SAVE_GAME_MAGIC_VALUE_ADDRESS, SAVE_GAME_BANK) ~= SAVE_GAME_MAGIC_VALUE then
|
||||
-- No saved game found, start a new one
|
||||
Context.new_game()
|
||||
return
|
||||
end
|
||||
|
||||
reset_context_to_initial_state() -- Reset data, preserve methods
|
||||
|
||||
Context.player.x = mget(SAVE_GAME_PLAYER_X_ADDRESS, SAVE_GAME_BANK) / 10
|
||||
Context.player.y = mget(SAVE_GAME_PLAYER_Y_ADDRESS, SAVE_GAME_BANK) / 10
|
||||
Context.player.vx = (mget(SAVE_GAME_PLAYER_VX_ADDRESS, SAVE_GAME_BANK) - VX_VY_OFFSET) / 100
|
||||
Context.player.vy = (mget(SAVE_GAME_PLAYER_VY_ADDRESS, SAVE_GAME_BANK) - VX_VY_OFFSET) / 100
|
||||
Context.player.jumps = mget(SAVE_GAME_PLAYER_JUMPS_ADDRESS, SAVE_GAME_BANK)
|
||||
Context.current_screen = mget(SAVE_GAME_CURRENT_SCREEN_ADDRESS, SAVE_GAME_BANK)
|
||||
|
||||
Context.game_in_progress = true
|
||||
MenuWindow.refresh_menu_items()
|
||||
end
|
||||
@@ -7,6 +7,7 @@ local InventoryWindow = {}
|
||||
local ConfigurationWindow = {}
|
||||
|
||||
local UI = {}
|
||||
local Print = {}
|
||||
local Input = {}
|
||||
local NPC = {}
|
||||
local Item = {}
|
||||
|
||||
19
inc/map/map.bedroom.lua
Normal file
19
inc/map/map.bedroom.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
MapBedroom = {
|
||||
"10101010101010101010101010101010",
|
||||
"10141410101010101010101010101010",
|
||||
"10141410101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"10101010101010101010101010101010",
|
||||
"11111111111111111111111111111111",
|
||||
"11111111111111111111111111111111",
|
||||
"11111111111111111111111111111111",
|
||||
"11111516111213111111111111111111",
|
||||
"11111111111111111111111111111111",
|
||||
"11111111111111111111111111111111",
|
||||
"11111111111111111111111111111111",
|
||||
"11111111111111111111111111111111"
|
||||
}
|
||||
@@ -8,6 +8,13 @@
|
||||
-- 006:9999999999999999999999999999999999999999999999999999999999999999
|
||||
-- 007:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
-- 008:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
-- 016:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
|
||||
-- 017:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||
-- 018:cc222222cc222222cc222222cc222222222222222222222222222222eeeeeeee
|
||||
-- 019:222222cc222222cc222222cc222222cc222222222222222222222222eeeeeeee
|
||||
-- 020:daaaabdddaaaabdddaaaabdddaaaabdddaaaabdddaaaabdddddddddddddddddd
|
||||
-- 021:f888888ff888888ff888888ff888888f8888888f8888888ffeeeeffeeeeffee
|
||||
-- 022:e000000ee000000ee000000ee000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||
-- </TILES>
|
||||
|
||||
-- <WAVES>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- title: Mr Anderson's Adventure
|
||||
-- author: Zsolt Tasnadi
|
||||
-- title: Definitely not an Impostor
|
||||
-- author: Teletype Games
|
||||
-- desc: Life of a programmer in the Vector
|
||||
-- site: https://github.com/rastasi/mranderson
|
||||
-- site: https://git.teletype.hu/games/impostor
|
||||
-- license: MIT License
|
||||
-- version: 0.10
|
||||
-- version: 0.15
|
||||
-- script: lua
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
function Input.up() return btnp(0) end
|
||||
function Input.down() return btnp(1) end
|
||||
function Input.left() return btnp(2) end
|
||||
function Input.right() return btnp(3) end
|
||||
function Input.player_jump() return btnp(4) end
|
||||
function Input.menu_confirm() return btnp(4) end
|
||||
function Input.player_interact() return btnp(5) end -- B button
|
||||
function Input.menu_back() return btnp(5) end
|
||||
-- Gamepad buttons
|
||||
local INPUT_KEY_UP = 0
|
||||
local INPUT_KEY_DOWN = 1
|
||||
local INPUT_KEY_LEFT = 2
|
||||
local INPUT_KEY_RIGHT = 3
|
||||
local INPUT_KEY_A = 4 -- Z key
|
||||
local INPUT_KEY_B = 5 -- X key
|
||||
local INPUT_KEY_X = 6 -- A key
|
||||
local INPUT_KEY_Y = 7 -- S key
|
||||
|
||||
-- Keyboard keys
|
||||
-- TODO: Find correct key codes for SPACE and LCTRL
|
||||
local INPUT_KEY_SPACE = 48
|
||||
local INPUT_KEY_BACKSPACE = 51
|
||||
local INPUT_KEY_ENTER = 50
|
||||
|
||||
function Input.up() return btnp(INPUT_KEY_UP) end
|
||||
function Input.down() return btnp(INPUT_KEY_DOWN) end
|
||||
function Input.left() return btn(INPUT_KEY_LEFT) end
|
||||
function Input.right() return btn(INPUT_KEY_RIGHT) end
|
||||
function Input.player_jump() return btnp(INPUT_KEY_A) or keyp(INPUT_KEY_SPACE) end
|
||||
function Input.menu_confirm() return btnp(INPUT_KEY_A) or keyp(INPUT_KEY_ENTER) end
|
||||
function Input.player_interact() return btnp(INPUT_KEY_B) or keyp(INPUT_KEY_ENTER) end -- B button
|
||||
function Input.menu_back() return btnp(INPUT_KEY_Y) or keyp(INPUT_KEY_BACKSPACE) end
|
||||
function Input.toggle_popup() return keyp(INPUT_KEY_ENTER) end
|
||||
|
||||
@@ -35,7 +35,18 @@ local STATE_HANDLERS = {
|
||||
end,
|
||||
}
|
||||
|
||||
local initialized_game = false
|
||||
|
||||
function init_game()
|
||||
if initialized_game then return end
|
||||
|
||||
MenuWindow.refresh_menu_items()
|
||||
initialized_game = true
|
||||
end
|
||||
|
||||
function TIC()
|
||||
init_game()
|
||||
|
||||
cls(Config.colors.black)
|
||||
local handler = STATE_HANDLERS[Context.active_window]
|
||||
if handler then
|
||||
|
||||
8
inc/system/system.print.lua
Normal file
8
inc/system/system.print.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
function Print.text(text, x, y, color, fixed, scale)
|
||||
local shadow_color = Config.colors.black
|
||||
if color == shadow_color then shadow_color = Config.colors.light_grey end
|
||||
scale = scale or 1
|
||||
print(text, x + 1, y + 1, shadow_color, fixed, scale)
|
||||
print(text, x, y, color, fixed, scale)
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
function UI.draw_top_bar(title)
|
||||
rect(0, 0, Config.screen.width, 10, Config.colors.dark_grey)
|
||||
print(title, 3, 2, Config.colors.green)
|
||||
Print.text(title, 3, 2, Config.colors.green)
|
||||
end
|
||||
|
||||
function UI.draw_dialog()
|
||||
@@ -11,9 +11,9 @@ function UI.draw_menu(items, selected_item, x, y)
|
||||
for i, item in ipairs(items) do
|
||||
local current_y = y + (i-1)*10
|
||||
if i == selected_item then
|
||||
print(">", x - 8, current_y, Config.colors.green)
|
||||
Print.text(">", x - 8, current_y, Config.colors.green)
|
||||
end
|
||||
print(item.label, x, current_y, Config.colors.green)
|
||||
Print.text(item.label, x, current_y, Config.colors.green)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,3 +77,11 @@ function UI.create_numeric_stepper(label, value_getter, value_setter, min, max,
|
||||
type = "numeric_stepper"
|
||||
}
|
||||
end
|
||||
|
||||
function UI.create_action_item(label, action)
|
||||
return {
|
||||
label = label,
|
||||
action = action,
|
||||
type = "action_item"
|
||||
}
|
||||
end
|
||||
|
||||
@@ -17,6 +17,14 @@ function ConfigurationWindow.init()
|
||||
function(v) Config.physics.max_jumps = v end,
|
||||
1, 5, 1, "%d"
|
||||
),
|
||||
UI.create_action_item(
|
||||
"Save",
|
||||
function() Config.save() end
|
||||
),
|
||||
UI.create_action_item(
|
||||
"Restore Defaults",
|
||||
function() Config.restore_defaults() end
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -32,6 +40,7 @@ function ConfigurationWindow.draw()
|
||||
local current_y = y_start + (i - 1) * 12
|
||||
local color = Config.colors.green
|
||||
|
||||
if control.type == "numeric_stepper" then
|
||||
local value = control.get()
|
||||
local label_text = control.label
|
||||
local value_text = string.format(control.format, value)
|
||||
@@ -41,28 +50,36 @@ function ConfigurationWindow.draw()
|
||||
|
||||
if i == ConfigurationWindow.selected_control then
|
||||
color = Config.colors.item
|
||||
print("<", x_start -8, current_y, color)
|
||||
print(label_text, x_start, current_y, color) -- Shift label due to '<'
|
||||
print(value_text, value_x, current_y, color)
|
||||
print(">", x_value_right_align + 4, current_y, color) -- Print '>' after value
|
||||
Print.text("<", x_start -8, current_y, color)
|
||||
Print.text(label_text, x_start, current_y, color) -- Shift label due to '<'
|
||||
Print.text(value_text, value_x, current_y, color)
|
||||
Print.text(">", x_value_right_align + 4, current_y, color) -- Print '>' after value
|
||||
else
|
||||
print(label_text, x_start, current_y, color)
|
||||
print(value_text, value_x, current_y, color)
|
||||
Print.text(label_text, x_start, current_y, color)
|
||||
Print.text(value_text, value_x, current_y, color)
|
||||
end
|
||||
elseif control.type == "action_item" then
|
||||
local label_text = control.label
|
||||
if i == ConfigurationWindow.selected_control then
|
||||
color = Config.colors.item
|
||||
Print.text("<", x_start -8, current_y, color)
|
||||
Print.text(label_text, x_start, current_y, color)
|
||||
Print.text(">", x_start + 8 + (#label_text * char_width) + 4, current_y, color)
|
||||
else
|
||||
Print.text(label_text, x_start, current_y, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print("Press B to go back", x_start, 120, Config.colors.light_grey)
|
||||
Print.text("Press B to go back", x_start, 120, Config.colors.light_grey)
|
||||
end
|
||||
|
||||
function ConfigurationWindow.update()
|
||||
if Input.menu_back() then
|
||||
-- I need to find out how to switch back to the menu
|
||||
-- For now, I'll assume a function GameWindow.set_state exists
|
||||
GameWindow.set_state(WINDOW_MENU)
|
||||
return
|
||||
end
|
||||
|
||||
-- Navigate between controls
|
||||
if Input.up() then
|
||||
ConfigurationWindow.selected_control = ConfigurationWindow.selected_control - 1
|
||||
if ConfigurationWindow.selected_control < 1 then
|
||||
@@ -75,16 +92,21 @@ function ConfigurationWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
-- Modify control value
|
||||
local control = ConfigurationWindow.controls[ConfigurationWindow.selected_control]
|
||||
if control then
|
||||
if control.type == "numeric_stepper" then
|
||||
local current_value = control.get()
|
||||
if Input.left() then
|
||||
if btnp(2) then -- Left
|
||||
local new_value = math.max(control.min, current_value - control.step)
|
||||
control.set(new_value)
|
||||
elseif Input.right() then
|
||||
elseif btnp(3) then -- Right
|
||||
local new_value = math.min(control.max, current_value + control.step)
|
||||
control.set(new_value)
|
||||
end
|
||||
elseif control.type == "action_item" then
|
||||
if Input.menu_confirm() then
|
||||
control.action()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,6 +26,11 @@ function GameWindow.draw()
|
||||
end
|
||||
|
||||
function GameWindow.update()
|
||||
if Input.menu_back() then
|
||||
Context.active_window = WINDOW_MENU
|
||||
MenuWindow.refresh_menu_items()
|
||||
return
|
||||
end
|
||||
Player.update() -- Call the encapsulated player update logic
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function IntroWindow.draw()
|
||||
local x = (Config.screen.width - 132) / 2 -- Centered text
|
||||
print(Context.intro.text, x, Context.intro.y, Config.colors.green)
|
||||
Print.text(Context.intro.text, x, Context.intro.y, Config.colors.green)
|
||||
end
|
||||
|
||||
function IntroWindow.update()
|
||||
|
||||
@@ -2,15 +2,15 @@ function InventoryWindow.draw()
|
||||
UI.draw_top_bar("Inventory")
|
||||
|
||||
if #Context.inventory == 0 then
|
||||
print("Inventory is empty.", 70, 70, Config.colors.light_grey)
|
||||
Print.text("Inventory is empty.", 70, 70, Config.colors.light_grey)
|
||||
else
|
||||
for i, item in ipairs(Context.inventory) do
|
||||
local color = Config.colors.light_grey
|
||||
if i == Context.selected_inventory_item then
|
||||
color = Config.colors.green
|
||||
print(">", 60, 20 + i * 10, color)
|
||||
Print.text(">", 60, 20 + i * 10, color)
|
||||
end
|
||||
print(item.name, 70, 20 + i * 10, color)
|
||||
Print.text(item.name, 70, 20 + i * 10, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,14 +14,21 @@ function MenuWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
function MenuWindow.play()
|
||||
-- Reset player state and screen for a new game
|
||||
Context.player.x = Config.player.start_x
|
||||
Context.player.y = Config.player.start_y
|
||||
Context.player.vx = 0
|
||||
Context.player.vy = 0
|
||||
Context.player.jumps = 0
|
||||
Context.current_screen = 1
|
||||
function MenuWindow.new_game()
|
||||
Context.new_game() -- This function will be created in Context
|
||||
GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
function MenuWindow.load_game()
|
||||
Context.load_game() -- This function will be created in Context
|
||||
GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
function MenuWindow.save_game()
|
||||
Context.save_game() -- This function will be created in Context
|
||||
end
|
||||
|
||||
function MenuWindow.resume_game()
|
||||
GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
@@ -34,9 +41,20 @@ function MenuWindow.configuration()
|
||||
GameWindow.set_state(WINDOW_CONFIGURATION)
|
||||
end
|
||||
|
||||
-- Initialize menu items after actions are defined
|
||||
Context.menu_items = {
|
||||
{label = "Play", action = MenuWindow.play},
|
||||
{label = "Configuration", action = MenuWindow.configuration},
|
||||
{label = "Exit", action = MenuWindow.exit}
|
||||
}
|
||||
function MenuWindow.refresh_menu_items()
|
||||
Context.menu_items = {} -- Start with an empty table
|
||||
|
||||
if Context.game_in_progress then
|
||||
table.insert(Context.menu_items, {label = "Resume Game", action = MenuWindow.resume_game})
|
||||
table.insert(Context.menu_items, {label = "Save Game", action = MenuWindow.save_game})
|
||||
end
|
||||
|
||||
table.insert(Context.menu_items, {label = "New Game", action = MenuWindow.new_game})
|
||||
table.insert(Context.menu_items, {label = "Load Game", action = MenuWindow.load_game})
|
||||
table.insert(Context.menu_items, {label = "Configuration", action = MenuWindow.configuration})
|
||||
table.insert(Context.menu_items, {label = "Exit", action = MenuWindow.exit})
|
||||
|
||||
Context.selected_menu_item = 1 -- Reset selection after refreshing
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -82,14 +82,14 @@ function PopupWindow.draw()
|
||||
|
||||
-- Display the entity's name as the dialog title
|
||||
if Context.dialog.active_entity and Context.dialog.active_entity.name then
|
||||
print(Context.dialog.active_entity.name, 120 - #Context.dialog.active_entity.name * 2, 45, Config.colors.green)
|
||||
Print.text(Context.dialog.active_entity.name, 120 - #Context.dialog.active_entity.name * 2, 45, Config.colors.green)
|
||||
end
|
||||
|
||||
-- Display the dialog content (description for "look at", or initial name/dialog for others)
|
||||
local wrapped_lines = UI.word_wrap(Context.dialog.text, 25) -- Max 25 chars per line
|
||||
local current_y = 55 -- Starting Y position for the first line of content
|
||||
for _, line in ipairs(wrapped_lines) do
|
||||
print(line, 50, current_y, Config.colors.light_grey)
|
||||
Print.text(line, 50, current_y, Config.colors.light_grey)
|
||||
current_y = current_y + 8 -- Move to the next line (8 pixels for default font height + padding)
|
||||
end
|
||||
|
||||
@@ -97,6 +97,6 @@ function PopupWindow.draw()
|
||||
if not Context.dialog.showing_description then
|
||||
UI.draw_menu(Context.dialog.menu_items, Context.dialog.selected_menu_item, 50, current_y + 2)
|
||||
else
|
||||
print("[A] Go Back", 50, current_y + 10, Config.colors.green)
|
||||
Print.text("[A] Go Back", 50, current_y + 10, Config.colors.green)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
function SplashWindow.draw()
|
||||
print("Mr. Anderson's", 78, 60, Config.colors.green)
|
||||
print("Addventure", 90, 70, Config.colors.green)
|
||||
for y, row in ipairs(MapBedroom) do
|
||||
for x = 1, #row, 2 do
|
||||
local tile_id_hex = string.sub(row, x, x + 1)
|
||||
local tile_id = tonumber(tile_id_hex, 16)
|
||||
local screen_x = (x - 1) / 2 * 8
|
||||
local screen_y = (y - 1) * 8
|
||||
spr(tile_id, screen_x, screen_y, -1, 1, 0, 0, 1, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SplashWindow.update()
|
||||
|
||||
Reference in New Issue
Block a user