From d82b3afeb1322bbd521767754ec862ae99dd625c Mon Sep 17 00:00:00 2001 From: RageCage64 Date: Wed, 26 Jan 2022 23:09:45 -0500 Subject: [PATCH] picking pokemon sorta --- src/assets.p8 | 72 +++++++++++++++++++++++++++ src/game.lua | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.lua | 48 +++++++++--------- src/menu.lua | 51 +++++++++++++++++++ src/pokemon.lua | 30 +++++++++--- 5 files changed, 299 insertions(+), 29 deletions(-) create mode 100644 src/game.lua create mode 100644 src/menu.lua diff --git a/src/assets.p8 b/src/assets.p8 index dfe69ad..ba2f486 100644 --- a/src/assets.p8 +++ b/src/assets.p8 @@ -33,5 +33,77 @@ __gfx__ 00000000000000000000000000000000000000000000b000000b000000000000000000000000b000000b00000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000b00000000b0000000000000000000000b00000000b0000000000000000000000000000000000000000000 000000000000000000000000000000000000000000b0000000000b00000000000000000000b0000000000b000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077000 __sfx__ 000300001c3501d3501c15020150261502e1502e3501d15027150381500000000000000001d3501c350193501735014350113500c350093500535000350123000f3000e3000b3000830004300003000000000000 diff --git a/src/game.lua b/src/game.lua new file mode 100644 index 0000000..2d72440 --- /dev/null +++ b/src/game.lua @@ -0,0 +1,127 @@ +require("pokemon.lua") +require("textbox.lua") +require("menu.lua") + +function new_game(start_state) + return { + player = nil, + enemy = nil, + main_txb = new_textbox(2, 98, 124, 124), + menu = nil, + state = start_state, + lockout = 0, + } +end + +function new_state(name, init, draw, update, next, timer) + return { + name = name, + init = init, + draw = draw, + update = update, + next = next, + timer = timer, + next_state = false, + } +end + +function start_menu() + init = function(g) + end + + update = function(g) + if btn(4) then + return true + end + return false + end + + draw = function(g) + print("welcome to pico-mon!", 0, 0) + print("press a to continue", 0, 10) + end + + return new_state("start_menu", init, draw, update, "pick_player") +end + +function pick_state(enemy, name, next) + init = function(g) + g.lockout = 2 + menu = pokemon_menu() + g.menu = menu + if enemy then + g.main_txb.current_text = "choose your enemy's pokemon" + else + g.main_txb.current_text = "choose your pokemon" + end + end + + update = function(g) + if g.lockout > 0 then + g.lockout = g.lockout - 1 + return false + end + + if btn(2) then + m_up(g.menu) + elseif btn(3) then + m_down(g.menu) + end + + if btn(4) then + p_name = m_select(g.menu) + p = choose(p_name, enemy) + if enemy then + g.enemy = p + else + g.player = p + end + g.menu = nil + return true + end + + return false + end + + draw = function(g) + draw_m(g.menu) + draw_txb(g.main_txb) + end + + return new_state(name, init, draw, update, next) +end + +function appear_enemy() + init = function(g) + appear(g.enemy) + g.main_txb.current_text = "enemy " .. g.enemy.name .. " appeared!" + end + + update = function(g) + end + + draw = function(g) + draw_p(g.enemy) + draw_txb(g.main_txb) + end + + return new_state("appear_enemy", init, draw, update, "appear_player", 80) +end + +function appear_player() + init = function(g) + appear(g.player) + g.main_txb.current_text = "go " .. g.player.name .. "!" + end + + update = function(g) + end + + draw = function(g) + draw_p(g.enemy) + draw_p(g.player) + draw_txb(g.main_txb) + end + + return new_state("appear_player", init, draw, update, "appear_player", 80) +end diff --git a/src/main.lua b/src/main.lua index dcdec43..c53f87e 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,36 +1,40 @@ require("pokemon.lua") require("textbox.lua") - - -main_txb = new_textbox(2, 98, 124, 124) - -enemy_x = 78 -enemy_y = 8 -player_x = 12 -player_y = 56 +require("game.lua") function _init() cls(0) - p_player = axoleafel(false) - p_player.x = player_x - p_player.y = player_y - p_enemy = axoleafel(true) - p_enemy.x = enemy_x - p_enemy.y = enemy_y - -- appear(p_enemy) - -- main_txb.current_text = "enemy " .. p_enemy.name .. " appeared!" + states = {} + states["start_menu"] = start_menu() + states["pick_player"] = pick_state(false, "pick_player", "pick_enemy") + states["pick_enemy"] = pick_state(true, "pick_enemy", "appear_enemy") + states["appear_enemy"] = appear_enemy() + states["appear_player"] = appear_player() + -- states["player_turn"] = new_state("player_turn") - appear(p_player) - main_txb.current_text = "go " .. p_enemy.name .. "!" + gm = new_game("start_menu") + states[gm.state].init(gm) end function _draw() cls(0) - draw_p(p_enemy) - draw_p(p_player) - draw_txb(main_txb) + states[gm.state].draw(gm) end function _update() -end \ No newline at end of file + next_state = states[gm.state].update(gm) + + t = states[gm.state].timer + if t then + if t <= 0 then + next_state = true + end + states[gm.state].timer = t - 1 + end + + if next_state then + gm.state = states[gm.state].next + states[gm.state].init(gm) + end +end diff --git a/src/menu.lua b/src/menu.lua new file mode 100644 index 0000000..1ee44f9 --- /dev/null +++ b/src/menu.lua @@ -0,0 +1,51 @@ +-- Constructor + +cursor_spr = 207 + +function new_menu(x, y, w, h, options) + return { + x = x, + y = y, + w = w, + h = h, + + options = options, + cursor = 1, + } +end + +-- Menu methods + +function pokemon_menu() + return new_menu(60, 8, 88, 68, { + "axoleafel", + }) +end + +function draw_m(m) + rect(m.x, m.y, m.w, m.h) + for i,o in ipairs(m.options) do + r = i-1 + o_x = m.x+14 + o_y = m.y+4+(8*r) + print(o, o_x, o_y) + end + + spr(cursor_spr, m.x+14, m.y+4+(8*m.cursor)) +end + +function m_down(m) + if m.cursor == 1 then + m.cursor = table.getn(m.options) + end +end + +function m_up(m) + if m.cursor == table.getn(m.options) then + m.cursor = 1 + end +end + +function m_select(m) + return m.options[m.cursor] +end diff --git a/src/pokemon.lua b/src/pokemon.lua index 7d801d4..bde0f86 100644 --- a/src/pokemon.lua +++ b/src/pokemon.lua @@ -1,6 +1,18 @@ -- Constructor function new_pokemon(name, enemy, front_sprite, back_sprite, cry) + enemy_x = 78 + enemy_y = 8 + player_x = 12 + player_y = 56 + + p_x = player_x + p_y = player_y + if enemy then + p_x = enemy_x + p_y = enemy_y + end + return { name = name, enemy = enemy, @@ -9,8 +21,8 @@ function new_pokemon(name, enemy, front_sprite, back_sprite, cry) cry = cry, -- moves = moves, - x = 0, - y = 0, + x = p_x, + y = p_y, appeared = false, } @@ -22,8 +34,6 @@ function appear(p) if p.appeared then return end - - draw_p(p) cry(p) p.appeared = true end @@ -37,11 +47,11 @@ function draw_p(p) end function draw_front(p) - draw(p.front_sprite, p.x, p.y) + draw_p_spr(p.front_sprite, p.x, p.y) end function draw_back(p) - draw(p.back_sprite, p.x, p.y) + draw_p_spr(p.back_sprite, p.x, p.y) end function cry(p) @@ -50,6 +60,12 @@ end --Pokemon +function choose(name, enemy) + if name == "axoleafel" then + return axoleafel(enemy) + end +end + function axoleafel(enemy) return new_pokemon( "axoleafel", @@ -63,7 +79,7 @@ end -- Functions -function draw(start, x, y) +function draw_p_spr(start, x, y) for i=0,3 do tile_row = 16 * i spr_row = 8 * i