Interactions between diferent objects

BlitzMax Forums/BlitzMax Beginners Area/Interactions between diferent objects

redmoth(Posted 2011) [#1]
I'm new to tlists and object orientated programs
Basically I have two lists of objects, one for enemies who are red and one for the hero's who are blue.


Function CheckTile(x:Int,y:Int,team:Int) 'change the tile to the current objects team colour
		tileMap[x/tilesize,y/tilesize] = team

End Function

Function DrawMapBG() 'draw lots of white boxes, (which turn to a different colour or image once a hero or enemy moves over it)
	For Local i:Int = 0 To 31
		For Local j:Int = 1 To 22
			 DrawImage(img_box,i*32,j*32,tileMap[i,j])
		Next
	Next
End Function

Function DrawObjects()
	For Local enemy:gameObject = EachIn enemyList
		DrawImage(circRed,enemy.x,enemy.y,enemy.img)
		enemy.x:-1 'temporary, move the enemy to the left
		CheckTile(enemy.x,enemy.y,enemy.team)'check the tile
	 Next
	
	For Local hero:gameObject = EachIn heroList
		DrawImage(circBlue,hero.x,hero.y,hero.img)
		CheckTile(hero.x,hero.y,hero.team)
	Next
	

End Function



Basically, i want to check whether the enemy objects have passed the x position of the hero.
I know how to write it without objects, for example:
if enemy.x < hero.x then 'do something


but how do I do it from the two list of objects? i have no idea, where do i put it? in which for loop? or where? haha, thank you.


ImaginaryHuman(Posted 2011) [#2]
Look at

For EachIn

loop command.


Jesse(Posted 2011) [#3]
@imaginaryHuman
I think you need to actually look at his code.

@redmoth
what I usually do in with objects I usually separate processing of objects from display. I have a function that do all of the processing and one that do all of the display. simple way to do is like this:
Function CheckTile(x:Int,y:Int,team:Int) 'change the tile to the current objects team colour
		tileMap[x/tilesize,y/tilesize] = team

End Function

Function DrawMapBG() 'draw lots of white boxes, (which turn to a different colour or image once a hero or enemy moves over it)
	For Local i:Int = 0 To 31
		For Local j:Int = 1 To 22
			 DrawImage(img_box,i*32,j*32,tileMap[i,j])
		Next
	Next
End Function

Function updateallObjects()
		For Local hero:gameObject = EachIn heroList
			'do hero logic such as movement bullet shot etc..
		Next
		For Local enemy:gameObject = EachIn heroList
			'do enemy logic such as movement bullet shot etc.
			enemy.x:-1 'temporary, move the enemy to the left
		Next
		For Local enemy:gameObject = EachIn enemyList
			For Local hero:gameObject = EachIn heroList
				'do hero/enemy logic interaction
				If enemy.x < hero.x Then 'do something
			Next
		Next
End Function


Function DrawObjects()
	For Local enemy:gameObject = EachIn enemyList
		DrawImage(circRed,enemy.x,enemy.y,enemy.img)
	 Next
	
	For Local hero:gameObject = EachIn heroList
		DrawImage(circBlue,hero.x,hero.y,hero.img)
	Next
	
End Function


and just for the record that's still really farm from being OO programming. :)

Last edited 2011

Last edited 2011


Czar Flavius(Posted 2011) [#4]
for local hero:thero = eachin hero_list
	for local enemy:tenemy = eachin enemy_list
		if enemy.x < hero.x
	next
next



redmoth(Posted 2011) [#5]
@Jesse
@Czar Flavius
Thanks you two!

That's exactly what I was trying to learn:

For Local enemy:gameObject = EachIn enemyList
	For Local hero:gameObject = EachIn heroList
		'do hero/enemy logic interaction
		If enemy.x < hero.x Then 'do something
	Next
Next


It seems so simple!

Last edited 2011