Adds Game Jam Ready Templates & ReiLua API Updates
(Most of the code is Copilot Generated LOL)
This commit is contained in:
146
template/states/game.lua
Normal file
146
template/states/game.lua
Normal file
@@ -0,0 +1,146 @@
|
||||
--[[
|
||||
Game State - Main gameplay state
|
||||
Demonstrates:
|
||||
- GameState usage
|
||||
- Animation system
|
||||
- Object-oriented player
|
||||
- Basic game loop
|
||||
]]
|
||||
|
||||
local Object = require("lib.classic")
|
||||
local Animation = require("lib.animation")
|
||||
local GameState = Object:extend()
|
||||
|
||||
-- Player class
|
||||
local Player = Object:extend()
|
||||
|
||||
function Player:new(x, y)
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.speed = 200
|
||||
self.animation = nil
|
||||
end
|
||||
|
||||
function Player:update(dt)
|
||||
local moved = false
|
||||
|
||||
-- Movement
|
||||
if RL.IsKeyDown(RL.KEY_LEFT) or RL.IsKeyDown(RL.KEY_A) then
|
||||
self.x = self.x - self.speed * dt
|
||||
moved = true
|
||||
end
|
||||
if RL.IsKeyDown(RL.KEY_RIGHT) or RL.IsKeyDown(RL.KEY_D) then
|
||||
self.x = self.x + self.speed * dt
|
||||
moved = true
|
||||
end
|
||||
if RL.IsKeyDown(RL.KEY_UP) or RL.IsKeyDown(RL.KEY_W) then
|
||||
self.y = self.y - self.speed * dt
|
||||
moved = true
|
||||
end
|
||||
if RL.IsKeyDown(RL.KEY_DOWN) or RL.IsKeyDown(RL.KEY_S) then
|
||||
self.y = self.y + self.speed * dt
|
||||
moved = true
|
||||
end
|
||||
|
||||
-- Update animation
|
||||
if self.animation then
|
||||
if moved then
|
||||
self.animation:play("walk")
|
||||
else
|
||||
self.animation:play("idle")
|
||||
end
|
||||
self.animation:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:draw()
|
||||
if self.animation then
|
||||
self.animation:drawSimple(self.x, self.y)
|
||||
else
|
||||
-- Fallback: draw a simple rectangle
|
||||
RL.DrawRectangle({self.x, self.y, 32, 32}, RL.BLUE)
|
||||
end
|
||||
end
|
||||
|
||||
-- Game State
|
||||
function GameState:new()
|
||||
self.player = nil
|
||||
self.paused = false
|
||||
end
|
||||
|
||||
function GameState:enter(previous)
|
||||
print("Entered game state")
|
||||
|
||||
local screenSize = RL.GetScreenSize()
|
||||
|
||||
-- Create player
|
||||
self.player = Player(screenSize[1] / 2 - 16, screenSize[2] / 2 - 16)
|
||||
|
||||
-- TODO: Load player sprite sheet and create animation
|
||||
-- Example:
|
||||
-- local playerTexture = RL.LoadTexture("assets/player.png")
|
||||
-- self.player.animation = Animation.new(playerTexture, 32, 32, {
|
||||
-- idle = {frames = {1, 2, 3, 4}, fps = 8, loop = true},
|
||||
-- walk = {frames = {5, 6, 7, 8}, fps = 12, loop = true}
|
||||
-- })
|
||||
-- self.player.animation:play("idle")
|
||||
end
|
||||
|
||||
function GameState:update(dt)
|
||||
-- Pause/unpause
|
||||
if RL.IsKeyPressed(RL.KEY_ESCAPE) or RL.IsKeyPressed(RL.KEY_P) then
|
||||
self.paused = not self.paused
|
||||
end
|
||||
|
||||
if self.paused then
|
||||
return
|
||||
end
|
||||
|
||||
-- Update game objects
|
||||
if self.player then
|
||||
self.player:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function GameState:draw()
|
||||
RL.ClearBackground({50, 50, 50, 255})
|
||||
|
||||
-- Draw game objects
|
||||
if self.player then
|
||||
self.player:draw()
|
||||
end
|
||||
|
||||
-- Draw pause overlay
|
||||
if self.paused then
|
||||
local screenSize = RL.GetScreenSize()
|
||||
local centerX = screenSize[1] / 2
|
||||
local centerY = screenSize[2] / 2
|
||||
|
||||
-- Semi-transparent overlay
|
||||
RL.DrawRectangle({0, 0, screenSize[1], screenSize[2]}, {0, 0, 0, 128})
|
||||
|
||||
-- Pause text
|
||||
local text = "PAUSED"
|
||||
local size = 40
|
||||
local width = RL.MeasureText(text, size)
|
||||
RL.DrawText(text, {centerX - width / 2, centerY - 20}, size, RL.WHITE)
|
||||
|
||||
local hint = "Press ESC or P to resume"
|
||||
local hintSize = 20
|
||||
local hintWidth = RL.MeasureText(hint, hintSize)
|
||||
RL.DrawText(hint, {centerX - hintWidth / 2, centerY + 30}, hintSize, RL.GRAY)
|
||||
end
|
||||
|
||||
-- Draw controls hint
|
||||
local hint = "WASD/ARROWS: Move | ESC: Pause"
|
||||
local hintSize = 16
|
||||
local screenSize = RL.GetScreenSize()
|
||||
RL.DrawText(hint, {10, screenSize[2] - 30}, hintSize, RL.LIGHTGRAY)
|
||||
end
|
||||
|
||||
function GameState:leave()
|
||||
print("Left game state")
|
||||
-- Cleanup game assets here
|
||||
end
|
||||
|
||||
return GameState
|
||||
92
template/states/menu.lua
Normal file
92
template/states/menu.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
--[[
|
||||
Menu State - Example menu screen
|
||||
Demonstrates:
|
||||
- GameState usage
|
||||
- Simple UI with keyboard navigation
|
||||
]]
|
||||
|
||||
local Object = require("lib.classic")
|
||||
local MenuState = Object:extend()
|
||||
|
||||
function MenuState:new()
|
||||
self.options = {"Start Game", "Options", "Exit"}
|
||||
self.selected = 1
|
||||
self.title = "MY AWESOME GAME"
|
||||
self.font = nil
|
||||
end
|
||||
|
||||
function MenuState:enter(previous)
|
||||
print("Entered menu state")
|
||||
-- Load menu assets here if needed
|
||||
end
|
||||
|
||||
function MenuState:update(dt)
|
||||
-- Navigate menu
|
||||
if RL.IsKeyPressed(RL.KEY_DOWN) or RL.IsKeyPressed(RL.KEY_S) then
|
||||
self.selected = self.selected + 1
|
||||
if self.selected > #self.options then
|
||||
self.selected = 1
|
||||
end
|
||||
end
|
||||
|
||||
if RL.IsKeyPressed(RL.KEY_UP) or RL.IsKeyPressed(RL.KEY_W) then
|
||||
self.selected = self.selected - 1
|
||||
if self.selected < 1 then
|
||||
self.selected = #self.options
|
||||
end
|
||||
end
|
||||
|
||||
-- Select option
|
||||
if RL.IsKeyPressed(RL.KEY_ENTER) or RL.IsKeyPressed(RL.KEY_SPACE) then
|
||||
if self.selected == 1 then
|
||||
-- Switch to game state
|
||||
local GameState = require("lib.gamestate")
|
||||
local game = require("states.game")
|
||||
GameState.switch(game)
|
||||
elseif self.selected == 2 then
|
||||
-- Options (not implemented)
|
||||
print("Options selected")
|
||||
elseif self.selected == 3 then
|
||||
-- Exit
|
||||
RL.CloseWindow()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MenuState:draw()
|
||||
local screenSize = RL.GetScreenSize()
|
||||
local centerX = screenSize[1] / 2
|
||||
local centerY = screenSize[2] / 2
|
||||
|
||||
RL.ClearBackground(RL.BLACK)
|
||||
|
||||
-- Draw title
|
||||
local titleSize = 40
|
||||
local titleText = self.title
|
||||
local titleWidth = RL.MeasureText(titleText, titleSize)
|
||||
RL.DrawText(titleText, {centerX - titleWidth / 2, centerY - 100}, titleSize, RL.WHITE)
|
||||
|
||||
-- Draw menu options
|
||||
local optionSize = 24
|
||||
local startY = centerY
|
||||
for i, option in ipairs(self.options) do
|
||||
local color = (i == self.selected) and RL.YELLOW or RL.GRAY
|
||||
local prefix = (i == self.selected) and "> " or " "
|
||||
local text = prefix .. option
|
||||
local width = RL.MeasureText(text, optionSize)
|
||||
RL.DrawText(text, {centerX - width / 2, startY + (i - 1) * 40}, optionSize, color)
|
||||
end
|
||||
|
||||
-- Draw controls hint
|
||||
local hint = "UP/DOWN: Navigate | ENTER: Select"
|
||||
local hintSize = 16
|
||||
local hintWidth = RL.MeasureText(hint, hintSize)
|
||||
RL.DrawText(hint, {centerX - hintWidth / 2, screenSize[2] - 40}, hintSize, RL.DARKGRAY)
|
||||
end
|
||||
|
||||
function MenuState:leave()
|
||||
print("Left menu state")
|
||||
-- Cleanup menu assets here if needed
|
||||
end
|
||||
|
||||
return MenuState
|
||||
Reference in New Issue
Block a user