diff options
| author | Chris Bradley <1029chris@gmail.com> | 2022-02-19 13:40:34 -0800 |
|---|---|---|
| committer | Chris Bradley <1029chris@gmail.com> | 2022-02-19 13:40:34 -0800 |
| commit | 4f3bfa57d582d1f8a20da0c34cc7c94563570008 (patch) | |
| tree | 40b909149599b732ab5501c867b3bb6993e7d543 | |
| parent | 86fdddc12397f45af95cd85729b12f88edd33dc5 (diff) | |
added back local variables, some more tokens gained
target player now changes every second
| -rw-r--r-- | draw.lua | 4 | ||||
| -rw-r--r-- | enemies.lua | 58 | ||||
| -rw-r--r-- | pickups.lua | 5 | ||||
| -rw-r--r-- | players.lua | 6 | ||||
| -rw-r--r-- | ui.lua | 10 | ||||
| -rw-r--r-- | update.lua | 4 | ||||
| -rw-r--r-- | waves.lua | 4 |
7 files changed, 42 insertions, 49 deletions
@@ -21,9 +21,9 @@ if gamerunning then runningscore(currentscore,true) else runningscore(currentscore,false) - scoretextcolors = {{12,15},{2,9}} --shows incorrect shadow colour for 2P counter (shows as 0) + local scoretextcolors = {{12,15},{2,9}} --shows incorrect shadow colour for 2P counter (shows as 0) for i = 1, #players, 1 do - player = players[i] + local player = players[i] if player.health < 1 then printdropshadow(ceil(player.inv),player.x+circletimex,player.y+circletimey,scoretextcolors[i][i],scoretextcolors[i][i+1]) end diff --git a/enemies.lua b/enemies.lua index b997c3b..e569c71 100644 --- a/enemies.lua +++ b/enemies.lua @@ -87,7 +87,7 @@ function addbasicenemy(x, y, speed) --basic small weak enemy } function enemy.draw() - sprite = enemy.sprite + local sprite = enemy.sprite if flr(sin(time()*speed)) ~= 0 then --if the ships heading up, change sprite sprite += 1 end @@ -149,7 +149,7 @@ function addwallshooter(x, shootup, speed, offset, bulletspeed) if enemy.shootcooldown < 0 then if (t()+enemy.offset)%1>0.5/enemy.bulletspeed then enemy.shootcooldown = 0.08/enemy.bulletspeed - velywall = -1 + local velywall = -1 if shootup then velywall = 1 end if enemy.x < 120 and enemy.x > 20 then addbullet(enemy.x, enemy.y, -speed, enemy.bulletspeed*velywall) @@ -188,7 +188,7 @@ function addballshooter(x, y, speed) function enemy.draw() if enemy.inv < 0 or flashtime then - sprite = 11 + local sprite = 11 if enemy.health < 4 then damagesmoke(enemy) sprite = 27 @@ -228,7 +228,6 @@ function addtargetingenemy(x, y, speed) health = 3, shootcooldown = rnd(0.4)+0.2, speed = speed, - bulletcounter = 0, shot = enemyshot, collide = enemycollide } @@ -246,12 +245,10 @@ function addtargetingenemy(x, y, speed) enemy.x -= speed if enemy.shootcooldown < 0 and currentwavetime%1.5>1.2 then enemy.shootcooldown = 0.1 - enemy.bulletcounter += 1 - ptarget = enemy.bulletcounter%#players+1 - if enemy.x < canshootatx and players[ptarget].x < enemy.x+30 then --math involving a distance check to get the proper velocity for aiming - distancetarget = sqrt((players[ptarget].x - enemy.x)^2+(players[ptarget].y - enemy.y)^2) - velxtarget = (players[ptarget].x - enemy.x)/distancetarget - velytarget = (players[ptarget].y - enemy.y)/distancetarget + if enemy.x < canshootatx and players[targetplayer].x < enemy.x+30 then --math involving a distance check to get the proper velocity for aiming + local distancetarget = sqrt((players[targetplayer].x - enemy.x)^2+(players[targetplayer].y - enemy.y)^2) + local velxtarget = (players[targetplayer].x - enemy.x)/distancetarget + local velytarget = (players[targetplayer].y - enemy.y)/distancetarget addbullet(enemy.x-3, enemy.y, velxtarget, velytarget) -- shoot if on screen sfx(15, 2) -- play shoot sound if on screen end @@ -285,7 +282,7 @@ function addlasershooter(x, y, points, speed, stay, isboss) function enemy:draw() if enemy.inv < 0 or flashtime then - sprite = 64 + local sprite = 64 if enemy.health < 10 then damagesmoke(enemy) sprite = 96 @@ -365,8 +362,8 @@ function addwallboss(x, y, length, points, speed, stay, move, isboss) end function enemy.draw() - x,y = enemy.x,enemy.y - dmgwall = 0 + local x,y = enemy.x,enemy.y + local dmgwall = 0 if enemy.health < enemy.starthealth*0.25 then damagesmoke(enemy) dmgwall = 32 @@ -451,11 +448,11 @@ function addbomb(x, y, delay) --BIG BOMB!!!! KILL IIT QUICKLY!!!! shot = enemyshot, collide = enemycollide } - pointsbomb = 50 --points by default if killed by player + local pointsbomb = 50 --points by default if killed by player function enemy.draw() - x,y = enemy.x,enemy.y - sprite = 73 + local x,y = enemy.x,enemy.y + local sprite = 73 if everysecondtimer > 0.5 then sprite = 75 end --animation if enemy.health < 7 then damagesmoke(enemy) @@ -463,7 +460,7 @@ function addbomb(x, y, delay) --BIG BOMB!!!! KILL IIT QUICKLY!!!! end if enemy.inv < 0 or flashtime then circfill(x+15, y+16, sin(enemy.shootcooldown^2)*3-enemy.shootcooldown, rnd({7,11,3})) - offsetbomb = mid(0, -enemy.shootcooldown-2, 3) + local offsetbomb = mid(0, -enemy.shootcooldown-2, 3) spr(sprite, x, y-offsetbomb, 2, 2) spr(sprite, x, y+16+offsetbomb, 2, 2, false, true) spr(sprite, x+15, y-offsetbomb, 2, 2, true) @@ -518,7 +515,7 @@ function addmissileboss(x, y) --boss that shoots missiles!!! } function enemy.draw() - sprite = 68 + local sprite = 68 if enemy.health < 11 then sprite = 100 damagesmoke(enemy) @@ -530,14 +527,13 @@ function addmissileboss(x, y) --boss that shoots missiles!!! end function enemy.update() - playertarget = ceil((t()/2.4)%#players) enemy.targetchangetimer -= ft --some cool different moves, shout out to dont get a virus fans! if currentwavetime%18 > 8 and currentwavetime%20 < 12 then enemy.targety = flr(everysecondtimer*1.99)*96 elseif currentwavetime%18 > 17.3 then --INTIMIDATION TACTICS!!!!! - enemy.targety = players[playertarget].y - enemy.targetx = players[playertarget].x+24 + enemy.targety = players[targetplayer].y + enemy.targetx = players[targetplayer].x+24 enemy.shootcooldown = 0.4 end enemy.x = lerp(enemy.x, enemy.targetx, enemy.speed) @@ -549,13 +545,13 @@ function addmissileboss(x, y) --boss that shoots missiles!!! end if enemy.shootcooldown < 0 then enemy.shootcooldown = 0.3 + rnd(1.2) - if enemy.x < canshootatx and players[playertarget] ~= nil then - offsetmissleboss = 2 + if enemy.x < canshootatx and players[targetplayer] ~= nil then + local offsetmissleboss = 2 if currentwavetime%2 > 1 then offsetmissleboss = 30 end - addmissile(enemy.x, enemy.y+offsetmissleboss, playertarget) + addmissile(enemy.x, enemy.y+offsetmissleboss, targetplayer) if enemy.health < 11 then sfx(15, 2) - addbullet(enemy.x,enemy.y+16,(players[playertarget].x-enemy.x)/70,(players[playertarget].y-enemy.y-16)/70) + addbullet(enemy.x,enemy.y+16,(players[targetplayer].x-enemy.x)/70,(players[targetplayer].y-enemy.y-16)/70) -- ERROR attempting to find a non existant player end enemy.speed += 0.001 @@ -587,7 +583,7 @@ function addfinalboss() --THE FINAL BOSS!!!!!!! WOOOAAAHHHHHH!!!!!!!!!!!!!!!!!!! --thrusters that each fall off once the portal's health is 1/5th depleated function addportalthruster(x,y,id,isflipped) if id*40-40 < enemy.health then - spritethruster = 128 + local spritethruster = 128 isflipped = isflipped or 1 if flashtime then spritethruster = 132 end --animation spr(spritethruster, x, isflipped*(sin(time()*enemy.speed)*3.5)+y, 4, 2) @@ -599,11 +595,11 @@ function addfinalboss() --THE FINAL BOSS!!!!!!! WOOOAAAHHHHHH!!!!!!!!!!!!!!!!!!! function enemy:draw() -- portal local x,y,speed,amount = enemy.x-8,10+sin(time()*enemy.speed+0.2)*2,enemy.speed,enemy.amount - ovaly1 = (sin(time()*speed-0.12)*amount/2)+y+24 + local ovaly1 = (sin(time()*speed-0.12)*amount/2)+y+24 --local ovaly2 = (-sin(time()*speed-0.12)*amount/2)+y+84 - ovaly2 = -ovaly1+128 + local ovaly2 = -ovaly1+128 ovalfill(x+28,ovaly1,x+6,ovaly2,14) - portalcolors = {11,3} + local portalcolors = {11,3} for i = 1, 260, 1 do --cool swirling portal effect pset(x+17+sin(i/53.3465+t()/8)*i/24+sin(i/350.23548+t()), y+54+cos(i/53.3465+t()/8)*i/9,portalcolors[(ceil(i/20))%#portalcolors+1]) end @@ -611,7 +607,7 @@ function addfinalboss() --THE FINAL BOSS!!!!!!! WOOOAAAHHHHHH!!!!!!!!!!!!!!!!!!! oval(x+28,ovaly1,x+6,ovaly2,11) addportalthruster(x-19,y-4,3) addportalthruster(x-19,y+97,4,-1) - spriteportal = 136 + local spriteportal = 136 if enemy.health < 40 then spriteportal = 140 end spr(spriteportal, x, (sin(time()*speed)*amount)+y, 4, 3) spr(spriteportal, x, (-sin(time()*speed)*amount)+y+85, 4, 3, false,true) @@ -629,7 +625,7 @@ function addfinalboss() --THE FINAL BOSS!!!!!!! WOOOAAAHHHHHH!!!!!!!!!!!!!!!!!!! addbullet(110,64, rnd(0.5)-1, rnd(2)-1) end if rnd() < 0.4 then - addmissile(110, 60, 1) + addmissile(110, 60, targetplayer) end end if rnd() < 0.4 then diff --git a/pickups.lua b/pickups.lua index 41fa66c..cd0de85 100644 --- a/pickups.lua +++ b/pickups.lua @@ -15,8 +15,7 @@ function addpickup(x, y, type) local pickup = {} - x = x - y = y + --x,y = x,y type = type or rnd({"fastshoot", "3shoot"}) function pickup.draw(pickup) @@ -38,7 +37,7 @@ function addpickup(x, y, type) end function pickup:affect(player) - pickupcolor = 8 --health + local pickupcolor = 8 --health if type == "fastshoot" then player.shootspeed = 0.17 pickupcolor = 12 diff --git a/players.lua b/players.lua index a98c543..a6a7dc5 100644 --- a/players.lua +++ b/players.lua @@ -1,4 +1,5 @@ alwaysfire = false +coopmode = false players = {} function addplayer(x, y, sprite, bulletsprite) @@ -93,9 +94,8 @@ function addplayer(x, y, sprite, bulletsprite) --particles from rockets, and smoke/sparks from damage player.particlecooldown -= ft if player.particlecooldown < 0 and player.health > 0 then - thrusteroffset = {0,7} - for i = 1, 2, 1 do - addcircle(player.x-1, player.y+thrusteroffset[i], -0.5, 0, 1.5, 0.5, 9) + for i = 0, 1, 1 do + addcircle(player.x-1, player.y+i*7, -0.5, 0, 1.5, 0.5, 9) end -- addcircle(player.x-1, player.y, -0.5, 0, 1.5, 0.5, 9) -- addcircle(player.x-1, player.y+7, -0.5, 0, 1.5, 0.5, 9) @@ -14,7 +14,7 @@ function invaderslogotext(x,y) -- x = 12 -- y = 20 - invaderstext = "I N V A D E R S" + local invaderstext = "I N V A D E R S" for i = 1, 12, 1 do print(invaderstext, x+i%3-1, y+i%4-1, 3) end @@ -85,8 +85,8 @@ function credits(x,y) -- default vaues -- x = 10 -- y = 100 - sintimecredits = sin(t())*2 - timemodcredits = (t()%2<1) + local sintimecredits = sin(t())*2 + local timemodcredits = (t()%2<1) palt(2,true) palt(0,false) @@ -99,8 +99,8 @@ end --Ending screen function finalscorescreen(x,y) - playercolour0 = 12 - playercolour1 = 15 + local playercolour0 = 12 + local playercolour1 = 15 if coopmode then playercolour0 = 9 playercolour1 = 2 @@ -6,9 +6,6 @@ circletimex = sin(t())*3 -- for elements that move in a circle (respawn timer) circletimey = cos(t())*3 screenshakex = sin(shake+t())*shake screenshakey = sin(shake+gt/2.1)*shake -if #players > 1 then - coopmode = true -end if gameover then scrollspeed = mid(-1/10,scrollspeed-1/3000,ft) @@ -36,6 +33,7 @@ elseif not gamerunning and t() > 1 then --main menu addplayer(18, 60, 16, 18) startgame() elseif btn(5) then + coopmode = true addplayer(18, 45, 16, 18) addplayer(18, 75, 32, 34) startgame() @@ -221,7 +221,7 @@ wave[16] = { end, everysecond = function () if flr(currentwavetime%6) == 5 and currentwavetime < 20 then - ylaserpos = 16 + local ylaserpos = 16 if players[targetplayer].y > 64 then ylaserpos = 80 end @@ -286,10 +286,10 @@ wave[20] = { foreach(wave, function(wave) if not wave.conditions then wave.conditions = function() if #enemies < 1 then return true end end end end) --if there are no conditons for a wave, give them one. look at all those ends!!!! function updatewaves() - if coopmode then targetplayer = rnd({1,2}) end currentwavetime += ft everysecondtimer += ft if everysecondtimer >= 1 then + targetplayer = rnd({1,#players}) --swaps target every second everysecondtimer = 0 if wave[currentwave].everysecond then wave[currentwave].everysecond() |
