set vars and functions to local
This commit is contained in:
34
game.lua
34
game.lua
@@ -42,13 +42,13 @@ MOVE_SPEED = 1.5
|
|||||||
MAX_JUMPS = 2
|
MAX_JUMPS = 2
|
||||||
|
|
||||||
-- Global variables (initialized)
|
-- Global variables (initialized)
|
||||||
gameState = STATE_SPLASH
|
local gameState = STATE_SPLASH
|
||||||
currentScreen = 1
|
local currentScreen = 1
|
||||||
dialog_text = ""
|
local dialog_text = ""
|
||||||
splash_timer = 120 -- 2 seconds at 60fps
|
local splash_timer = 120 -- 2 seconds at 60fps
|
||||||
|
|
||||||
-- Player properties
|
-- Player properties
|
||||||
player = {
|
local player = {
|
||||||
x = PLAYER_START_X,
|
x = PLAYER_START_X,
|
||||||
y = PLAYER_START_Y,
|
y = PLAYER_START_Y,
|
||||||
w = PLAYER_WIDTH,
|
w = PLAYER_WIDTH,
|
||||||
@@ -59,7 +59,7 @@ player = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Ground properties
|
-- Ground properties
|
||||||
ground = {
|
local ground = {
|
||||||
x = GROUND_X,
|
x = GROUND_X,
|
||||||
y = GROUND_Y,
|
y = GROUND_Y,
|
||||||
w = GROUND_W,
|
w = GROUND_W,
|
||||||
@@ -67,28 +67,28 @@ ground = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Menu properties
|
-- Menu properties
|
||||||
menuItems = {"Play", "Exit"}
|
local menuItems = {"Play", "Exit"}
|
||||||
selectedMenuItem = 1
|
local selectedMenuItem = 1
|
||||||
|
|
||||||
function draw_splash()
|
local function draw_splash()
|
||||||
cls(COLOR_BLACK)
|
cls(COLOR_BLACK)
|
||||||
print("Mr. Anderson's", 78, 60, COLOR_LIGHT_GREY)
|
print("Mr. Anderson's", 78, 60, COLOR_LIGHT_GREY)
|
||||||
print("Addventure", 90, 70, COLOR_LIGHT_GREY)
|
print("Addventure", 90, 70, COLOR_LIGHT_GREY)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_splash()
|
local function update_splash()
|
||||||
splash_timer = splash_timer - 1
|
splash_timer = splash_timer - 1
|
||||||
if splash_timer <= 0 then
|
if splash_timer <= 0 then
|
||||||
gameState = STATE_MENU
|
gameState = STATE_MENU
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_top_bar(title)
|
local function draw_top_bar(title)
|
||||||
rect(0, 0, SCREEN_WIDTH, 10, COLOR_BLACK)
|
rect(0, 0, SCREEN_WIDTH, 10, COLOR_BLACK)
|
||||||
print(title, 3, 2, COLOR_LIGHT_GREY)
|
print(title, 3, 2, COLOR_LIGHT_GREY)
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_menu()
|
local function draw_menu()
|
||||||
cls(COLOR_LIGHT_GREY)
|
cls(COLOR_LIGHT_GREY)
|
||||||
draw_top_bar("Main Menu")
|
draw_top_bar("Main Menu")
|
||||||
for i, item in ipairs(menuItems) do
|
for i, item in ipairs(menuItems) do
|
||||||
@@ -100,7 +100,7 @@ function draw_menu()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_menu()
|
local function update_menu()
|
||||||
if btnp(0) then -- Up
|
if btnp(0) then -- Up
|
||||||
selectedMenuItem = selectedMenuItem - 1
|
selectedMenuItem = selectedMenuItem - 1
|
||||||
if selectedMenuItem < 1 then
|
if selectedMenuItem < 1 then
|
||||||
@@ -130,7 +130,7 @@ function update_menu()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Screen data
|
-- Screen data
|
||||||
screens = {
|
local screens = {
|
||||||
{ -- Screen 1
|
{ -- Screen 1
|
||||||
name = "Screen 1",
|
name = "Screen 1",
|
||||||
platforms = {
|
platforms = {
|
||||||
@@ -169,7 +169,7 @@ screens = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function game_update()
|
local function game_update()
|
||||||
-- Handle input
|
-- Handle input
|
||||||
if btn(2) then
|
if btn(2) then
|
||||||
player.vx = -MOVE_SPEED
|
player.vx = -MOVE_SPEED
|
||||||
@@ -258,13 +258,13 @@ function game_update()
|
|||||||
rect(player.x, player.y, player.w, player.h, COLOR_GREEN)
|
rect(player.x, player.y, player.w, player.h, COLOR_GREEN)
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_dialog()
|
local function draw_dialog()
|
||||||
rect(40, 50, 160, 40, COLOR_BLACK)
|
rect(40, 50, 160, 40, COLOR_BLACK)
|
||||||
rectb(40, 50, 160, 40, COLOR_DARK_GREY)
|
rectb(40, 50, 160, 40, COLOR_DARK_GREY)
|
||||||
print(dialog_text, 120 - #dialog_text * 2, 68, COLOR_DARK_GREY)
|
print(dialog_text, 120 - #dialog_text * 2, 68, COLOR_DARK_GREY)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_dialog()
|
local function update_dialog()
|
||||||
if btnp(4) or btnp(5) then
|
if btnp(4) or btnp(5) then
|
||||||
gameState = STATE_GAME
|
gameState = STATE_GAME
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user