Creating A Laser

BlitzPlus Forums/BlitzPlus Beginners Area/Creating A Laser

SuperSonic7(Posted 2008) [#1]
Um, I'm not so sure how I should go about creating a laser power-up. I need suggestions or source code (that is not just in the main code, preferrably make it Function friendly, make assumable variables). Any help would be appriciated.


Nate the Great(Posted 2008) [#2]
I would just draw a white line in the middle and a blue line on either side that is what I do for lasers. :)


SuperSonic7(Posted 2008) [#3]
Um, I'm looking for example code, not how to draw a laser. Not to be rude, that's just not the thing I'm looking for.


Nate the Great(Posted 2008) [#4]
Oh sorry I didn't understand what you meant. How would you want your laser to act and look?


Newcomer(Posted 2008) [#5]
Try

Function LaserUp(x,y)
If Millisecs() > LaserTimer + 3000 ;do if you havent shot a laser in 3 seconds
color 9,233,251 ;Set color to blue
for z = 0 to 4
Line x+z,y,x+z,0 ;draw a laser from the player to the top of the screen
next
color 0,0,0 ;reset color for any text or whatever later
endif
end function

;the following code will go in the main loop

if keydown(57)
space = 1 ;if the space key is pressed then prepare for laser
LaserTimer = millisecs()
endif
if space > 0
LaserUp() ;draw laser
space = space + 1 ;increase count so laser doesn't last forever or one frame
end if
if space > 10 then space = 0 ;set this so the laser will dissapear after 10 frames


;Variable declarations!!! Place the following at the top of your code

LaserTimer = millisecs()
space = 0


;P.S. Be Sure to Replace Playerx And Playery with your player coordinates


SuperSonic7(Posted 2008) [#6]
Okay,

The laser will be used for this Pacman game I'm building. Unlike the regular maze avoid ghosts eat all dots, I made it two-player and I have power-ups, so basically whoever earns the most points at the end of 3 minutes or kills their opponent wins. The power-ups are basically recieved when you eat a power-up dot (when any dot is eaten, it respawns on the field and there's a randomization system that chooses between a small dot or power-ups), and you can use them by pressing a keyboard key. I need the laser to either be a small image to start off with, then to have the image drag in the direction it's going (sorta like how images slur when the game's lagging). The laser has to follow the Pacman's direction, so if I face another direction while I am utilizing the laser the laser has to follow me like so, and also if I move vertically or horizontially. The part of the laser that goes off screen must also be deleted.