Type TAlienShip Field X:Int = 320 Field Y:Int = 0 Field Speed:Int=3 Field Image:TImage |
Function Create:TAlienShip(File:String,xstart:Int,ystart:Int) Local Ship:TAlienShip=New TAlienShip Ship.X=xstart Ship.Y=ystart Ship.Image=LoadImage(LoadBank(File)) If Ship.Image=Null Print "Not able to load image file. Program aborting" End EndIf Return Ship End Function |
| Method UpdateState() X :- Speed If X<-ImageWidth(Image) Then X=620 End Method |
| Method DrawSelf() DrawImage Image,X,Y End Method |
| ' -----------------SETUP GAME CONDITIONS-------------------- Graphics 640,480,0 Local URL:String="http::www.2dgamecreators.com/tutorials/gameprogramming/basic/" Local Player:TSpaceShip = TSpaceShip.Create(URL+"/blobship_1-1.png",320,420) Local Alien:TAlienShip = TAlienShip.Create(URL+"/cartoonufo_1-1.png",320,0) |

| ' ---------------------MAIN LOOP------------------------- Repeat Cls Player.UpdateState() Player.DrawSelf() Alien.UpdateState() Alien.DrawSelf() Flip Until KeyDown(KEY_ESCAPE) Or AppTerminate() |
' -----------------SETUP GAME CONDITIONS-------------------- Graphics 640,480,0 Local URL:String="http::www.2dgamecreators.com/tutorials/gameprogramming/basic/" Local Player:TSpaceShip = TSpaceShip.Create(URL+"/blobship_1-1.png",320,420) Local Alien:TAlienShip = TAlienShip.Create(URL+"/cartoonufo_1-1.png",320,0) ' ---------------------MAIN LOOP------------------------- Repeat Cls Player.UpdateState() Player.DrawSelf() Alien.UpdateState() Alien.DrawSelf() Flip Until KeyDown(KEY_ESCAPE) Or AppTerminate() End ' ---------------------TYPES, ATTRIBUTES AND BEHAVIOURS------------------------- Type TSpaceShip Field X:Int = 320 Field Y:Int = 420 Field Speed:Int=3 Field Image:TImage Function Create:TSpaceShip(File:String,xstart:Int,ystart:Int) Local Ship:TSpaceShip=New TSpaceShip Ship.X=xstart Ship.Y=ystart Ship.Image=LoadImage(LoadBank(File)) If Ship.Image=Null Print "Not able to load image file. Program aborting" End EndIf Return Ship End Function Method UpdateState() If KeyDown(KEY_LEFT) X :- Speed EndIf If KeyDown(KEY_RIGHT) X :+ Speed EndIf If X<0 Then X=0 If X>620 Then X=620 End Method Method DrawSelf() DrawImage Image, X,Y End Method End Type Type TAlienShip Field X:Int = 320 Field Y:Int = 0 Field Speed:Int=3 Field Image:TImage Function Create:TAlienShip(File:String,xstart:Int,ystart:Int) Local Ship:TAlienShip=New TAlienShip Ship.X=xstart Ship.Y=ystart Ship.Image=LoadImage(LoadBank(File)) If Ship.Image=Null Print "Not able to load image file. Program aborting" End EndIf Return Ship End Function Method UpdateState() X :- Speed If X<-ImageWidth(Image) Then X=620 End Method Method DrawSelf() DrawImage Image,X,Y End Method End Type |
![]() |