Jetpac laser problem

Blitz3D Forums/Blitz3D Beginners Area/Jetpac laser problem

Mick Farrow(Posted 2007) [#1]
Can anyone help me? I am trying to recreate the laser routine from Jetpac, the problem I have is understanding how to get a fixed position to fire the laser from (if I fire the laser & move the player, the laser follows!)


Amon(Posted 2007) [#2]
Have a temp Var that when you press the mouse button stores the position in it only once.

ie

if moushit 1
tempx = mousex()
endif

tempx:+5

that means it's only updated when the mouse is hit and then goes on its travels.


Mick Farrow(Posted 2007) [#3]
Thanks Amon, you've made that sound so simple! Cheers.


big10p(Posted 2007) [#4]
JetPac allows many laser shots to be fired at once, though.

I'd probably create a laser type for this and create a new instance every time fire is pressed - then have a function that updates all the types, every update.


GfK(Posted 2007) [#5]
This is in the showcase forum, why??


Mick Farrow(Posted 2007) [#6]
Oops!


Grey Alien(Posted 2007) [#7]
Yeah Big10p's is a good extension of Amon's one shot deal.


big10p(Posted 2007) [#8]
Heh - I didn't even notice this was in the wrong forum. Anyway, quick and dirty example:




Grey Alien(Posted 2007) [#9]
BlitzMax version with Delta Timing (of sorts). Try with Flip 0 instead of Flip 1, it runs the same speed. Personally I normally keep the logic separate from the drawing.

Strict

'Init
Graphics 800,600,0 'windowed mode
SeedRnd MilliSecs()

'Types
Type TLaser
	Global LASER_LEN = 500
	
	Field x,y
	Field len_ang#
End Type

Type TLaserList Extends TList
	
	Method Add(startx, starty)
		Local L:TLaser = New TLaser
		
		L.x = startx 
		L.y = starty		
		L.len_ang = 0.0
		AddLast(L)
	End Method 
	
	Method Draw()
		For Local L:TLaser = EachIn Self
			Local cur_len = (Sin(L.len_ang) * TLaser.LASER_LEN)
			If L.len_ang > 90 Then 'don't let it go beyond 90 degrees or it'll shrink!
				Remove(L)
			Else
				SetColor Rand(0,255),Rand(0,255),Rand(0,255)
				DrawLine L.x,L.y,L.x+cur_len,L.y
			
				L.len_ang = L.len_ang + (3.0*Delta)
			EndIf		
		Next
	End Method	
End Type

'Variables
Local LaserList:TLaserList = New TLaserList

'Timing
Const FRAME_LENGTH=10 'in millisecs
Global Delta#
Local LastTime = MilliSecs()

'Main Loop
While Not KeyHit(Key_escape)
	Local Current = MilliSecs()
	Local elapsed# = Current-LastTime 'float for future calcs
	'Compare elapsed against one frame which we want to be 10ms (100FPS)
	Delta = elapsed/FRAME_LENGTH	
	LastTime=Current 'keep track
	
	Local mx = MouseX()
	Local my = MouseY()
	
	If MouseHit(1) Then LaserList.Add(mx,my)	
	
	Cls		
	LaserList.Draw()
	SetColor 255,255,255
	DrawOval mx-4,my-4,9,9
	DrawText Delta,0,0
	
	Flip 1 'Vsync on
'	Flip 0 'Vsync off (note how it runs the same speed)
Wend

End



Grey Alien(Posted 2007) [#10]
With autofire and separate laser logic and drawing:




H&K(Posted 2007) [#11]
Oh come on, Post an emit sound event


Grey Alien(Posted 2007) [#12]
please write the code, I don't know it :-)


Grey Alien(Posted 2007) [#13]
Now with moving aliens and explosions via collision detection + enhanced laser and ship graphics.

Press R to summon more aliens.




H&K(Posted 2007) [#14]
You are just showing off now


agent4125(Posted 2007) [#15]
Ok, now add network multiplayer. =)


Grey Alien(Posted 2007) [#16]
just having fun. bah now it's been moved into the B3D thread.


Mick Farrow(Posted 2007) [#17]
Thanks to all for speedy replies, looking through them now!


H&K(Posted 2007) [#18]
bah now it's been moved into the B3D thread
lol, isnt Mick a B+ user?

@Mick, what language are you using?


Mick Farrow(Posted 2007) [#19]
Yes, using Blitz Plus.