battling kinda works, or at least pretends to

main
RageCage64 3 years ago
parent 2418f8beb7
commit bcf02928b4

@ -97,13 +97,12 @@ __gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077000
__sfx__ __sfx__
000300001c3501d3501c15020150261502e1502e3501d15027150381500000000000000001d3501c350193501735014350113500c350093500535000350123000f3000e3000b3000830004300003000000000000 000300001c3501d3501c15020150261502e1502e3501d15027150381500000000000000001d3501c350193501735014350113500c350093500535000350123000f3000e3000b3000830004300003000000000000

@ -2,6 +2,8 @@ require("pokemon.lua")
require("textbox.lua") require("textbox.lua")
require("menu.lua") require("menu.lua")
-- Game Constructor
function new_game(start_state) function new_game(start_state)
return { return {
player = nil, player = nil,
@ -10,9 +12,20 @@ function new_game(start_state)
menu = nil, menu = nil,
state = start_state, state = start_state,
lockout = 0, lockout = 0,
player_move = nil,
enemy_move = nil,
} }
end end
-- Game methods
function set_txb(g, s)
g.main_txb.current_text = s
end
-- State Constructor
function new_state(name, init, draw, update, next, timer) function new_state(name, init, draw, update, next, timer)
return { return {
name = name, name = name,
@ -50,22 +63,19 @@ function pick_state(enemy, name, next)
menu = pokemon_menu() menu = pokemon_menu()
g.menu = menu g.menu = menu
if enemy then if enemy then
g.main_txb.current_text = "choose your enemy's pokemon" set_txb(g, "choose your enemy's pokemon")
else else
g.main_txb.current_text = "choose your pokemon" set_txb(g, "choose your pokemon")
end end
end end
update = function(g) update = function(g)
if g.lockout > 0 then
g.lockout = g.lockout - 1
return false
end
if btn(2) then if btn(2) then
m_up(g.menu) m_up(g.menu)
g.lockout = 4
elseif btn(3) then elseif btn(3) then
m_down(g.menu) m_down(g.menu)
g.lockout = 4
end end
if btn(4) then if btn(4) then
@ -94,7 +104,7 @@ end
function appear_enemy() function appear_enemy()
init = function(g) init = function(g)
appear(g.enemy) appear(g.enemy)
g.main_txb.current_text = "enemy " .. g.enemy.name .. " appeared!" set_txb(g, "enemy " .. g.enemy.name .. " appeared!")
end end
update = function(g) update = function(g)
@ -111,7 +121,100 @@ end
function appear_player() function appear_player()
init = function(g) init = function(g)
appear(g.player) appear(g.player)
g.main_txb.current_text = "go " .. g.player.name .. "!" set_txb(g, "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, "player_choose_move", 80)
end
function player_choose_move()
init = function(g)
set_txb(g, "")
g.menu = move_menu(g.player)
end
update = function(g)
if btn(2) then
m_up(g.menu)
g.lockout = 4
elseif btn(3) then
m_down(g.menu)
g.lockout = 4
end
if btn(4) then
m_name = m_select(g.menu)
g.player_move = g.player.moves[m_name]
g.menu = nil
return true
end
return false
end
draw = function(g)
draw_p(g.enemy)
draw_health(g.enemy)
draw_p(g.player)
draw_health(g.player)
draw_m(g.menu)
end
return new_state("player_choose_move", init, draw, update, "enemy_choose_move")
end
function enemy_choose_move()
init = function(g)
end
update = function(g)
g.enemy_move = choose_random_move(p)
return true
end
draw = function(g)
draw_p(g.enemy)
draw_health(g.enemy)
draw_p(g.player)
draw_health(g.player)
end
return new_state("enemy_choose_move", init, draw, update, "player_turn")
end
function player_turn()
init = function(g)
set_txb(g, g.player.name .. " used " .. g.player_move.name)
g.enemy.health = g.enemy.health - g.player_move.damage
end
update = function(g)
end
draw = function(g)
draw_p(g.enemy)
draw_health(g.enemy)
draw_p(g.player)
draw_health(g.player)
draw_txb(g.main_txb)
end
return new_state("player_turn", init, draw, update, "enemy_turn", 80)
end
function enemy_turn()
init = function(g)
set_txb(g, g.enemy.name .. " used " .. g.enemy_move.name)
g.player.health = g.player.health - g.enemy_move.damage
end end
update = function(g) update = function(g)
@ -119,9 +222,11 @@ function appear_player()
draw = function(g) draw = function(g)
draw_p(g.enemy) draw_p(g.enemy)
draw_health(g.enemy)
draw_p(g.player) draw_p(g.player)
draw_health(g.player)
draw_txb(g.main_txb) draw_txb(g.main_txb)
end end
return new_state("appear_player", init, draw, update, "appear_player", 80) return new_state("enemy_turn", init, draw, update, "player_choose_move", 80)
end end

@ -7,6 +7,10 @@ function _init()
states["pick_enemy"] = pick_state(true, "pick_enemy", "appear_enemy") states["pick_enemy"] = pick_state(true, "pick_enemy", "appear_enemy")
states["appear_enemy"] = appear_enemy() states["appear_enemy"] = appear_enemy()
states["appear_player"] = appear_player() states["appear_player"] = appear_player()
states["player_choose_move"] = player_choose_move()
states["enemy_choose_move"] = enemy_choose_move()
states["player_turn"] = player_turn()
states["enemy_turn"] = enemy_turn()
gm = new_game("start_menu") gm = new_game("start_menu")
states[gm.state].init(gm) states[gm.state].init(gm)
@ -18,7 +22,12 @@ function _draw()
end end
function _update() function _update()
if gm.lockout > 0 then
gm.lockout = gm.lockout - 1
return false
else
next_state = states[gm.state].update(gm) next_state = states[gm.state].update(gm)
end
t = states[gm.state].timer t = states[gm.state].timer
if t then if t then

@ -4,12 +4,10 @@ cursor_spr = 207
-- Constructor -- Constructor
function new_menu(x, y, w, h, options) function new_menu(x, y, options)
return { return {
x = x, x = x,
y = y, y = y,
w = w,
h = h,
options = options, options = options,
cursor = 1, cursor = 1,
@ -18,33 +16,30 @@ end
-- Menu methods -- Menu methods
function pokemon_menu()
return new_menu(60, 8, 88, 68, {
"axoleafel",
})
end
function draw_m(m) function draw_m(m)
rect(m.x, m.y, m.w, m.h)
for i,o in ipairs(m.options) do for i,o in ipairs(m.options) do
r = i-1 r = i-1
o_x = m.x+14 o_x = m.x+12
o_y = m.y+4+(8*r) o_y = m.y+4+(8*r)
print(o, o_x, o_y) print(o, o_x, o_y)
end end
spr(cursor_spr, m.x+14, m.y+4+(8*m.cursor)) spr(cursor_spr, m.x+2, m.y+2+(8*(m.cursor-1)))
end end
function m_down(m) function m_up(m)
if m.cursor == 1 then if m.cursor == 1 then
m.cursor = table.getn(m.options) m.cursor = count(m.options)
else
m.cursor = m.cursor - 1
end end
end end
function m_up(m) function m_down(m)
if m.cursor == table.getn(m.options) then if m.cursor == count(m.options) then
m.cursor = 1 m.cursor = 1
else
m.cursor = m.cursor + 1
end end
end end

@ -0,0 +1,40 @@
-- Constructor
function new_move(name, damage)
return {
name = name,
damage = damage,
}
end
-- Move methods
-- Move Builders
function tackle()
return new_move(
"tackle",
10
)
end
function grass_knot()
return new_move(
"grass knot",
10
)
end
function wrap()
return new_move(
"wrap",
10
)
end
function leaf_blade()
return new_move(
"leaf blade",
10
)
end

@ -1,6 +1,9 @@
require("menu.lua")
require("move.lua")
-- Constructor -- Constructor
function new_pokemon(name, enemy, front_sprite, back_sprite, cry) function new_pokemon(name, enemy, front_sprite, back_sprite, cry, health, moves)
p_x = 12 p_x = 12
p_y = 56 p_y = 56
if enemy then if enemy then
@ -8,12 +11,21 @@ function new_pokemon(name, enemy, front_sprite, back_sprite, cry)
p_y = 8 p_y = 8
end end
move_table = {}
for i,m in ipairs(moves) do
move_table[m.name] = m
end
return { return {
name = name, name = name,
enemy = enemy, enemy = enemy,
front_sprite = front_sprite, front_sprite = front_sprite,
back_sprite = back_sprite, back_sprite = back_sprite,
cry = cry, cry = cry,
health = health,
max_health = health,
moves = move_table,
x = p_x, x = p_x,
y = p_y, y = p_y,
@ -22,7 +34,7 @@ function new_pokemon(name, enemy, front_sprite, back_sprite, cry)
} }
end end
-- Pokemon methods -- Methods
function appear(p) function appear(p)
if p.appeared then if p.appeared then
@ -64,7 +76,40 @@ function draw_p_spr(start, x, y)
end end
end end
--Pokemon function move_menu(p)
move_names = {}
for n in pairs(p.moves) do
add(move_names, n)
end
return new_menu(76, 84, move_names)
end
function choose_random_move(p)
move_names = {}
for n in pairs(p.moves) do
add(move_names, n)
end
choice = flr(rnd(4)) + 1
choice_move = move_names[choice]
return p.moves[choice_move]
end
function draw_health(p)
h = tostr(p.health) .. "/" .. tostr(p.max_health)
if p.enemy then
print(h, 56, 16)
else
print(h, 46, 66)
end
end
-- Pokemon builders
function pokemon_menu()
return new_menu(30, 8, {
"axoleafel",
})
end
function choose(name, enemy) function choose(name, enemy)
if name == "axoleafel" then if name == "axoleafel" then
@ -78,7 +123,13 @@ function axoleafel(enemy)
enemy, enemy,
4, 4,
8, 8,
0 0,
-- {} 50,
{
tackle(),
wrap(),
grass_knot(),
leaf_blade(),
}
) )
end end

Loading…
Cancel
Save