Created
November 22, 2011 03:19
-
-
Save anonymous/1384800 to your computer and use it in GitHub Desktop.
Wizard's Fire Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Wizard's Fire 0.1 | |
function setup() | |
-- the missiles array holds the incoming fire | |
missiles = {} | |
-- the houses array holds buildings, including towers | |
houses = {} | |
-- the shot is your return fire. single shot for now | |
shot = Shot(0,0,0,0, SHOT_READY) | |
-- level has most of the info on diificulty | |
level = Level(1) | |
-- layout buildings | |
for i=1, 7 do | |
houses[i] = House(i * 100 - 100 + 70) | |
end | |
houses[1].type = HOUSE_TOWER | |
houses[7].type = HOUSE_TOWER | |
startLevel() | |
end | |
function startLevel() | |
for i=1, level.maxMissiles do | |
missiles[i] = Missile(math.random(WIDTH), HEIGHT + math.random(113), 1 + level.number/3) | |
end | |
end | |
function launchShot() | |
if shot.status == SHOT_READY then | |
if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then | |
-- find nearest tower | |
distance = 1000 | |
tower = 0 | |
for i = 1, 7 do | |
if houses[i].type == HOUSE_TOWER then | |
x = houses[i]:distance(CurrentTouch.x) | |
if x < distance then | |
distance = math.abs(houses[i].x - CurrentTouch.x) | |
tower = i | |
end | |
end | |
end | |
-- launch a shot | |
if tower > 0 and shot.status == SHOT_READY then | |
sound(SOUND_HIT,111) | |
shot = Shot(houses[tower].x, 145, CurrentTouch.x, | |
CurrentTouch.y, SHOT_IN_FLIGHT) | |
else | |
sound(SOUND_BLIT,111) | |
end | |
end | |
end | |
return nil | |
end | |
function drawLanscape() | |
fill(0, 0, 0, 255) | |
rect(0, 100, WIDTH, HEIGHT) | |
fill(33, 188, 71, 255) | |
rect(0,0,WIDTH,100) | |
for i=1, 7 do | |
houses[i]:draw() | |
end | |
return nil | |
end | |
function restartMissile(m) | |
missiles[m]:init(math.random(WIDTH /3)+111, HEIGHT + math.random(155), 1 + level.number/3) | |
end | |
-- This function gets called once every frame | |
function draw() | |
drawLanscape() | |
launchShot() | |
for i=1, level.maxMissiles do | |
if missiles[i].status < 1 then | |
missiles[i]:draw() | |
end | |
-- check to see if missiles have hit ground | |
if missiles[i].status == MISSILE_DONE then | |
houses[missiles[i].target].type = HOUSE_DESTROYED | |
sound(SOUND_EXPLODE, 111) | |
missiles[i].status = MISSILE_READY | |
level:hit() | |
elseif missiles[i].status == MISSILE_IN_FLIGHT then | |
-- check to see if missiles are destroyed | |
if shot.status == SHOT_DONE then | |
if shot:collision(missiles[i].x, missiles[i].y) then | |
sound(SOUND_EXPLODE, 111) | |
fill(255, 220, 0, 255) | |
stroke(255, 224, 0, 255) | |
ellipse(missiles[i].x, missiles[i].y, 22,33) | |
missiles[i].status = MISSILE_READY | |
level:hit() | |
end | |
end | |
end | |
if missiles[i].status == MISSILE_READY then | |
if level.hitCount >= level.totalMissiles then | |
sound(SOUND_PICKUP) | |
level = Level(level.number + 1) | |
print(level.number) | |
startLevel() | |
else | |
print(level.hitCount, level.totalMissiles) | |
restartMissile(i) | |
end | |
end | |
end | |
shot:draw() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment