` UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU??CC??CC??CC??CCU^^_]__]UUUUU]UUUUUUU^UUUU_U_UUUUU_UUU]_]UU]UUUU^UUU\\\\  ^^^^____]^ /! ! 2#0 /! ! 2#@1 /! ! 2#  2""" 1 2#0 2""" 1 2#@1 2""" 1 2# "$$"22A "$$"22! "$$"22  "BB "##  "BB "##A "BB "##@! /! !02#@ 2""" 12#"$$@#2! "BB "## A ""22  `P`p`pppppp4C 2C!2#2#!!2# C4 C42#!!2#!C42DD#2DD#!C42#!!B$!4CB#2$B#2$!4CB$!1#21!1!#21!!!!!!@@0" ""@@@@ ""@@@ 0?333, <`        6::RPPR;;8::RPPR       >?    CCCC????OCCC????CCCC???? MCCC?OC?CC?CCCC???? MCCC>???                             CCCC???? MCCC=???CCCC????MCCC=??? CCCC????MCCC=???CCCC????MCCC,0,]']>S}Wup8d%qy)6o;]AsVl3 1.5 then cam.velocity.speed = 1.5 end if shipHull < 0 then shipHull = 0 end if shipHull == 0 then print("YOU ARE DEAD",64,64) end -- debug print("X: "..cam.position.x//1,0,0) print("Y: "..cam.position.y//1,0,8) print("Rot: "..cam.rotation,0,16) print("Maptile: "..mget((cam.position.x+120)//8,(cam.position.y+68)//8),0,24) print("Velocity: "..cam.velocity.speed,0,32) print("Hull: "..shipHull//1,0,40) -- pause if btnp(4) then gameState = state_paused end end -- doSpaceship function doPilot() sync(1,1,false) sync(4,1,false) weaponOffset() pilotControls() screenWrapping() t=t+1 cls(13) map(mapX,mapY) spr(sprite, x, y, 0) swingWeapon() -- debug print("map.: "..mapX.."-"..mapY,0,0) print("player coords: "..x.."-"..y,0,8) print("Current dir: "..dir,0,16) print("Last dir: "..lastDir,0,24) print("time: "..t,0,32) print("SwingTimer: "..swingTimer,0,40) print("Stamina: "..stamina,0,48) print(walk,0,56) -- pause if btnp(4) then gameState=state_paused end -- take off if mget(x//8,y//8) == 2 then print("Press Z to return to ship",64,64) end if btnp(5) and mget(x//8,y//8) == 2 then gameState=state_spaceship end end -- doPilot function doEndScreen() cls() print("GAME OVER",80,40) print("press z to start",60,60) if btnp(4) then gameState=state_spaceship end end -- doEndScreen function doPauseScreen() print("Paused",80,40) print("press z to resume",60,60) if btnp(4) then gameState=lastState end end -- doPauseScreen function shipCollision() if mget((cam.position.x+120)//8, (cam.position.y+68)//8) == 2 then print ("DOCKING AVAILABLE",90,56) if btnp(5) then gameState = state_pilot end end if mget((cam.position.x+120)//8, (cam.position.y+68)//8) ~= 0 and mget((cam.position.x+120)//8, (cam.position.y+68)//8) ~= 2 then print ("TAKING DAMAGE",90,56) hitTimer = hitTimer + 2 if hitTimer>10 then hitTimer = 10 end cam.velocity.speed = (cam.velocity.speed*-0.9)+-0.1 shipHull = shipHull - 1 * (-cam.velocity.speed*15) end end function pilotControls() cycle = t%40//10 walk = 0 if cycle == 0 then walk = 0 elseif cycle == 1 then walk = 1 elseif cycle == 2 then walk = 0 elseif cycle == 3 then walk = 2 end if btn(0) and swingTimer == 0 and mget((x+(mapX*8))//8,(y+(mapY*8)-1)//8)<48 and mget((x+(mapX*8)+7)//8,(y+(mapY*8)-1)//8)<48 then y=y-speed dir="up" lastDir="up" sprite=260+walk defaultSprite=260 attackSprite=270 end -- up if btn(1) and swingTimer == 0 and mget((x+(mapX*8))//8,(y+(mapY*8)+7+1)//8)<48 and mget((x+(mapX*8)+7)//8,(y+(mapY*8)+7+1)//8)<48 then y=y+speed dir="down" lastDir="down" sprite=257+walk defaultSprite=257 attackSprite=269 end -- down if btn(2) and swingTimer == 0 and mget(((x-1)+(mapX*8))//8,(y+(mapY*8))//8)<48 and mget(((x-1)+(mapX*8))//8,(y+7+(mapY*8))//8)<48 then x=x-speed dir="left" lastDir="left" sprite=263+walk defaultSprite=263 attackSprite=271 end -- left if btn(3) and swingTimer == 0 and mget((x+7+1+(mapX*8))//8,(y+(mapY*8))//8)<48 and mget((x+7+1+(mapX*8))//8,(y+7+(mapY*8))//8)<48 then x=x+speed dir="right" lastDir="right" sprite=266+walk defaultSprite=266 attackSprite=272 end -- right if swingTimer==0 and (btn(0) or btn(1) or btn(2) or btn(3)) then sprite = sprite elseif swingTimer > 0 then sprite = attackSprite else sprite = defaultSprite end end -- pilotControls function screenWrapping() if x < 0 then x = 240 mapX = mapX - 30 elseif x > 240 then x = 0 mapX = mapX + 30 end if y < 0 then y = 136 mapY = mapY - 17 elseif y > 136 then y = 0 mapY = mapY + 17 end end -- screenWrapping function swingWeapon() swingTimer=swingTimer-1 if swingTimer<0 then swingTimer = 0 end if stamina<0 then stamina = 0 end if stamina>=99 then stamina = 99 end if swingTimer == 0 then stamina = stamina + 1 end if btnp(6) and swingTimer == 0 and stamina > 35 then spr(273,x+offsetX,y+offsetY,0) swingTimer=swingTimer+30 stamina=stamina-35 end end -- swingWeapon function weaponOffset() if lastDir == "down" then offsetX = 0 offsetY = 8 elseif lastDir == "up" then offsetX = 0 offsetY = -8 elseif lastDir == "left" then offsetX = -8 offsetY = 0 elseif lastDir == "right" then offsetX = 8 offsetY = 0 end end -- weaponOffset function checkPlayerButtons() if btn(2) then -- left playerShip.rotation = playerShip.rotation - playerShip.rotationSpeed cam.rotation = playerShip.rotation end if btn(3) then -- right playerShip.rotation = playerShip.rotation + playerShip.rotationSpeed cam.rotation = playerShip.rotation end playerShip.rotation = keepAngleInRange(playerShip.rotation) end -- checkPLayerButtons function drawVectorShape(shape) local firstPoint = true local lastPoint = 0 local rotatedPoint = 0 for index, point in ipairs(shape.points) do rotatedPoint = rotatePoint(point, shape.rotation) if firstPoint then lastPoint = rotatedPoint firstPoint = false else line(lastPoint.x + shape.position.x, lastPoint.y + shape.position.y, rotatedPoint.x + shape.position.x, rotatedPoint.y + shape.position.y, 8) lastPoint = rotatedPoint end end end -- drawVectorShape function rotatePoint(point, rotation) local rotatedX = (point.x * math.cos(rotation)) - (point.y * math.sin(rotation)) local rotatedY = (point.y * math.cos(rotation)) + (point.x * math.sin(rotation)) return {x=rotatedX, y=rotatedY} end -- rotatePoint function keepAngleInRange(angle) if angle < 0 then while angle < 0 do angle = angle + (2*math.pi) end end if angle > (2*math.pi) then while angle > (2*math.pi) do angle = angle - (2*math.pi) end end return angle end -- keepAngleinAngle function movePointByVelocity(object) local xSpeed = object.velocity.speed * math.cos(object.velocity.direction) local ySpeed = object.velocity.speed * math.sin(object.velocity.direction) local newPosition = { x = object.position.x + xSpeed, y = object.position.y + ySpeed } return newPosition end -- movePointByVelocity function moveCam() hitTimer = hitTimer - 1 if hitTimer < 0 then hitTimer = 0 end if btn(0) or hitTimer > 0 then camThrust() end cam.velocity.speed = cam.velocity.speed - cam.deceleration if cam.velocity.speed < 0 then cam.velocity.speed = 0 end cam.position = movePointByVelocity(cam) end -- moveCam function camThrust() local acceleration = { speed = cam.acceleration, direction = cam.rotation } cam.velocity = addVectors(cam.velocity, acceleration) end -- camThrust function addVectors(vector1,vector2) v1Comp = getVectorComponents(vector1) v2Comp = getVectorComponents(vector2) resultantX = v1Comp.xComp + v2Comp.xComp resultantY = v1Comp.yComp + v2Comp.yComp local resVector = compToVector(resultantX, resultantY) return resVector end -- addVectors function getVectorComponents(vector) local xComp = vector.speed * math.cos(vector.direction) local yComp = vector.speed * math.sin(vector.direction) local components = { xComp = xComp, yComp = yComp } return components end -- getVectorComponent function compToVector(x,y) local magnitude = math.sqrt((x*x)+(y*y)) local direction = math.atan2(y,x) direction = keepAngleInRange(direction) local vector = { speed = magnitude, direction = direction } return vector end -- compToVector function drawStars() for i=1,#s do pix( (s[i].x - (cam.position.x - 120)/ (s[i].id+1)) % 240, (s[i].y - (cam.position.y - 68)/ (s[i].id+1)) % 136,11+s[i].id) end end function updStars() for i=1,#s do s[i].x=s[i].x+1/s[i].id if s[i].x<0 then s[i].x=238 elseif s[i].x>238 then s[i].x=0 elseif s[i].y<0 then s[i].y=136 elseif s[i].y>136 then s[i].y=0 end end end function updStarsMenu() for i=1,#s do s[i].x=s[i].x+1/s[i].id if s[i].x<0 then s[i].x=238 elseif s[i].x>238 then s[i].x=0 elseif s[i].y<0 then s[i].y=136 elseif s[i].y>136 then s[i].y=0 end end end