Create a 2d Shoot'em Up

BlitzMax Forums/BlitzMax Tutorials/Create a 2d Shoot'em Up

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

My first collisions experiment:
Graphics 640,480,0

Type TPlayer
	Field X:Int
	Field Y:Int
	Field img:TImage
	
	Method CheckInput()
		X = MouseX()
		Y = MouseY()
	End Method
	
	Method Draw()
		DrawImage(img,X,Y)
	End Method

	Function Create:TPlayer(X,Y,ImageFile$)
		Local p:TPlayer = New TPlayer
			p.X = X
			p.Y = Y
			p.img = LoadImage(ImageFile$,0)
		Return p
	End Function
End Type

Type TBlock
	Field X
	Field Y
	Field Img:TImage
	
	Function create:TBlock()
		Local b:TBlock = New TBlock
			b.X = Rand(0,800)
			b.Y = Rand(0,600)
			b.Img = LoadImage("ball.png")
		Return b
	End Function
End Type

Global p1:TPlayer = TPlayer.Create(100,100,"test.png")
Global block:TImage = LoadImage("ball.png",0)
Global blockArray:TBlock[50]

For Local i = 0 To 49 
	blockArray[i] = TBlock.Create()
Next

While Not KeyDown(KEY_ESCAPE)
p1.CheckInput()
p1.Draw()

'DrawImage(Block,200,200)

For Local c = 0 To 49
	DrawImage(blockArray[c].img, blockArray[c].X, blockArray[c].Y)
	If ImagesCollide(p1.img, p1.X, p1.Y, 0, blockArray[c].img, blockArray[c].X,blockArray[c].Y,0) Then DrawImage(Block, 0,0)
Next

Flip
Cls
Wend

End