Picking the entity

Blitz3D Forums/Blitz3D Beginners Area/Picking the entity

I need a little help with some programming that i know how to do in 3D, but dont know in 2D.

I am making a small pong game, i guess because i am bored and want to play pong, and i ran into a problem.
I am doing the main menu, and i was going to have a start button, and simply use the Entitypickmode command to simply click on the entity and make it do something. When i run the program, i figure out entitypickmode is only a 3d command set.

I am not that familiar with the 2D commands yet (in fact im not that familiar with blitz at all :] ). Is there any 2D substitute for Entitypickmode? I would think there would be.

Thanks for your help everyone. :)

Kevin

ImagesOverlap()

Does that work with the mouse though? When i tried it did not, maybe i did not do it right though.

You could use RectsOverlap, ImagesCollide, ImageRectCollide or ImagesRectOverlap with a rectangle/image sized 1x1 at MouseX(), MouseY()

ImageRectCollide or ImagesRectOverlap

Oooh -- hadn't seen those! Definitely better than loading a hotspot image for the mouse I think. Anyway usage might be something like-a-this:

Graphics 640,480,0,2

;GUI SYS----------------------------------------\/
Type mouse
	Field xPos%
	Field yPos%
	Field image%
End Type

Function mouse_init.mouse()
	If First mouse=Null
		Local newMouse.mouse=New mouse
		newMouse\xPos=GraphicsWidth()/2
		newMouse\yPos=GraphicsHeight()/2
		newMouse\image=CreateImage(16,16)
		SetBuffer ImageBuffer(newMouse\image)
		Line 0,0,15,15:Line 0,0,6,0:Line 0,0,0,6
		Return newMouse
	Else
		RuntimeError("Only room for one mouse in this town!")
	EndIf	
End Function

Function gui_update()
	Local currentButton.button
	
	If MouseHit(1)
		For currentButton=Each button
			If ImageRectCollide(currentButton\image,currentButton\xPos,currentButton\yPos,0,currentMouse\xPos,currentMouse\yPos,1,1)
			If currentButton\clickCount=0
				currentButton\clickCount=30
			EndIf
			EndIf
		Next
	EndIf

	For currentButton=Each button
		If currentButton\clickCount=0
			DrawImage currentButton\image,currentButton\xPos,currentButton\yPos
		Else
			DrawImage currentButton\imageClicked,currentButton\xPos,currentButton\yPos
			currentButton\clickCount=currentButton\clickCount-1
		EndIf			
	Next
	
	currentMouse\xPos=MouseX()
	currentMouse\yPos=MouseY()
	DrawImage currentMouse\image,currentMouse\xPos,currentMouse\yPos
End Function

Global currentMouse.mouse=mouse_init()
HidePointer
;
;
Type button
	Field xPos%
	Field yPos
	Field image%
	Field imageClicked%
	Field clickCount%
End Type

Function gui_createButton.button(x,y,width,height,r,g,b)
	Local newButton.button=New button
	newButton\xPos=x
	newButton\yPos=y
	newButton\image=CreateImage(width,height)
	SetBuffer ImageBuffer(newButton\image)
	Color r,g,b
	Rect 0,0,width,height,True
	newButton\imageClicked=CreateImage(width,height)
	SetBuffer ImageBuffer(newButton\imageClicked)
	Rect width*.25,height*.25,width*.5,height*.5,True
	newButton\clickCount=0
End Function
;GUI SYS ENDS ----------------------------------/\


gui_createButton(10,340,150,50,200,100,100)
gui_createButton(140,10,50,150,100,200,100)
gui_createButton(10,10,100,50,100,200,200)


Color 255,255,255
SetBuffer BackBuffer()
While Not KeyHit(1)
	gui_update()
	Flip
	Cls
Wend


Ok thanks. Ill try some of those out.