Collision Detection

new topic     » topic index » view thread      » older message » newer message

Hey Guys,

I was playing around with Euphoria, and I was wondering how I would add some collision detection to this program? Its pretty simple, I just wanna add some collision detection, so I know when the images intersect with each other. Here's the code.

without warning 
without type_check 
 
include win32lib.ew 
include file.e 
include get.e 
include misc.e 
include wildcard.e 
 
if platform() != WIN32 then 
	puts(1,"Must run under Windows!\n") 
	abort(1) 
end if 
 
atom SizeX, 
SizeY 
 
SizeX = 640 
SizeY = 480 
 
constant Win = createEx(Window,"Simple Game",0,Default,Default,SizeX,SizeY,0,0), 
Stat = createEx(StatusBar,"",Win,0,0,0,0,0,0) 
 
atom Guy, 
Guy2 
Guy = loadBitmapFromFile("Stick.bmp") 
Guy2 = loadBitmapFromFile("Stick2.bmp") 
 
atom X, 
Y, 
X2, 
Y2 
 
X = 180 
Y = 35 
 
X2 = 280 
Y2 = 35 
 
procedure GameLoop(integer self, integer event, sequence parm) 
	integer key 
	key = parm[1] 
	 
	drawBitmap(Win,Guy,X,Y) 
	drawBitmap(Win,Guy2,X2,Y2) 
	 
	if key = VK_ESCAPE then 
		closeWindow(Win) 
	end if 
	 
	wPrintf({Win,1,1},"X:%d",{X}) 
	wPrintf({Win,1,12},"Y:%d",{Y}) 
	wPrintf({Win,1,25},"X2:%d",{X2}) 
	wPrintf({Win,1,42},"Y2:%d",{Y2}) 
	 
	if key = VK_LEFT then 
		X = X - 5 
		X2 = X2 + 5 
		drawBitmap(Win,Guy,X,Y) 
		repaintWindow(Win) 
	elsif key = VK_RIGHT then 
		X = X + 5 
		X2 = X2 - 5 
		drawBitmap(Win,Guy,X,Y) 
		repaintWindow(Win) 
	elsif key = VK_UP then 
		Y = Y - 5 
		Y2 = Y2 + 5 
		drawBitmap(Win,Guy,X,Y) 
		repaintWindow(Win) 
	elsif key = VK_DOWN then 
		Y = Y + 5 
		Y2 = Y2 - 5 
		drawBitmap(Win,Guy,X,Y) 
		repaintWindow(Win) 
	elsif X and Y = X2 and Y2 then 
		setText(Stat,"Images Hit") 
	end if 
	 
end procedure 
setHandler(Win,w32HPaint,routine_id("GameLoop")) 
setHandler(Win,w32HKeyDown,routine_id("GameLoop")) 
 
WinMain(Win,Normal) 

I plan on adding some other features to it later on, but I wanna get the collision detection down first.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu