ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >1ÀÌÌ ÌÌÌÀÀÌ À Ì ÀÌ ÌÌ ÀÌÌÌÌÀ ÌÌ ÌÌÌ Ì Ì ÌÀÀ ÀÀ À ÀÌÌÌ Ì ÌÌ ÌÌ ÌÌ ÌÌÌÌÀ ÀÀ À ÀÌÌÌÌ Ì ÌÌ ÌÌÌ Ì Ì Ì À ÀÌ À ÀÌÌÌÌÌ ÌÌ ÌÌÌÀÌÀÌÌÌÀ À ÀÌÌÀ ÀÌÌÀÌÌ ÌÌ Ì pwwwwpwpwwwwpwwpwwwwwwwwpwwpwwwpwwwwwpwpwpwwwpwpwwwwwwwwwwwpwwpwwpwwwwwwpwwwwwwwwwwwwwpwwwwwwpwwwpwpwwwwîîàîîîàîàîîîàààîîîàîàîàîîîîîîîîàîàîîîàîîîîîîîîàîîàîîîîîîàîîààîàîîîîîîîîîîîîîàîîààîàîîàîîîîîîîîîàîîîîàîîîîàîîî-- title: Cuby Platformer -- author: Alexander -- desc: platformer game -- script: lua -- cover: 0000000000000000000000000000000000000000000000000000000000000000 -- Controls: A = left, D = right, Space = jump -- States state = "menu" -- "menu", "game", "win" current_level = 1 -- Player player = { x=0, y=0, w=8, h=8, dx=0, dy=0, speed=1.5, jump_power=-4.5, on_ground=false, alive=true } gravity = 0.2 -- Levels definition: -- platform types: normal, moving, disappearing -- platform = {x, y, w, h, type, dir, speed, timer, visible} levels = {} -- Helper func: reset player pos on current level start function reset_player() local start = levels[current_level].start player.x = start.x player.y = start.y player.dx = 0 player.dy = 0 player.on_ground = false player.alive = true end -- Define levels function define_levels() levels = { { start={x=10, y=100}, platforms={ {0,108,128,8,"normal"}, {20,90,20,4,"normal"}, {50,80,15,4,"disappear",0,0,0,true}, {70,70,20,4,"moving",1,1,0,true}, {100,60,15,4,"normal"}, }, spikes={ {45,104,8,4}, {80,104,8,4}, }, exit={x=110, y=52, w=8, h=8} }, { start={x=5, y=100}, platforms={ {0,108,128,8,"normal"}, {15,90,10,4,"moving",1,1,0,true}, {35,75,15,4,"disappear",0,0,0,true}, {60,65,10,4,"normal"}, {85,55,15,4,"moving",-1,1,0,true}, {110,45,15,4,"normal"}, }, spikes={ {30,104,8,4}, {55,104,8,4}, {90,50,8,4}, }, exit={x=115, y=38, w=8, h=8} }, { start={x=10, y=100}, platforms={ {0,108,128,8,"normal"}, {15,95,15,4,"disappear",0,0,0,true}, {40,85,20,4,"moving",1,1,0,true}, {70,75,15,4,"disappear",0,0,0,true}, {95,65,20,4,"moving",-1,1,0,true}, {120,55,8,4,"normal"}, }, spikes={ {30,104,8,4}, {60,104,8,4}, {100,60,8,4}, }, exit={x=118, y=48, w=8, h=8} }, { start={x=10, y=100}, platforms={ {0,108,128,8,"normal"}, {20,90,15,4,"moving",1,1,0,true}, {50,80,15,4,"disappear",0,0,0,true}, {80,70,20,4,"moving",-1,1,0,true}, {110,60,15,4,"normal"}, }, spikes={ {40,104,8,4}, {75,104,8,4}, {105,104,8,4}, }, exit={x=115, y=52, w=8, h=8} } } end -- Check rectangle overlap function rects_overlap(a,b) return a.x < b.x + b.w and a.x + a.w > b.x and a.y < b.y + b.h and a.y + a.h > b.y end -- Update platforms (moving and disappearing) function update_platforms(dt) local pls = levels[current_level].platforms for i, p in ipairs(pls) do if p[5] == "moving" then p[1] = p[1] + p[7]*p[6] -- Bounce back at edges (20 and 108 for X) if p[1] < 20 then p[6] = 1 end if p[1] + p[3] > 108 then p[6] = -1 end elseif p[5] == "disappear" then -- timer cycles 0-120 frames, visible half the time p[8] = p[8] + 1 if p[8] >= 120 then p[8] = 0 end p[9] = p[8] < 60 -- visible first 60 frames end end end -- Draw platforms function draw_platforms() local pls = levels[current_level].platforms for i,p in ipairs(pls) do if p[5] == "disappear" and not p[9] then -- skip invisible platform else local color = 11 if p[5] == "moving" then color = 12 end rect(p[1], p[2], p[3], p[4], color) end end end -- Check collision with platforms (only visible) function collide_platforms(rect) local pls = levels[current_level].platforms for i,p in ipairs(pls) do if p[5] == "disappear" and not p[9] then -- invisible, no collision else local plat = {x=p[1], y=p[2], w=p[3], h=p[4]} if rects_overlap(rect, plat) then return plat end end end return nil end -- Check collision with spikes function collide_spikes(rect) local spikes = levels[current_level].spikes for i,s in ipairs(spikes) do local spike = {x=s[1], y=s[2], w=s[3], h=s[4]} if rects_overlap(rect, spike) then return true end end return false end function TIC() cls(0) if state == "menu" then -- Draw title screen print("CUBY PLATFORMER", 30, 40, 12) print("A/D = Move", 40, 60, 7) print("SPACE = Jump", 40, 70, 7) print("Press SPACE to start", 20, 100, 14) if btnp(4) then -- SPACE pressed define_levels() current_level = 1 reset_player() state = "game" end elseif state == "game" then -- Update -- Controls if btn(2) then -- A left player.dx = -player.speed elseif btn(3) then -- D right player.dx = player.speed else player.dx = 0 end if btnp(4) and player.on_ground then -- Space jump player.dy = player.jump_power player.on_ground = false end -- Gravity player.dy = player.dy + gravity -- Update platforms update_platforms() -- Move player X player.x = player.x + player.dx -- Collision X local player_rect = {x=player.x, y=player.y, w=player.w, h=player.h} local plat = collide_platforms(player_rect) if plat then if player.dx > 0 then player.x = plat.x - player.w elseif player.dx < 0 then player.x = plat.x + plat.w end end -- Move player Y player.y = player.y + player.dy -- Collision Y player_rect = {x=player.x, y=player.y, w=player.w, h=player.h} plat = collide_platforms(player_rect) if plat then if player.dy > 0 then player.y = plat.y - player.h player.dy = 0 player.on_ground = true elseif player.dy < 0 then player.y = plat.y + plat.h player.dy = 0 end else player.on_ground = false end -- Check spikes if collide_spikes(player_rect) then player.alive = false end -- Check void (fall off screen) if player.y > 128 then player.alive = false end -- If dead, restart level if not player.alive then reset_player() end -- Check exit local ex = levels[current_level].exit local exit_rect = {x=ex.x, y=ex.y, w=ex.w, h=ex.h} if rects_overlap(player_rect, exit_rect) then current_level = current_level + 1 if current_level > #levels then state = "menu" current_level = 1 else reset_player() end end -- Draw draw_platforms() -- Draw spikes for i,s in ipairs(levels[current_level].spikes) do rect(s[1], s[2], s[3], s[4], 8) end -- Draw exit rect(ex.x, ex.y, ex.w, ex.h, 14) -- Draw player rect(player.x, player.y, player.w, player.h, 12) -- Draw level text print("Level "..current_level, 2, 2, 7) end end