Whats goin on speed prob

BlitzMax Forums/BlitzMax Programming/Whats goin on speed prob

Hi ..

Well decided that id try and make a fast little game, just to get my head round all this new OO and syntax stuff. this project when complete will be open to the community in the hope that it will help some other New ppl pick up the language easier.

Anyway onto the problem, In my bullet type I have the update method, all this really does is change the Y field of a bullet and reduce by speed to move the bullet up the screen.

But when I fire 2 bullets they move at twice the speed, and so on as I fire even more.

Rem

	Pocket Space Invaders
	By Paul Grayston (Team Rebellion Software)
	
	The Aim of this project is to create a small
	Space Invaders game using some of the new
	features found in blitz Max.
	
	This is to help me and others like me in the
	process of moving from blitz 3d to blitz max.
	
	I will do what I can to make sure as much of 
	this source is commented as possible to make
	things as clear as possible.

	Project Start Date [2nd Jan 2005 - 1Am]
	
End Rem 


Strict	 					' Force Variable Decliration.
Global GFX_Width		:Int 	= 	120
Global GFX_Height		:Int 	= 	200
Graphics GFX_Width,GFX_Height,0		' Create the Window (width,height,bit-depth(0=windowmode in beta) )


SetMaskColor 255,0,255
Global PlayerImage:Timage 	= LoadImage ("img/ship.bmp")
Global AlienImage:Timage 	= LoadImage ("img/alien.bmp")
Global blockimage:Timage 	= LoadImage ("img/block.bmp")
Global bulletImage:Timage 	= LoadImage ("img/bullet.bmp")

'
'	Fields common to all game items.
'
'


Type CommonFields
	Field X		:Int
	Field Y		:Int  
	Field speed	:Int
	Field life		:Int
	Field Sprite	:Timage
End Type

'
'
'	PLAYER CODE
'
'
'

Type player Extends CommonFields
	
	Method MoveLeft()
		Self.x:-Self.Speed
		If Self.x<1 Then Self.x=1
	End Method 	
	
	Method MoveRight()
		Self.x:+Self.Speed
		If Self.x>GFX_Width-ImageWidth(Self.sprite) Then Self.x=GFX_Width-ImageWidth(Self.sprite)
	End Method 	
		
	Method Draw()
		DrawImage Self.Sprite,Self.x,Self.y
	End Method
	
	Method Shoot()
		bullets = New bullet
	End method
	
	Method New ()
		Self.Sprite=PlayerImage
		Self.x=GFX_Width/2
		Self.y=GFX_Height-ImageHeight(Self.Sprite)
		Self.life=3
		Self.speed=2
	End Method
End Type

Global Player1:player = New player
Print Player1.x


Global AlienList:Tlist = CreateList()
Type alien Extends CommonFields
	
	
	
End Type






'
'
'	BLOCK CODE
'
'

Global Blocklist:Tlist
Blocklist = CreateList()


Type block Extends CommonFields

	Method Draw()
		DrawImage Self.Sprite,Self.x,Self.y
	End Method
	
	Method Position(newx:Int,newy:Int)
		Self.x=newx
		Self.y=newy
	End method
	
	Method New ()
		Self.Sprite=BlockImage
		MidHandleImage Self.sprite
		Self.x=x
		Self.y=y
		Self.life=3
		ListAddLast Blocklist,Self
	End Method
End type

Global Blocks:Block

'
'
'	BULLET CODE
'
'
Global Bulletlist:Tlist = CreateList()
Global BulletCount:Int
Type bullet Extends CommonFields
	
	
	Method New()
	Print "Creating New Bullet"
		self.speed=2	
		self.sprite=BulletImage
		self.x=player1.x
		self.y=player1.y
		ListAddLast bulletlist,self
		BulletCount:+1
	End method	
	
	Function update()
	
		If Not ListIsEmpty(bulletlist)
			For bullets = EachIn bulletlist
				bullets.y:-bullets.speed

				If bullets.y<0 Then 
					bulletlist.remove bullets 'rem << stop the crappy ide colour bug
					FlushMem  
					BulletCount:-1
				End If
			Next
		End If
		
	End Function
	
	Function Draw()
		For bullets = EachIn bulletlist
			DrawImage bullets.sprite,bullets.x,bullets.y
		Next
	End Function
	
End Type

Global Bullets:Bullet



'Create 3 Blocks

For Local looper:Int =1 To 3
	blocks:Block = New Block
		Blocks.position( (Looper*((GFX_Width/3)-10)),(GFX_Height-10-(ImageHeight(player1.sprite)) ) )
Next


While Not KeyHit(KEY_ESCAPE)
	Cls							'	Clear the screen.
	
		Update()
		Render()
		
	FlushMem
	Flip			'	Clear out any unused memory and flip the back buffer.
Wend


Function Update()
	
	'Call the player move left and right methods.
	If KeyDown(KEY_LEFT)
		player1.moveleft()
	End If 
	
	If KeyDown(KEY_right)
		player1.moveright()
	End If 
	
	If KeyHit(KEY_UP)
		player1.shoot()
	End If
	
	For bullets = EachIn BulletList
		bullets.update()
	Next
	
End Function

Function Render()
	
	DrawText ("Bullets = "+BulletCount,1,1)
		
	Player1.Draw()
	
	'Draw All Blocks
	For blocks = EachIn BlockList
		blocks.draw()
	Next
	
	For bullets = EachIn BulletList
		bullets.draw()
	Next
	
End Function






You are going over the list of bullets recursively (or is it exponentially? :) )

For bullets = EachIn BulletList
-> Goes to function bullets.update()
-> which does
-> For bullets = eachin BulletsList
-> add speed to this bullet
-> Next
Next

OMG so I am.

Dood I would have been here till 4AM trying to track that down lol.(2AM now)

thanks.