![]() |
|
| Global ExpImage:Timage=LoadAnimImage(LoadBank(URL+"exp1.png"),64,64,0,16) |
| Type TExplosion Extends TGameObject Field AnimDelay:Int=10 Function Create:TExplosion(Image:TImage,xstart:Int,ystart:Int) Local obj:TExplosion=New TExplosion CreateObject(Obj,Image,xstart,ystart,2) Return obj End Function Method UpdateState() If AnimDelay<0 Then Frame :+ 1 AnimDelay=10 If Frame>15 Then TAlienShip.Create(AlienImage,X,Y) ListRemove(GameObjectList,Self) Return EndIf EndIf AnimDelay :- 1 End Method End Type |
| Type TGameObject Field X:Int = 320 Field Y:Int = 420 Field Speed:Int=3 Field Image:TImage Field Frame:Int=0 Field XScale:Float=1.0 Field YScale:Float=1.0 Method DrawSelf() SetColor 255,255,255 SetScale XScale,YScale DrawImage Image,X,Y,Frame End Method Method UpdateState() Abstract End Type |
| Method CheckCollision() For Local g:TMissile=EachIn GameObjectList CollideImage(g.Image,g.X,g.Y,0,0,AlienLayer,g) Next |
| Local p:Object[]= CollideImage(Image,X,Y,0,AlienLayer,0) For Local k:TMissile=EachIn p Explosion :+ k.Damage ListRemove(GameObjectList,k) Next |
| If Explosion > 15 ListRemove(GameObjectList,Self) TExplosion.Create(ExpImage,X,Y) EndIf |
| ResetCollisions(AlienLayer) |
| Global URL:String="http::www.2dgamecreators.com/tutorials/gameprogramming/basic/" Global ExpImage:Timage=LoadAnimImage(LoadBank(URL+"exp1.png"),64,64,0,16) Global AlienImage:TImage=LoadImage(LoadBank(URL+"cartoonufo_1-1.png")) Global PlayerImage:TImage=LoadImage(LoadBank(URL+"blobship_1-1.png")) Global MissileImage:TImage=LoadImage(BlitzMaxPath()+"\samples\firepaint\bullet.png") |
| Function CreateObject(Obj:TGameObject, Image:TImage,xstart:Int,ystart:Int,scale:Float=1.0) Obj.X=xstart Obj.Y=ystart Obj.XScale=scale Obj.YScale=Scale Obj.Image=Image If Obj.Image=Null Print "Not able to load image file. Program aborting" End EndIf ListAddLast GameObjectList, Obj End Function |
| Function LoadAnimImage:TImage( url:Object,cell_width,cell_height,first_cell,cell_count,flags=-1 ) | ||
| Load a multi-frame image. |
| Function CollideImage:Object[](image:TImage,x,y,frame,collidemask%,writemask%,id:Object=Null) | ||
| Pixel accurate collision testing between transformed Images. |
| Function ResetCollisions(mask%=0) | ||||
|
| Function SetScale( scale_x#,scale_y# ) | ||
| scale_x and scale_y multiply the width and height of drawing commands where 0.5 will half the size of the drawing and 2.0 is equivalent to doubling the size |