0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3= 30 then -- Update every second timer = 0 gameTime = gameTime - 1 if gameTime <= 0 then gameState = "summary" end end -- Move player with arrow keys local moveSpeed = player.speed if btn(0) then player.y = player.y - moveSpeed end -- Up if btn(1) then player.y = player.y + moveSpeed end -- Down if btn(2) then player.x = player.x - moveSpeed end -- Left if btn(3) then player.x = player.x + moveSpeed end -- Right -- Attack with button [Z] if btnp(4) then -- Button [Z] to attack attack() end -- Update dirty spots, obstacles, and slowdowns, and check for collisions updateDirtySpots() updateObstacles() updateSlowdowns() -- Check if player health is zero if player.health <= 0 then gameState = "summary" end -- Check if all dirty spots are cleaned if checkAllCleaned() then gameState = "summary" end elseif gameState == "summary" then if btnp(4) then -- Button [Z] to restart gameState = "playing" init() end end TOC() -- Draw the current game state end function init() -- Initialize game elements dirtySpots = {} obstacles = {} slowdowns = {} -- Reset slowdowns score = 0 gameTime = 30 -- Reset game time to 30 seconds player = {x=60, y=68, health=50, speed=2} -- Reset player health to 50 and speed to default -- Create initial dirty spots for i=1, 5 do addDirtySpot() end -- Create initial obstacles for i=1, 3 do addObstacle() end -- Create initial slowdowns for i=1, 2 do addSlowdown() end end function addDirtySpot() local spotX = math.random(220) -- Random position on screen (expanded to 240x136) local spotY = math.random(120) local dirX = math.random(-1, 1) * 0.5 -- ทำให้เคลื่อนไหวช้าลง local dirY = math.random(-1, 1) * 0.5 -- ทำให้เคลื่อนไหวช้าลง table.insert(dirtySpots, {x=spotX, y=spotY, alive=true, dirX=dirX, dirY=dirY}) end function addObstacle() local obsX = math.random(220) -- Random position on screen (expanded to 240x136) local obsY = math.random(120) local dirX = math.random(-1, 1) * 0.5 -- ทำให้เคลื่อนไหวช้าลง local dirY = math.random(-1, 1) * 0.5 -- ทำให้เคลื่อนไหวช้าลง table.insert(obstacles, {x=obsX, y=obsY, dirX=dirX, dirY=dirY}) end function addSlowdown() local slowX = math.random(220) -- Random position on screen (expanded to 240x136) local slowY = math.random(120) table.insert(slowdowns, {x=slowX, y=slowY}) end function attack() for i, spot in ipairs(dirtySpots) do if spot.alive and abs(player.x - spot.x) < 8 and abs(player.y - spot.y) < 8 then spot.alive = false score = score + 10 break end end end function updateDirtySpots() for i, spot in ipairs(dirtySpots) do if spot.alive then -- Move dirty spot randomly spot.x = spot.x + spot.dirX * 2 spot.y = spot.y + spot.dirY * 2 -- Bounce off screen edges if spot.x < 0 or spot.x > 240 then spot.dirX = -spot.dirX end if spot.y < 0 or spot.y > 136 then spot.dirY = -spot.dirY end -- Check collision with player if abs(player.x - spot.x) < 8 and abs(player.y - spot.y) < 8 then player.health = player.health - 10 -- ลดเลือดของตัวละคร spot.alive = false -- Make dirty spot disappear after collision score = score + 10 -- เพิ่มคะà¹à¸™à¸™à¹€à¸¡à¸·à¹ˆà¸­à¸Šà¸™à¸ªà¸´à¹ˆà¸‡à¸ªà¸à¸›à¸£à¸ sfx(SFX_HIT) -- เล่นเสียงชน end end end end function updateObstacles() for i = #obstacles, 1, -1 do local obstacle = obstacles[i] -- Move obstacle randomly obstacle.x = obstacle.x + obstacle.dirX * 2 obstacle.y = obstacle.y + obstacle.dirY * 2 -- Bounce off screen edges if obstacle.x < 0 or obstacle.x > 240 then obstacle.dirX = -obstacle.dirX end if obstacle.y < 0 or obstacle.y > 136 then obstacle.dirY = -obstacle.dirY end -- Check collision with player if abs(player.x - obstacle.x) < 8 and abs(player.y - obstacle.y) < 8 then if player.health < 50 then player.health = player.health + 10 -- เพิ่มเลือดของตัวละคร end table.remove(obstacles, i) -- Remove obstacle after collision score = score - 5 -- ลดคะà¹à¸™à¸™à¹€à¸¥à¹‡à¸à¸™à¹‰à¸­à¸¢à¹€à¸¡à¸·à¹ˆà¸­à¹€à¸à¹‡à¸šà¹€à¸žà¸´à¹ˆà¸¡à¹€à¸¥à¸·à¸­à¸” sfx(SFX_HEALTH) -- เล่นเสียงเà¸à¹‡à¸šà¹€à¸¥à¸·à¸­à¸” end end end function updateSlowdowns() for i, slowdown in ipairs(slowdowns) do -- Check collision with player if abs(player.x - slowdown.x) < 8 and abs(player.y - slowdown.y) < 8 then player.speed = 0.5 -- ลดความเร็วชั่วคราว score = score + 50 -- เพิ่มคะà¹à¸™à¸™ table.remove(slowdowns, i) -- Remove slowdown after collision sfx(SFX_HIT) -- เล่นเสียงชน -- Set a timer to reset speed tmr = 60 -- Set timer for 1 second end end -- Reset player speed after the timer if tmr then tmr = tmr - 1 if tmr <= 0 then player.speed = 2 -- à¸à¸¥à¸±à¸šà¹„ปความเร็วปà¸à¸•ิ tmr = nil end end end function checkAllCleaned() for _, spot in ipairs(dirtySpots) do if spot.alive then return false end end return true end function TOC() cls() if gameState == "menu" then -- Draw menu screen print("Dishwashing Action Game", 30, 30, 7) print("Press [Z] to Start", 30, 50, 7) elseif gameState == "playing" then -- Draw background map(0, 0, 30, 17, 0, 0, 0) -- Draw the entire map (adjust parameters as needed) -- Draw game screen print("Score: " .. score, 5, 5, 7) print("Time: " .. gameTime, 5, 15, 7) print("Health: " .. player.health, 5, 25, 7) -- Draw player spr(PLAYER_SPRITE, player.x, player.y) -- Draw player sprite -- Draw dirty spots for _, spot in ipairs(dirtySpots) do if spot.alive then spr(DIRTY_SPOT_SPRITE, spot.x, spot.y) -- Draw dirty spot sprite end end -- Draw obstacles for _, obstacle in ipairs(obstacles) do spr(OBSTACLE_SPRITE, obstacle.x, obstacle.y) -- Draw obstacle sprite end -- Draw slowdowns for _, slowdown in ipairs(slowdowns) do spr(SLOWDOWN_SPRITE, slowdown.x, slowdown.y) -- Draw slowdown sprite end -- Draw attack range (for visualization) spr(ATTACK_SPRITE, player.x, player.y) -- Draw attack range sprite elseif gameState == "summary" then -- Draw summary screen print("Game Over", 30, 30, 7) print("Final Score: " .. score, 30, 50, 7) print("Time Remaining: " .. gameTime, 30, 70, 7) -- Show remaining time print("Health Remaining: " .. player.health, 30, 90, 7) -- Show remaining health print("Press [Z] to Restart", 30, 110, 7) end end function abs(x) return x < 0 and -x or x end -- Using TICO-80's time function function t() return time() -- Return the time value from TICO-80's time function end