make it so that the score is kept and shown at the end of the game whether the player…
- User
make it so that the score is kept and shown at the end of the game whether the player loses or wins. show it under the you win or game over text -- define constants for block size and sprites block_size = 8 grid_width = 15 grid_height = 13 -- adjusted grid height to fit the screen green_sprite_idx = 2 -- sprite index for green block gray_sprite_idx = 3 -- sprite index for gray blocks golden_snowflake_sprite_idx = 4 -- sprite index for golden snowflakes
-- calculate ui and game offsets ui_height = 8 -- height reserved for ui game_offset_x = (128 - grid_width * block_size) / 2 -- center grid horizontally game_offset_y = ui_height -- start grid beneath the ui ui_margin = 4 -- margin for ui elements
-- player position (cursor) player_x = 0 player_y = 0
-- grid to store blocks blocks = {}
-- player score and game state score = 0 time_limit = 60 * 5 -- 5 minutes in seconds start_time = time() game_over = false game_won = false
function init_blocks() for x=1,grid_width do blocks[x] = {} for y=1,grid_height do blocks[x][y] = 0 end end end
-- initialize game state function _init() init_blocks() end
-- update game state function _update() if game_over or game_won then return end
-- check time local elapsed_time = time() - start_time if elapsed_time > time_limit then if score < 8000 then game_over = true end end -- check win condition if score >= 8000 then game_won = true end -- move cursor if (btnp(0)) then player_x = max(0, player_x - 1) end if (btnp(1)) then player_x = min(grid_width - 1, player_x + 1) end if (btnp(2)) then player_y = max(0, player_y - 1) end if (btnp(3)) then player_y = min(grid_height - 1, player_y + 1) end -- place block if (btnp(4)) then if blocks[player_x + 1][player_y + 1] == 0 then if rnd() < 0.25 then blocks[player_x + 1][player_y + 1] = green_sprite_idx else blocks[player_x + 1][player_y + 1] = gray_sprite_idx end check_for_scoring() end end -- erase block if (btnp(5)) then if blocks[player_x + 1][player_y + 1] ~= 0 then blocks[player_x + 1][player_y + 1] = 0 end endend
-- check for 3-in-a-row green blocks to score points and play sound function check_for_scoring() -- horizontal for y=1,grid_height do for x=1,grid_width-2 do if blocks[x][y] == green_sprite_idx and blocks[x+1][y] == green_sprite_idx and blocks[x+2][y] == green_sprite_idx then score += 300 sfx(2) -- play sound 02 when score increases by 300 blocks[x][y], blocks[x+1][y], blocks[x+2][y] = 0, 0, 0 end end end
-- vertical for x=1,grid_width do for y=1,grid_height-2 do if blocks[x][y] == green_sprite_idx and blocks[x][y+1] == green_sprite_idx and blocks[x][y+2] == green_sprite_idx then score += 300 sfx(2) -- play sound 02 when score increases by 300 blocks[x][y], blocks[x][y+1], blocks[x][y+2] = 0, 0, 0 end end end -- diagonal (down-right) for x=1,grid_width-2 do for y=1,grid_height-2 do if blocks[x][y] == green_sprite_idx and blocks[x+1][y+1] == green_sprite_idx and blocks[x+2][y+2] == green_sprite_idx then score += 300 sfx(2) -- play sound 02 when score increases by 300 blocks[x][y], blocks[x+1][y+1], blocks[x+2][y+2] = 0, 0, 0 end end end -- diagonal (up-right) for x=1,grid_width-2 do for y=3,grid_height do if blocks[x][y] == green_sprite_idx and blocks[x+1][y-1] == green_sprite_idx and blocks[x+2][y-2] == green_sprite_idx then score += 300 sfx(2) -- play sound 02 when score increases by 300 blocks[x][y], blocks[x+1][y-1], blocks[x+2][y-2] = 0, 0, 0 end end end - Assistant
To implement the feature where the score is shown at the end of the game, whether the player wins or loses, you can modify the
_drawfunction to display the score under the "Game Over" or "You Win" text. Here's the revised code with the necessary changes: - User
put it all in one code
- Assistant
- User
also keep the time at the end where the score is kept as well
- Assistant
- User
why does the final tiny keep moviing? please stop it when it shows the final time
- Assistant
- User
take out the final score
- Assistant
- User
when the time runs out and it says game over, show slow moving red snowflakes. also take the final time off only when the player loses the game and it says game over
- Assistant
- User
make it so at the "game over" screen there are red snowflakes just like the golden snowflakes on the winning screen
- Assistant