Playing around with BlitzMax Demo...

BlitzMax Forums/BlitzMax Beginners Area/Playing around with BlitzMax Demo...

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.

Heres a good pdf that goes over all of the basics, then more cool stuff like arrays and oop and then some more basic (yet cool) stuff. This is a must read. Theres also lots of stuff on collision code I've yoinked off the internet and other various places...

One from a tutorial on bm
Graphics 640,480,0
AutoMidHandle True

Type ball
	Field image:timage
	Field name$

	Method New()
		Cls
		DrawOval 0,0,64,64
		image=CreateImage(64,64,1,DYNAMICIMAGE|MASKEDIMAGE)
		GrabImage image,0,0
	End Method
End Type

Local a:ball = New ball
Local b:ball = New ball
Local player:ball = New ball

a.name = "Ball a"
b.name = "Ball b"
player.name = "Ball player"

'cList is used to store a list of collided Objects
Local cList:Object[] = Null


SetBlend ALPHABLEND
		
While Not KeyHit(KEY_ESCAPE)
	Cls
	Local x%=MouseX()
	Local y%=MouseY()
	
	'Clear collision mask layer 1
	ResetCollisions(1)
	
	'Write image a.image into collision layer mask 1, and also store a link to Object a
	CollideImage a.image,50,50,0,0,COLLISION_LAYER_1,a
	DrawImage a.image,50,50

	'Write image b.image into collision layer mask 1, and also store a link to Object b
	CollideImage b.image,150,50,0,0,COLLISION_LAYER_1,b
	DrawImage b.image,150,50
	
	'Before we draw c.image, test if it will collide with anything in collision layer mask 1
	cList = CollideImage(player.image,x,y,0,COLLISION_LAYER_1,0)
	
	'Check the collision count
	If cList.length > 0
		'One or more collisions has happened!
		'change the alpha level as a visual indication
		SetAlpha .5
	Else
		SetAlpha 1.0
	End If
	
	'Draw player.image
	DrawImage player.image,x,y
	
	'Reset the alpha
	SetAlpha 1
	
	'Print a list of collision Objects names
	For Local i%=1 To cList.length
		'Remember, cList will contain Objects! We can cast them back to Types like so: ball(cList[x])
		'We could if needed check the Type of Object the player collided with using a cast check
		'If ball(cList[0]) = True 'cList[0] is a 'ball' Type
		DrawText("player.image collided with Object "+ball(cList[i-1]).name,5,150+(i*12))
	Next
	
	Flip
	
	'Free the old collision list
	cList = Null
'	FlushMem
Wend


Another one from I don't know where...
Strict

Local rot,x,y

Graphics 640,480

AutoMidHandle True	'image will rotate around it's center

Local image:TImage=LoadImage("gfx\player.bmp")
Local image2:TImage=LoadImage("gfx\bullet.bmp")

While Not KeyHit(KEY_ESCAPE)
	Cls
	ResetCollisions

' draw the first image at 5 times the size and on an arbitrary angle
	
	SetScale 5,5
	SetRotation 125

	DrawImage image,200,200

' add the first image to the first collision layer at same postion, rotation 
' and scale as it has just been drawn

	CollideImage image,200,200,0,0,6

' move the other image relative to the mouse and rotate it continuously

	x=MouseX()
	y=MouseY()-20
	rot:+1

	SetRotation rot
	DrawImage image2,x,y

' test the image at it's current rotation, scale and position with images
' that have been added to the first collision layer

	If CollideImage(image2,x,y,0,6,0)

' reset scale and rotation states so our text is drawn correctly		

		SetScale 1,1
		SetRotation 0
		DrawText "COLLISION!",20,20

	EndIf

	Flip
Wend


One I yoinked off the internet...
Graphics 1024,768,32,60,1

Global tList:TList = New TList

Type img
	Field image:timage
	Field x:Float,y:Float
	Field sx:Float,sy:Float
	Field r:Float,sr:Float
	
	Function Create:img(f:String)
		i:img = New img
		i.image = LoadImage(f)
		i.x		= Rnd(20,620)
		i.y		= Rnd(20,460)
		i.sx	= Rnd(-1,1)
		i.sy	= Rnd(-1,1)
		i.r		= Rnd(0,360)
		i.sr	= Rnd(-1,1)
		tList.Addlast i
		Return i
	End Function
	
	Method Update()
		x :+ sx
		y :+ sy
		r :+ sr
		If x>620 And sx>0
			sx = -sx
		ElseIf x<20 And sx<0
			sx = -sx			
		EndIf
		If y>460 And sy>0
			sy = -sy
		ElseIf y<20 And sy<0
			sy = -sy
		EndIf
		
		SetBlend ALPHABLEND
		SetScale 3,3
		SetRotation r
		SetColor 255,255,255
		
		' Draw this image in collision layer 1
		CollideImage(image,x,y,0,0,1)
		' Test all other images with collision layer 1
		For Local i:img = EachIn tList
			If i<>Self
				' This tests i.image for collision with layer 1
				If CollideImage(i.image,i.x,i.y,0,1,0)
					' We have a collision so let's make it red!
					SetColor 255,0,0
				EndIf
			EndIf
		Next
		' Clear all collision layers
		ResetCollisions()
		DrawImage image,x,y
	End Method
	
End Type

For j = 0 To 9
	i:img = img.create("gfx\bullet.bmp")
	MidHandleImage( i.image )
Next

Repeat
	
	Cls
	
	For i:img = EachIn tList
		i.Update()
	Next
	
	Flip
'	FlushMem
	
Until KeyHit(KEY_ESCAPE)


and another one I yoinked off the internet...
Global foodlayer = 1

Type Food
	Global List:TList = New TList
	Field x,y
		
	Function Create:Food(x,y)
		Local f:Food = New Food
		f.x=x
		f.y=y
		List.Addlast(f)
		Return f
	End Function
	
	Function UpdateAll()
		For Local f:Food = EachIn List
		f.Update()
		Next
	End Function 
	
	Method Render()
	SetColor 0,255,0
	DrawRect x,y,7,7
	SetColor 255,255,255
	
	End Method
	
	Method Update()
	
	Render()
	
	Local Collided:Object[], CollidedObj:Object, G:Gog
		
	Collided = CollideRect(X,Y,7,7,FoodLayer,0,Self)
	
	For CollidedObj = EachIn Collided
	If Gog(CollidedObj)
		Print 1
		G = Gog(CollidedObj)
		G.Energy:+10
		Food.List.Remove(Self)
		Exit
	End If
	Next
	
	End Method
	
End Type

Type Gog
	Field x,y
	Field Energy
	
	Function Create:gog(x,y)
		Local g:gog = New gog
		g.x=x
		g.y=y
		Return g
	End Function
	
	Method Update()
	
	DrawRect(x,y,7,7)
	DrawText Energy,x+10,y+10
	CollideRect(x,y,7,7,0,FoodLayer,Self)
	
	End Method
End Type

Graphics 800,600,0,-1



For Local I:Int = 0 To 30 
	Food.Create(Rnd(0,800),Rnd(0,600))
Next

Local G:Gog = Gog.Create(MouseX(),MouseY())

While Not KeyHit(key_escape)

ResetCollisions()

G.X = MouseX()
G.Y = MouseY()

G.Update()
Food.UpdateAll()



Flip
Cls
Wend


If you really want to go mad and kill yourself then theres more confusing things like asteroids in an hour or so that you probably don't care about in the tutorials forum so check out the tutorials section some time :)

but I would recommend staying with blitz-whatsit that you've already got.