Computer Science Canada

Shoot a gun

Author:  paintball_guy [ Wed Apr 09, 2003 5:51 pm ]
Post subject:  Shoot a gun

HEY! 8) I'm making this asteroids program where the space ship moves along the bottom x-axis and when you hit the "8" key on the number pad it shoots a little red lazer... Right now when i do that it makes one lazer and u haveto hold the key down to make it move... how do i make it so u press 8 once and it send a little red lazer moving straight up along the y-axis??? Thanks


elsif move = "8" then
Pic.ScreenLoad ("lazer.jpg", x9 + 25, y10, picCopy)
y10 := y10 + 10
end if
thats the script that makes it go up when u hold "8" help plz...

Author:  Tony [ Wed Apr 09, 2003 6:51 pm ]
Post subject: 

you can read a tutorial on processes. This way you can program lazer to run independantly of the rest of the program

a better way however would be to use hasch function and put the lazer in same loop

code:

loop

if hasch then %if button is pressed
getch(c)
end if

if lazeron = true then %if lazer is currently on screen
lazerY += 5 %move lazer
end if

%move spaceship here

end loop


hasch returns true if there's a key in input buffer. Using above code you can bypass getch if no key is pressed and execute the rest of your code without waiting to press a key. Thats how you code snake and/or pacman to keep on moving untill another buttom is pressed

Author:  paintball_guy [ Wed Apr 09, 2003 7:10 pm ]
Post subject:  Re:

I have no idea what you just put.... it gave me like 40 errors... i'm not the greatest Turist... Sad Anyways heres my script.... Can you plz help me? thanx




%%%%%%%%%%%%%%%%%%
%1337 4@xX0r5
%Meteor Storm
%April 8 2003
%%%%%%%%%%%%%%%%%%
setscreen ("graphics:500;500, nocursor, noecho")
var hp, rp, rocket1 : int %repeats meteors axis of rocket for shooting
%draw meteor 1
drawfilloval (200, 200, 20, 20, brown)
%take picture
hp := Pic.New (180, 180, 250, 250)
cls
%%%%%%%%%%%%%%%%%%%%%%%%%%%

process rocket
var x9, x10 : int
var y9, y10 : int

var move : string (1)
%initialize variables
x9 := 200
y9 := 0
y10 := 10
loop
Pic.ScreenLoad ("rocket.jpg", x9, 0, picCopy)
if hasch then
getch (move)
if move = "4" then
x9 += -40
elsif move = "6" then
x9 += +40
elsif move = "8" then
Pic.ScreenLoad ("lazer.jpg", x9 + 25, y10, picCopy)
y10 := y10 + 10
end if
end if
delay (10)
cls
if x9 < 0 then
x9 = 0
elsif x9 >= 445 then
x9 = 500 - 60
end if
end loop
end rocket

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ball1
var x1, y1 : int %x and y coord of meteors
loop
randint (x1, 1, 480)
y1 := maxy
loop
y1 := y1 - 1
%Draw the meteor
Pic.Draw (hp, x1, y1, picCopy)

delay (10)

end loop
end loop
end ball1
process ball2
var x2, y2 : int %x and y coord of meteors, lr action, ud action

loop
randint (x2, 1, 400)
delay (Rand.Int (500, 3000))
y2 := maxy
loop
y2 := y2 - 1
%Draw the meteor
Pic.Draw (hp, x2, y2, picCopy)
delay (10)

end loop
end loop
end ball2
process ball3
var x3, y3 : int %x and y coord of meteors, lr action, ud action

loop
randint (x3, 1, 400)
delay (Rand.Int (500, 3000))
y3 := maxy
loop
y3 := y3 - 1
%Draw the meteor
Pic.Draw (hp, x3, y3, picCopy)
delay (10)

end loop
end loop
end ball3
process ball4
var x4, y4 : int %x and y coord of meteors, lr action, ud action

loop
randint (x4, 1, 400)
delay (Rand.Int (1500, 3000))
y4 := maxy
loop
y4 := y4 - 1
%Draw the meteor
Pic.Draw (hp, x4, y4, picCopy)
delay (10)

end loop
end loop
end ball4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fork rocket
fork ball1
fork ball2
fork ball3
fork ball4

Author:  void [ Wed Apr 09, 2003 7:25 pm ]
Post subject: 

if you want to have better results zip all of your files into one zip and add it as an attachement thus making it easier for us to run and compile the program while editing Wink .....i copied and pasted the code and it didnt even run.....the thing shut down due to too many errors j/k....i din realize u used pictures..but when i ran it its like "NO PICTURE THERE H0M0"


: