Simple Crosshair Movement- Help Needed
Author |
Message |
skatelhs
|
Posted: Thu May 22, 2003 9:59 pm Post subject: Simple Crosshair Movement- Help Needed |
|
|
so, im making a game ( ) for compsci class, grade 10, final evaluation.
Im doin somethin like that arcade game(like the ones in arcades), where you step on that thing and your character pops up, and you shoot. I'm not doin any poppin up actually, just people stop shooting you when you put your gun away. I'm not really too far along, I am just in the process of making the crosshair and noises. Heres the code I've got so far...
code: | var x, y, button : int
loop
Mouse.Where (x, y, button)
%CROSSHAIR
locatexy (maxx div 2, maxy div 2)
%Making "Out of Bounds" Area for crosshair
if y > 390 then
y := 390
elsif
y < 10 then
y := 10
end if
if x > maxx then
x := maxx
elsif
x < 10 then
x := 10
end if
%Triple-Thick Horizontal Line
drawline (x - 30, y, x + 30, y, black)
drawline (x - 30, y - 1, x + 30, y - 1, black)
drawline (x - 30, y + 1, x + 30, y - 1, black)
%Triple-Thick Vertical Line
drawline (x, y - 30, x, y + 30, black)
drawline (x - 1, y - 30, x - 1, y + 30, black)
drawline (x + 1, y - 30, x + 1, y + 30, black)
%Clearing Screen of Crosshair
cls
%Button-Click "Shooting"
if button = 1 then
%Gun Sound
sound (20000, 20)
sound (2000, 20)
sound (1000, 20)
sound (200, 20)
locatexy (maxx div 2, maxy div 2)
%Weird Laser Spirals
drawoval (x, y, 4, 4, red)
delay (10)
cls
drawoval (x, y, 8, 8, red)
delay (10)
cls
drawoval (x, y, 12, 12, red)
delay (10)
cls
drawoval (x, y, 18, 18, red)
delay (10)
cls
end if
%Press X to draw your weapon
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
exit
end if
end loop
end loop
|
I had a few questions about it:
1) how do i get the loop to look un-crappy? Its so friggin sketchy you can barely see it.
2) does anyone have any suggestions on stuff that will make it better?
3) Whats with that last part:
code: | var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
exit
end if
end loop |
If i leave out the
"Then
Exit"
part it doesnt ever take the "weapon" out, when i'm actually trying to make the program close when i press it? Also, how do i make it exit, say, when the key "x" is pressed, and weapon comes out when key "enter" is pressed (pretty much already like that, just dont understand how i got there)
any help would be much appreciated!
adam |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Blade
|
Posted: Fri May 23, 2003 7:53 am Post subject: (No subject) |
|
|
ok. to make the weapon stay you you have to hold the enter key for now. so make a boolean variable to check to see whether its true (out) or false (holstered). make the loop look somethin like this
code: | var holster : boolean := false
%Press X to draw your weapon
var chars : array char of boolean
if holster = false then
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
exit
holster := true
end if
end loop
elsif holster = true then
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
exit
holster := false
end if
end loop
end if |
this is just saying if holster is false it wont ask to draw your weapon. but if its true then you can press enter to draw it. but if its true then press enter to holster it.
to get rid of the crappy flashy if you are using version 4 of turing then you can use in your setscreen or View.Set "offscreenonly"
ex: View.Set("offscreenonly") and View.Update to update your graphics to the screen. |
|
|
|
|
|
skatelhs
|
Posted: Fri May 23, 2003 8:10 am Post subject: (No subject) |
|
|
I have no clue, whats this offscreenonly and viewupdate stuff? |
|
|
|
|
|
skatelhs
|
Posted: Fri May 23, 2003 8:15 am Post subject: (No subject) |
|
|
also im getting some problems with yours, the "holster" in "holster := true and holster:=false, is highlighted and it says it wont be executed |
|
|
|
|
|
Homer_simpson
|
Posted: Fri May 23, 2003 2:10 pm Post subject: (No subject) |
|
|
this solves the crappy loop problem
code: | View.Set ("offscreenonly")
var x, y, button : int := 0
loop
drawfillbox (x - 15, y - 1, x + 15, y + 1, white)
drawfillbox (x - 1, y - 15, x + 1, y + 15, white)
Mouse.Where (x, y, button)
if button not= 0 then
%shooting
drawfillbox (x - 15, y - 1, x + 15, y + 1, 12)
drawfillbox (x - 1, y - 15, x + 1, y + 15, 12)
View.Update
delay (10)
else
%notshooting
drawfillbox (x - 15, y - 1, x + 15, y + 1, 9)
drawfillbox (x - 1, y - 15, x + 1, y + 15, 9)
View.Update
delay (10)
end if
end loop
|
i'll help u with the holster thing when i get home |
|
|
|
|
|
Blade
|
Posted: Fri May 23, 2003 2:44 pm Post subject: (No subject) |
|
|
yeah. i used yer's and added in the holster. i used getch because in this case Input.KeyDown was way too fast. you push the button and it goes off and on and off and on again. lol. it ran really slowly on my comp. maybe thats just cuz its a lil screwed and needs a reformat cuz i did something to it i wasn't supossed to but here ya go.
code: | View.Set ("offscreenonly")
var holster : boolean := false
var chars : string (1)
var x, y, button : int := 0
loop
if hasch then
getch (chars)
if ord (chars) = 10 & holster = false then
holster := true
elsif ord (chars) = 10 & holster = true then
holster := false
end if
end if
if holster = false then
Mouse.Where (x, y, button)
if button not= 0 then
%shooting
drawfillbox (x - 15, y - 1, x + 15, y + 1, 12)
drawfillbox (x - 1, y - 15, x + 1, y + 15, 12)
else
%notshooting
drawfillbox (x - 15, y - 1, x + 15, y + 1, 9)
drawfillbox (x - 1, y - 15, x + 1, y + 15, 9)
end if
end if
View.Update
cls
end loop |
|
|
|
|
|
|
|
|