Strict
Import mojo
class Bullets
Field fx:Int , fy:Int
Field canshoot:Bool = true
Field shotFired:Int
Field numBul:Int
Field bspeed:Int = 3
Method New(x:Int,y:Int)
fx = x
fy = y
End
Method Update:Int()
fy -= bspeed
Return 0
End
Method Draw:Int(fire:Image)
DrawImage(fire,fx,fy)
Return 0
End
End
Class ship Extends App
Const WIDTH:Int = 640
Const HEIGHT:Int = 480
Field score:Int = 0
Field _1up:Image
Field lives:Image[3]
Field life:Int = 3
Field lx:Int
Field ly:Int
Field bg:Image
Field p1:Image ,px:Int ,py:int
Field bulletList:List<Bullets> = New List<Bullets>()
Field enemy:Image , ex:Int , ey:Int
Field fire:Image
Field boss:Image , bx:Int , by:Int
Field b_offset:Int
Field bmin:Int
Field bmax:Int
Field bframe:Int = 0
Field hit:Bool = false
Field mid:Int
Field Benergy:Int = 98
Field BenX:Int = 10
Field P_offset:Int
Field min:Int
Field max:Int
Field speed:Int = 5
Method OnCreate:Int()
SetUpdateRate(60)
bg = LoadImage("bg.png",320,480,1,Image.MidHandle)
mid = WIDTH/2
_1up = LoadImage("lives.png",18,14,1,Image.MidHandle)
For Local i:= 0 until life
lives[i] = _1up
End
lx = 400
ly = HEIGHT - _1up.Height()
fire = LoadImage("fire.png",11,19,1,Image.MidHandle)
p1 = LoadImage("player.png",37,34,1,Image.MidHandle)
P_offset = (bg.Width() - p1.Width())/2
px = mid
py = HEIGHT - p1.Height()
min = px - P_offset
max = px + P_offset
boss = LoadImage("boss1.png",183,162,2,Image.MidHandle)
b_offset = (bg.Width() - boss.Width())/2
bx = mid
by = boss.Height() - boss.Height()/2
bmin = bx - b_offset
bmax = bx + b_offset
Return 0
End
Method OnUpdate:Int()
If KeyDown(KEY_RIGHT)
px +=speed
Else If KeyDown(KEY_LEFT)
px -=speed
End
If px >= max Then px = max
If px <= min Then px = min
If KeyHit(KEY_A)
life -= 1
End
For Local i:= eachin bulletList
i.Update()
If i.fx > bx - 50 and i.fx < bx +50 and i.fy > by + 40 and i.fy < by + 80 Or i.fx > bx - 91 and i.fx < bx +91 and i.fy > by - 81 and i.fy < by + 41
bulletList.RemoveFirst()
score += 10
hit = True
Benergy -= 1
End
Next
If hit
bframe +=1
If bframe > 1 Then bframe = 0
hit = False
End
If Benergy <= 0
End
If KeyDown(KEY_SPACE)
bulletList.AddLast(New Bullets(px,py-p1.Height()/2))
End
Return 0
End
Method OnRender:Int()
Cls 80, 80, 80
DrawImage(bg , WIDTH/2 , HEIGHT/2)
For Local i:= Eachin bulletList
i.Draw(fire)
next
DrawImage(p1, px , py)
DrawImage(boss,bx,by,bframe)
For Local i:= 0 until life
DrawImage(lives[i], lx+ i* 30,ly)
Next
SetColor 255,0,0
DrawRect(BenX,40,100,10)
SetColor 0,0,0
DrawRect(BenX+1,41,Benergy,8)
SetColor 0,255,0
DrawText("SCORE: "+ score, 10,10)
Return 0
End
End
Function Main:Int()
New ship()
Return 0
End