For...Next help

Blitz3D Forums/Blitz3D Programming/For...Next help

Jerome Squalor(Posted 2008) [#1]
hey all, i am having some trouble with a small game i am trying to make. it consists of one space ship(player) which starts at the bottom middle of the screen. it is controlled with the arrow keys. you shoot with space. the enemies pretty much fly around until they get near the player. then the start shooting at and following you. here is my problem. when i have one enemy, everything is fine. but when i put a for next loop around th CreateEnemy() command, the player's bullets start moving super fast. can someone help me solve this issue?

ps u might have to change the Graphics 1280,1024,0,2 to a lower resolution.

Here is the source code
Source


thnx


boomboom(Posted 2008) [#2]
in your update bullet code, replace:
				If b\from = 1
			
					For e.enemy = Each enemy

						If ImagesOverlap(b\image,b\x#,b\y#,e\image,e\x#,e\y#)
				
							CreateExplosion(b\x#,b\y#)
							b\draw = 0
						
						EndIf
					
					Next
					
					DrawImage b\image,b\x#,b\y#
					b\y# = b\y# + b\yv#
					
				End If	


you were basically drawing a bullet for the players rocket for each enemy, so you where drawing 6 bullet graphics for the player if it didn't collide with an enemy.

Also, in your 'CreateBullet' function, its best not to be loading in a image file from the hdd. Much better would be for you to create a collection of resources that you can load in at the start of the level, such as commonly used graphics, and then copy/draw them as needed. It will save a lot of time for loading and memory space. (if everyone has the same bullet graphic then load it in once in a resources type, or global variable and just use that to draw)


Jerome Squalor(Posted 2008) [#3]
thanks it works fine now.