Jetpac laser problem
Blitz3D Forums/Blitz3D Beginners Area/Jetpac laser problem
| ||
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!) |
| ||
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. |
| ||
Thanks Amon, you've made that sound so simple! Cheers. |
| ||
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. |
| ||
This is in the showcase forum, why?? |
| ||
Oops! |
| ||
Yeah Big10p's is a good extension of Amon's one shot deal. |
| ||
Heh - I didn't even notice this was in the wrong forum. Anyway, quick and dirty example: |
| ||
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 |
| ||
With autofire and separate laser logic and drawing: |
| ||
Oh come on, Post an emit sound event |
| ||
please write the code, I don't know it :-) |
| ||
Now with moving aliens and explosions via collision detection + enhanced laser and ship graphics. Press R to summon more aliens. |
| ||
You are just showing off now |
| ||
Ok, now add network multiplayer. =) |
| ||
just having fun. bah now it's been moved into the B3D thread. |
| ||
Thanks to all for speedy replies, looking through them now! |
| ||
bah now it's been moved into the B3D thread lol, isnt Mick a B+ user?@Mick, what language are you using? |
| ||
Yes, using Blitz Plus. |