Update RainbowShotsFromOuterSpace

added indentation and more comments
This commit is contained in:
taxicomics 2024-05-13 14:47:54 +02:00 committed by GitHub
parent 0dba3fc3ea
commit a9e0be9545
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 54 additions and 51 deletions

View File

@ -2,56 +2,59 @@
--hold the random function and the value 128 --hold the random function and the value 128
웃=rnd 😐=128 웃=rnd 😐=128
enemies={} enemies={}
player_x=62♥=3◆=1✽={}function g(a,b,c,f)return abs(a-c)+abs(b-f)end player_x=62♥=3◆=1✽={}
--quick little distance function
function distance(a,b,c,f)return abs(a-c)+abs(b-f)end
function _draw() function _draw()
--the game logic if statement instead of a state machine --the game logic if statement instead of a state machine
--encompasses all game logic --encompasses all game logic
if ♥>0 do if ♥>0 do
--i use the modulo operator instead of a timer variable --i use the modulo operator instead of a timer variable
if(t()%1==0)add(enemies,{x=웃(😐),y=0}) if(t()%1==0)add(enemies,{x=웃(😐),y=0})
cls() cls()
--draw the player --draw the player
?"★",player_x,99,7 ?"★",player_x,99,7
--draw the 'gui' with points and remaining hearts --draw the 'gui' with points and remaining hearts
?◆.."◆ "..♥.."♥",50,0 ?◆.."◆ "..♥.."♥",50,0
--iterate over all enemies --iterate over all enemies
for j in all(enemies)do for j in all(enemies)do
--move them down --move them down
j.y+=1 j.y+=1
--check whether they touched the player --check whether they touched the player
if g(j.x,j.y,player_x,99)<5 do if distance(j.x,j.y,player_x,99)<5 do
--move them off screen if they do instead of spending tokens on del()- --move them off screen if they do instead of spending tokens on del()-
--i do that later --i do that later
j.x=-9 j.x=-9
♥-=1 ♥-=1
end end
--make the enemies harder to hit by adjusting their x position with sin(time()) --make the enemies harder to hit by adjusting their x position with sin(time())
if(j.x>9)j.x+=sin(t()) if(j.x>9)j.x+=sin(t())
--iterate over the shots inside the enemey loop-which means shots get faster if more enemies are on screen, --iterate over the shots inside the enemey loop-which means shots get faster if more enemies are on screen,
--but it saves an extra loop --but it saves an extra loop
for i in all(✽)do for i in all(✽)do
--draw the shots --draw the shots
?"◆",i.x,i.y,i.y%9 ?"◆",i.x,i.y,i.y%9
--move the shots up --move the shots up
i.y-=1 i.y-=1
--check wheter they've hit any enemies,pushing them offscreen if needed --check wheter they've hit any enemies,pushing them offscreen if needed
if(g(i.x,i.y,j.x,j.y)<6)del(✽,i)j.x=-9◆+=1end if(distance(i.x,i.y,j.x,j.y)<6)del(✽,i) j.x=-9 ◆+=1
--finally deleting the enemies that have gotten below the screen height,on or off screen end
if(j.y>😐)del(enemies,j) --finally deleting the enemies that have gotten below the screen height,on or off screen
--draw the enemies if(j.y>😐)del(enemies,j)
?"🐱",j.x,j.y,8 --draw the enemies
end ?"🐱",j.x,j.y,8
--spawn a shot based on a 'modulo-timer' end
if(t()%1==0)add(✽,{x=player_x,y=90}) --spawn a shot based on a 'modulo-timer'
--stolen and slightly modified bit of code to handle the input if(t()%1==0)add(✽,{x=player_x,y=90})
b=btn() --stolen and slightly modified bit of code to handle the input
player_x+=(b\2%2-b%2)*2 b=btn()
for i=0,9 do player_x+=(b\2%2-b%2)*2
--draw 'stars' in random spots for that speedy feel for i=0,9 do
?".",웃(😐),웃(😐),10 --draw 'stars' in random spots for that speedy feel
end ?".",웃(😐),웃(😐),10
else end
--closing the game logic if statement else
?"dead",55,60 --closing the game logic if statement
end ?"dead",55,60
end
end end