123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- -- title: survivor
- -- author: pixelbath
- -- desc: a game where you try not to die
- local t = 0
- local p = {
- x = 120, y = 68, hp = 1000,
- }
- local cam = {
- x = 120, y = 68,
- }
- local enemies = {}
- local drops = {}
- function add_drop(x, y, t)
- table.insert(enemies, {
- x = x, y = y, type = t, dc = 0.25,
- })
- end
- function spawn_enemy(x, y)
- table.insert(enemies, {x=x, y=y,})
- end
- function kill_enemy(en)
- -- TODO: check drop chance
- if math.random() > en.dc then
- add_drop(en.x, en.y, 0)
- end
- table.remove(enemies, en)
- end
- function draw_player()
- rect(p.x + cam.x, p.y + cam.y, 8, 8, 5)
- end
- -- also update here to save a loop
- function draw_enemies()
- for k, en in ipairs(enemies) do
- rect(en.x, en.y, 8, 8, 3)
- if en.x > p.x and en.x < p.x + 8 and en.y > p.y and en.y < p.y + 8 then
- p.hp = p.hp - 1
- else
- -- TODO: trig
- en.x = en.x
- end
- end
- end
- for i=1,30 do
- spawn_enemy(i * 20, 80)
- end
- function TIC()
- if btn(0) then p.y = p.y - 1 end
- if btn(1) then p.y = p.y + 1 end
- if btn(2) then p.x = p.x - 1 end
- if btn(3) then p.x = p.x + 1 end
- cam.x = 120 - p.x
- cam.y = 68 - p.y
- cls(0)
- draw_player()
- draw_enemies()
- print("hp: "..p.hp)
- end
- -- <PALETTE>
- -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
- -- </PALETTE>
|