-- Main
--
-- Plane Crazy 0.2 --
supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)
function setup()
local i
-- targets
target = {}
for i = 1, 3 do newTarget(i) end
-- instrument panel
w = (WIDTH - 80) / 4
panelTop = w + 130
throttle = Throttle(w * 3 + 100, 60, WIDTH - 30, panelTop - 10)
horizon = Horizon(w * 3 - w/2 + 50, panelTop - w/ 2 - 10, w)
altimeter = Altimeter(w * 2 - w/2 + 30, panelTop - w/ 2 - 10, w)
speedo = Speedometer(w - w/2 + 10, panelTop - w/ 2 - 10, w)
compass = Compass( 10, 60)
flightTimer = FlightTimer(w + 30, 60, "Flight Time")
bestFlightTimer = FlightTimer(w * 2 + 50, 60, "Best Flight Time")
map = Map(WIDTH-200, HEIGHT-200, 190, 190)
logFrame = Frame(WIDTH - 145, panelTop + 10,
WIDTH - 10, panelTop + 65)
-- meshes used for ground
trees = mesh()
trees2 = mesh()
ground = mesh()
mud = mesh()
bushes = mesh()
rocks = mesh()
createMapElements()
-- state of game variables
status = 1
showLog = false
stall = false
oldTouch = nil
accelMode = false
-- button for log book check box
accelFrame = Frame(WIDTH / 2 + 10, HEIGHT - 433,
WIDTH / 2 + 35, HEIGHT - 395)
mapFrame = Frame(0, panelTop, WIDTH, HEIGHT)
-- read high score
i = readLocalData("PlaneCrazyBest")
if i ~= nil then
bestFlightTimer.val = i
end
-- Start new game
newGame()
end
function drawPlane()
local x, y
pushMatrix()
translate(WIDTH/2, HEIGHT/2-100)
rotate(180 + spinTimer)
x=70
if altimeter.val < 10 then y = 70 else
y=70-math.abs(50*horizon.pitch)
end
if crashed then
sprite("Tyrian Remastered:Explosion Huge", 0, 0, 120, 120)
timer = 0
if flightTimer.val > bestFlightTimer.val then
bestFlightTimer.val = flightTimer.val
saveLocalData("PlaneCrazyBest", bestFlightTimer.val)
end
else
tint(56, 56, 56, 37)
sprite("Tyrian Remastered:Enemy Ship B", 0,
altimeter.val/2, 70,y)
noTint()
if horizon.roll < -20 then
sprite("Tyrian Remastered:Enemy Ship B R1", 0, 0, 70,y)
elseif horizon.roll > 20 then
sprite("Tyrian Remastered:Enemy Ship B L1", 0, 0, 70,y)
else
sprite("Tyrian Remastered:Enemy Ship B", 0, 0, 70,y)
end
end
popMatrix()
end
function drawMap()
-- draw the map features
pushStyle()
pushMatrix()
rotate(heading)
translate(east + WIDTH / 2, north + HEIGHT / 2)
s = 1 - (altimeter.val / 5000)
-- scaling disabled. .
--scale(s)
line(-10000, 0, 10000, 0)
line(0, -10000, 0, 10000)
ground:draw()
mud:draw()
rocks:draw()
bushes:draw()
trees:draw()
trees2:draw()
runway:draw()
-- runway details
stroke(213, 193, 129, 255)
strokeWidth(5)
for i=1,10 do
line(0, i * 100 - 400, 0, i * 100 - 350)
end
stroke(0, 138, 255, 255)
line(-80, 800, 80, 800)
font("Futura-CondensedExtraBold")
fill(151, 151, 151, 135)
fontSize(96)
text("0 0", 0, -200)
-- targets
noFill()
strokeWidth(20)
stroke(255, 240, 0, 255)
for i=1,#target do
if target[i].z == 500 then
stroke(255, 36, 0, 104)
elseif target[i].z == 1000 then
stroke(253, 224, 3, 255)
else
stroke(0, 255, 253, 255)
end
ellipse(target[i].x, target[i].y, target[i].z)
line(target[i].x - target[i].z / 3.2,
target[i].y - target[i].z / 3.2,
target[i].x + target[i].z / 3.2,
target[i].y + target[i].z / 3.2)
line(target[i].x - target[i].z / 3.2,
target[i].y + target[i].z / 3.2,
target[i].x + target[i].z / 3.2,
target[i].y - target[i].z / 3.2)
end
popMatrix()
-- intro screen if in intro mode
if status == 1 then
font("MarkerFelt-Wide")
fontSize(222 * WIDTH / 768)
fill(0, 0, 0, 123)
text("Plane", WIDTH / 2, HEIGHT - 100)
text("Crazy", WIDTH / 2, HEIGHT - 300)
fill(255, 252, 0, 255)
text("Plane", WIDTH / 2 - 10, HEIGHT - 90)
text("Crazy", WIDTH / 2 - 10, HEIGHT - 290)
fontSize(72 * WIDTH / 768)
text("Touch here to begin", WIDTH /2, HEIGHT - 450)
end
popStyle()
end
function drawInstruments()
line(0, panelTop, WIDTH, panelTop)
fill(89, 89, 89, 255)
rect(0,0,WIDTH,panelTop)
-- instruments
horizon:draw()
throttle:draw()
altimeter:draw()
speedo:draw()
compass:draw()
flightTimer:draw(altimeter.val)
bestFlightTimer:draw(0)
end
function drawLogBook()
-- pilot log book
pushStyle()
fill(0, 0, 0, 86)
logFrame:draw()
stroke(255, 230, 0, 255)
strokeWidth(1)
rect(logFrame.right - 75, logFrame.bottom + 5, 10, 10)
fill(255, 230, 0, 255)
fontSize(14)
if accelMode then
text("Accel. Mode", throttle.frame:midX(),
throttle.frame.bottom + 5)
end
fontSize(12)
text("Pilot Log", logFrame.left + 100, logFrame.bottom + 10)
font("HoeflerText-BlackItalic")
fill(216, 216, 216, 142)
noStroke()
ellipse(logFrame.left + 30, logFrame.bottom + 28, 44)
fill(0, 0, 0, 112)
fontSize(44)
text("i", logFrame.left + 30, logFrame.bottom + 22)
popStyle()
end
function draw()
noSmooth()
background(31, 89, 36, 255)
drawMap()
drawPlane()
drawInstruments()
if status > 1 and not crashed then calcPosition() end
if status > 1 then map:draw(east, north, target) end
drawLogBook()
if showLog then
showInstructions()
end
-- touch handle
if not accelMode then
throttle:touched(CurrentTouch)
else
throttle.val = throttle.val + UserAcceleration.y * 2
if throttle.val > 100 then throttle.val = 100
elseif throttle.val < 0 then throttle.val = 0 end
end
-- check targets
for i = 1, #target do
if math.abs(north + target[i].y + 300) < target[i].z / 1.5
and math.abs(east + target[i].x) < target[i].z / 1.5 then
if target[i].z == 500 then
timer = timer + 50
elseif target[i].z == 1000 then
timer = timer + 40
else
timer = timer + 25
end
sound(SOUND_POWERUP, 26628)
newTarget(i)
end
end
if mapFrame:touched(CurrentTouch) then
if status == 1 and oldTouch ~= CurrentTouch.x then
status = 2
throttle.val = 0
newGame()
elseif showLog and oldTouch ~= CurrentTouch.x
and CurrentTouch.state == BEGAN then
if accelFrame:touched(CurrentTouch) then
accelMode = not accelMode
else
showLog = false
end
end
end
if logFrame:touched(CurrentTouch) then
if oldTouch ~= CurrentTouch.x then
showLog = true
end
end
oldTouch = CurrentTouch.x
end