Love the smooth yet responsive movement with playerx, playertargetx etc. Will have to remember to use this trick myself next time!
Play game
New Super 1K Shoot Em Up's itch.io pageCompressed Bytes used
1023
Source Code (OPTIONAL)
pico-8 cartridge // http://www.pico-8.com
version 41
__lua__
function _init()
f = false
t = true
playerx = 64
playery = 105
playertargetx = playerx
playertargety = playery
playercanshoot = t
playerpowerlevel = 1
bullets = {}
for i=1,100 do
add(bullets, {rnd(128), rnd(228)-50, 0, 0.5+rnd(1), f, f, t})
end
enemies = {}
wave = 1
dead = f
end
function _update60()
if (#enemies < wave and time() % 1 == 0) then
add(enemies, {rnd(112)+8, -50, -wave/400+rnd(wave/200), 0.7+rnd(0.6), 1, flr(rnd(60))})
end
if (btn(0, 0)) playertargetx -= 2
if (btn(1, 0)) playertargetx += 2
if (btn(2, 0)) playertargety -= 2
if (btn(3, 0)) playertargety += 2
if (not btn(4, 0)) playercanshoot = t
playertargetx = min(max(8, playertargetx), 120)
playertargety = min(max(8, playertargety), 120)
playerx += (playertargetx-playerx)*0.2
playery += (playertargety-playery)*0.2
playerbullets = 0
for i=1,#bullets do if (bullets[i][5]) playerbullets += 1 end
if (btn(4, 0) and playercanshoot and playerbullets < playerpowerlevel) then
add(bullets, {playerx, playery, 0, -3, t, f, f})
playercanshoot = f
end
for i=1,#enemies do
enemies[i][2] += enemies[i][4]
if (enemies[i][2] > 178) enemies[i][2] -= 228
enemies[i][1] += enemies[i][3]
if (enemies[i][1] < 8 or enemies[i][1] > 136) enemies[i][3] = -enemies[i][3]
if ((time() + enemies[i][6]) % 3 == 0) then
add(bullets, {enemies[i][1], enemies[i][2], enemies[i][3]*2, 2, f, f, f})
end
end
for i=1,#bullets do
bullets[i][1] += bullets[i][3]
bullets[i][2] += bullets[i][4]
if bullets[i][7] then
if (bullets[i][2] > 178) bullets[i][2] -= 228
else
if (bullets[i][1] < -10 or bullets[i][1] > 138 or bullets[i][2] < -10 or bullets[i][2] > 138) bullets[i][6] = t
if bullets[i][5] then
for j=1,#enemies do
if (bullets[i][1] > enemies[j][1]-4 and bullets[i][1] < enemies[j][1]+4 and bullets[i][2] > enemies[j][2]-4 and bullets[i][2] < enemies[j][2]+4) then
bullets[i][6] = t
enemies[j][5] -= 1
end
end
else
if (bullets[i][1] > playerx-4 and bullets[i][1] < playerx+4 and bullets[i][2] > playery-4 and bullets[i][2] < playery+4) then
dead = t
end
end
end
end
for i=#bullets,1,-1 do
if (bullets[i][6]) deli(bullets, i)
end
for i=#enemies,1,-1 do
if (enemies[i][5] < 1) then
deli(enemies, i)
wave += 1
if (rnd(100) < 4) playerpowerlevel += 1
end
end
end
function drawship (x, y, side)
circfill(x, y, 2)
line(x-4, y-4, x-4, y+4)
line(x+4, y-4, x+4, y+4)
line(x, y+side*3, x, y)
line(x-4, y, x+4, y)
end
function _draw()
cls(0)
if (not dead) then
gameover = 240
for i=1,#bullets do
colr = 12
radi = 1
if (bullets[i][5]) colr = 10
if bullets[i][7] then
colr = 5
radi = 0.5
end
circfill(bullets[i][1], bullets[i][2], radi, colr)
end
color(8)
for i=1,#enemies do
drawship(enemies[i][1], enemies[i][2], 1)
end
color()
drawship(playerx, playery, -1)
else
gameover -= 1
print("score: "..wave-1, 47, 40)
if gameover < 0 then
print("continue", 49, 75)
if btn(4, 0) then
extcmd("reset")
end
end
end
end
Leave a comment
Log in with itch.io to leave a comment.