1,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3 1 then menu.position = menu.position - 1 end if btnp(1) and menu.position < #menu.list then menu.position = menu.position + 1 end if btnp(4) then if menu.position == 2 then num_players = 2 end global_state = "game" -- initialize games games = {} for k, v in ipairs(layouts[num_players]) do games[k] = {} initialize_game(games[k], v.x, v.y, v.w, v.h, k - 1, 8 * (k - 1), v.color) end end end function global_update_in_game() cls(12) for k, v in ipairs(games) do update_game(games[k]) end if num_players > 1 then line(119, 0, 119, 135, 0) line(120, 0, 120, 135, 0) end end function initialize_game(game, x_, y_, w_, h_, sfx_chan_, button_id_start_, bg_color_) game.screen = {x=x_, y=y_, w=w_, h=h_} game.game_state = "play" game.branch_list = {} for i=1, 10 do if math.random(2) == 1 then game.branch_list[i] = -1 else game.branch_list[i] = 1 end end game.tree_x_pos = (game.screen.w - 24) / 2 game.bob_x_pos = game.tree_x_pos - 32 game.axe_x_pos = game.bob_x_pos + axe_offset game.axe_flip = 1 game.score = 0 game.sfx_channel = sfx_chan_ game.button_id_start = button_id_start_ game.background_color = bg_color_ end function update_game(game) if game.game_state == "play" then rect(game.screen.x, game.screen.y, game.screen.w, game.screen.h, game.background_color) game.strike = 0 if btnp(game.button_id_start + 2) then game.strike = -1 elseif btnp(game.button_id_start + 3) then game.strike = 1 end if game.strike ~= 0 then if game.strike == game.branch_list[1] then table.remove(game.branch_list, 1) sfx(0, nil, 8, game.sfx_channel) game.score = game.score + 1 if #game.branch_list == 0 then game.game_state = "win" end else game.game_state = "lose" end if game.strike == -1 then game.bob_x_pos = game.tree_x_pos - 32 game.axe_x_pos = game.bob_x_pos + axe_offset game.axe_flip = 1 elseif game.strike == 1 then game.bob_x_pos = game.tree_x_pos + 34 game.axe_x_pos = game.bob_x_pos - axe_offset game.axe_flip = 0 end end for i=1, math.min(#game.branch_list, 6) do local flip = 0 spr(1, game.screen.x + game.tree_x_pos, 80 - (i - 1) * 16, 0, 1, 0, 0, 2, 2) if game.branch_list[i] == -1 then flip = 1 end spr(3, game.screen.x + game.tree_x_pos + 10 * game.branch_list[i], 80 - (i - 1) * 16, 0, 1, flip, 0, 2, 2) end spr(5, game.screen.x + game.bob_x_pos, 80, 0, 1, 0, 0, 2, 2) spr(7, game.screen.x + game.axe_x_pos, 80, 0, 1, game.axe_flip, 0, 2, 2) rect(game.screen.x, game.screen.y + 96, game.screen.w, game.screen.h - 96, 6) print("SCORE: ", game.screen.x + 5, 15, 0) print(game.score, game.screen.x + 18, 22, 0) elseif game.game_state == "lose" then music() rect(game.screen.x, game.screen.y, game.screen.w, game.screen.h, 2) print("You lose!", game.screen.x + (game.screen.w - 90) / 2, 50, nil, nil, 2) print("SCORE: "..game.score, game.screen.x + (game.screen.w - 90) / 2, 90, 14, nil, 2) elseif game.game_state == "win" then music() rect(game.screen.x, game.screen.y, game.screen.w, game.screen.h, 4) print("You win!", game.screen.x + (game.screen.w - 80) / 2, 50, nil, nil, 2) print("SCORE: "..game.score, game.screen.x + (game.screen.w - 90) / 2, 90, 14, nil, 2) end end end function TIC() cls(0) handle_global_state() end