Created
October 5, 2012 18:18
-
-
Save Synvox/3841469 to your computer and use it in GitHub Desktop.
Boss
This file contains hidden or 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
| --# Main | |
| World = class() | |
| function World:init() | |
| self.instances={} | |
| self.width=1024 | |
| self.height=768 | |
| self.index=0 | |
| end | |
| function World:update() | |
| for i,obj in ipairs(self.instances) do | |
| self.index=i | |
| --for j,other in ipairs(self.instances) do | |
| --end | |
| obj:update() | |
| end | |
| end | |
| function World:draw() | |
| background(0, 0, 0, 255) | |
| for i,obj in ipairs(self.instances) do | |
| self.index=i | |
| obj:draw() | |
| end | |
| end | |
| function World:add(inst) | |
| table.insert(self.instances,inst) | |
| end | |
| function World:remove() | |
| table.remove(self.instances,self.index) | |
| end | |
| function setup() | |
| displayMode(FULLSCREEN) | |
| world=World() | |
| for i=1,200 do | |
| world:add(Star()) | |
| end | |
| ship=Ship(400,300) | |
| world:add(ship) | |
| boss=Boss(200,HEIGHT-200) | |
| world:add(boss) | |
| end | |
| function draw() | |
| world:update() | |
| world:draw() | |
| end | |
| --# Star | |
| Star = class() | |
| function Star:init() | |
| self.x = math.random(WIDTH) | |
| self.y = math.random(HEIGHT) | |
| self.size=math.random() | |
| end | |
| function Star:update() | |
| -- Codea does not automatically call this method | |
| self.y = self.y - 11*self.size | |
| if self.y<0 then | |
| self.y = self.y + HEIGHT | |
| self.x = math.random(WIDTH) | |
| end | |
| end | |
| function Star:draw() | |
| -- Codea does not automatically call this method | |
| fill(255, 255, 255, self.size*255) | |
| ellipse(self.x,self.y,5*self.size,5*self.size) | |
| end | |
| --# Ship | |
| Ship = class() | |
| function Ship:init(x,y) | |
| self.x = x | |
| self.y = y | |
| self.counter=40 --this number is a timer for shooting. | |
| end | |
| function Ship:update() | |
| self.px=self.x | |
| self.py=self.y | |
| self.x = self.x + Gravity.x*20 | |
| self.y = self.y + (Gravity.y+0.2)*18 | |
| --if self.y>HEIGHT/3 then | |
| -- self.y=HEIGHT/3 | |
| --end | |
| self.counter = self.counter + 1 | |
| if self.counter>=30 then | |
| --sound(SOUND_SHOOT, 47057) | |
| self.counter=0 | |
| local bullet=ShipBullet(self.x,self.y) | |
| world:add(bullet) | |
| end | |
| end | |
| function Ship:draw() | |
| if math.abs(Gravity.x)<.05 then | |
| sprite("Tyrian Remastered:Ship C",self.x,self.y) | |
| elseif Gravity.x<0 then | |
| sprite("Tyrian Remastered:Ship C L1",self.x,self.y) | |
| else | |
| sprite("Tyrian Remastered:Ship C R2",self.x,self.y) | |
| end | |
| end | |
| --# ShipBullet | |
| ShipBullet = class() | |
| function ShipBullet:init(x,y) | |
| self.x=x | |
| self.y=y | |
| end | |
| function ShipBullet:update() | |
| self.y = self.y + 16 | |
| if self.y>world.width then | |
| world:remove() | |
| end | |
| if math.sqrt(math.pow((boss.x-self.x),2)+math.pow((boss.y-self.y),2))<80 then | |
| world:add(Explosion(self.x,self.y)) | |
| sound(SOUND_EXPLODE, 25890) | |
| world:remove() | |
| end | |
| end | |
| function ShipBullet:draw() | |
| sprite("Tyrian Remastered:Bullet Fire A",self.x,self.y) | |
| end | |
| --# Boss | |
| Boss = class() | |
| function Boss:init(x,y) | |
| self.x=x | |
| self.y=y | |
| self.vel=2 | |
| self.counter=20 | |
| self.side=1 | |
| end | |
| function Boss:update() | |
| self.x = self.x + (ship.x-self.x)/40 | |
| self.counter = self.counter + 1 | |
| if self.counter>=40 then | |
| --sound(SOUND_SHOOT, 47057) | |
| self.counter=0 | |
| local bullet=BossBullet(self.x+(self.side*48),self.y-64) | |
| world:add(bullet) | |
| self.side=-self.side | |
| end | |
| end | |
| function Boss:draw() | |
| sprite("Tyrian Remastered:Boss B",self.x,self.y) | |
| end | |
| --# Explosion | |
| Explosion = class() | |
| function Explosion:init(x,y) | |
| -- you can accept and set parameters here | |
| self.x = x | |
| self.y = y | |
| self.life=20 | |
| end | |
| function Explosion:update() | |
| -- Codea does not automatically call this method | |
| self.y = self.y - 2 | |
| self.life = self.life - 1 | |
| if self.life<0 then | |
| world:remove() | |
| end | |
| end | |
| function Explosion:draw() | |
| pushStyle() | |
| tint(255, 255, 255, 255*(self.life/20)) | |
| sprite("Tyrian Remastered:Bullet Fire C",self.x,self.y) | |
| popStyle() | |
| end | |
| --# BossBullet | |
| BossBullet = class() | |
| function BossBullet:init(x,y) | |
| self.x = x | |
| self.y = y | |
| self.vel=-10 | |
| end | |
| function BossBullet:update() | |
| self.x = self.x + (ship.x-self.x)/30 | |
| self.vel = self.vel - .1 | |
| self.y = self.y + self.vel | |
| if (self.y<-100) then | |
| world:remove() | |
| end | |
| if math.sqrt(math.pow((ship.x-self.x),2)+math.pow((ship.y-self.y),2))<30 then | |
| world:add(BigExplosion(self.x,self.y)) | |
| sound(SOUND_EXPLODE, 25880) | |
| world:remove() | |
| end | |
| end | |
| function BossBullet:draw() | |
| sprite("Tyrian Remastered:Flame 1",self.x,self.y) | |
| end | |
| --# BigExplosion | |
| BigExplosion = class() | |
| function BigExplosion:init(x,y) | |
| -- you can accept and set parameters here | |
| self.x = x | |
| self.y = y | |
| self.life=20 | |
| end | |
| function BigExplosion:update() | |
| -- Codea does not automatically call this method | |
| self.y = self.y - 8 | |
| self.life = self.life - 1 | |
| if self.life<0 then | |
| world:remove() | |
| end | |
| end | |
| function BigExplosion:draw() | |
| pushStyle() | |
| tint(255, 255, 255, 255*(self.life/20)) | |
| sprite("Tyrian Remastered:Explosion Huge",self.x,self.y) | |
| popStyle() | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment