0,]']>S}Wup8d%qy)6o;]AsVl3??????????????????????????@IOOOOOOOOOOOOOOOOOOOOOOOOOOOO@DGKLOOOOOOOOOOOOOOOOOOOOOOOOO@@@@ACDEGH K NOOOOOOOOOOOOOOOOOO       = ` `0]a``` `` `]a` `A A Aaaa A A A A A A A AaaaA``` `` ` `@@Xa`Ta`@`  ` `aaa A AaaA A A`` `` ` ``` ` ` ` `` ``0aaaaAAAAAA AAAAAAA````@@@@ @@ ` ` ` ` ` `      @ ^a 4@@Ɓ0 '9`f f`ff`ffff`f ` " " ffb&ff`ffff`ff`2-- title: Shoot Away -- author: Marcus -- desc: -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua atan2 = math.atan2 cos = math.cos sin = math.sin player ={ x = 120, y = 68, speed = 1, Face = 0,--rotation sprite = 256, canShoot = true, shootTime = 0 } enemies={} eSpawn = false bullets = {} score = 0 game = true music(0,0) function TIC() if game then map(0,0) spawnEnemies() MovePlayer() moveEnemies(player.x, player.y) moveBullets() spr(player.sprite, player.x, player.y, 0,1,0, player.Face) checkShoot( player, player.x, player.y, player.Face) enemyHit() drawEnemies() drawBullets() if time() - player.shootTime > 500 then player.canShoot = true end checkDeath() print(score) else map(0,0) print(score) print('GAME OVER',90,30) end end function MovePlayer() if btn(2) then player.x = player.x - 1 player.Face = 3 elseif btn(3) then player.x = player.x + 1 player.Face = 1 end if btn(0) then player.y = player.y - 1 player.Face = 0 elseif btn(1) then player.y = player.y + 1 player.Face = 2 end if player.x <= -2 then player.x = 241 elseif player.x >= 242 then player.x = -1 elseif player.y <= -2 then player.y = 137 elseif player.y >= 138 then player.y = -1 end end function addEnemy(mySprite, xPos, yPos) local e = { sprite = mySprite, spawnX = xPos, spawnY = yPos, x = xPos, y = yPos, dx = 0, dy = 0, speed = 1, tx = 0, ty = 0, active = true, index = 0 } enemies[#enemies+1] = e end function drawEnemies() for num=1,#enemies do local e = enemies[num] local s = e.sprite if e.active then spr(s, e.x, e.y, 0) end end end function moveEnemies(myTx,myTy) for num=1,#enemies do local e = enemies[num] if e.active then e.tx = myTx e.ty = myTy end if e.x~=e.tx and e.y~=e.ty then ang = atan2(e.ty - e.y, e.tx - e.x) dx =0.5*cos(ang) dy =0.5*sin(ang) end if e.active then e.x = e.x + dx e.y = e.y + dy end end end function spawnEnemies() if eSpawn == true then eSpawn = false if(time()/1000%5<1) and(time()/1000%10>1) then addEnemy(257,0,45) addEnemy(257,0,90) end if(time()/1000%10<1) then addEnemy(257,240,45) addEnemy(257,240,90) end if(time()/1000%15<1) and(time()/1000%30>1)then addEnemy(257,60,0) addEnemy(257,90,0) addEnemy(257,120,0) addEnemy(257,150,0) addEnemy(257,180,0) end if(time()/1000%30<1)then addEnemy(257,60,136) addEnemy(257,90,136) addEnemy(257,120,136) addEnemy(257,150,136) addEnemy(257,180,136) end end if(time()%5000>1000) then eSpawn = true end end function checkShoot(p,x,y,d) if btn(4) and p.canShoot then p.canShoot = false p.shootTime = time() sfx(63,64,-1,1) if d == 0 then addBullet(x,y+8,0,1) elseif d == 1 then addBullet(x-8,y,-1,0) elseif d == 2 then addBullet(x,y-8,0,-1) elseif d == 3 then addBullet(x+8,y,1,0) end end end function addBullet(xPos,yPos,pFaceX,pFaceY) local b = { x = xPos, y = yPos, xFace = pFaceX, yFace = pFaceY, speed = 1, active = true, index = 0 } bullets[#bullets+1] = b end function drawBullets() for num=1,#bullets do local b = bullets[num] if b.active then spr(288, b.x, b.y,0) if b.x < 0 or b.x > 241 then b.active = false b.y =-100 elseif b.y < 0 or b.y > 138 then b.active = false b.y =-100 end end end end function moveBullets() for num=1, #bullets do local b = bullets[num] if b.active then b.x = b.x + b.xFace b.y = b.y + b.yFace end end end function collision(px, py, ox, oy) hitX = false hitY = false if (px>ox and pxox-7) then hitX = true end if (py>oy and pyoy-7) then hitY = true end if hitX and hitY then return true else return false end end function enemyHit() for num=1, #enemies do local e = enemies[num] for num=1, #bullets do local b = bullets[num] hitb = collision(e.x,e.y,b.x,b.y) if hitb and e.active and b.active then e.x = -100 b.y = -100 e.active = false b.active = false score = score + 100 sfx(62,21,-1,3) end end end end function checkDeath() for num = 1, #enemies do local e = enemies[num] local hit = collision( player.x, player.y, e.x,e.y) if hit then game = false music(1,0,0,false) end end end