
-----------------------------------
sniper
Sat Nov 12, 2005 2:31 pm

shooting game help
-----------------------------------
I am making a shooting game.  you have to shoot random targets that come up on the screen.  The problem is, is that you can press the shoot button multiple times and hit the same target and rack up the points.  How do you fix this?

-----------------------------------
Cervantes
Sat Nov 12, 2005 3:05 pm


-----------------------------------
Once you shoot the target, remove it.  This could be done a number of ways: set a boolean flag, which represents its life, to false; remove its element from a flexible array of enemies; set the pointer, which points to the monster class (or whatever you're calling it), to nil.

-----------------------------------
GlobeTrotter
Sat Nov 12, 2005 3:18 pm


-----------------------------------
You could also use a counter variable to ensure that the user can only shoot once every so often.

-----------------------------------
Flikerator
Sat Nov 12, 2005 5:05 pm


-----------------------------------
You could also use a "cooldown" between shots, limiting how fast you can shoot.

-----------------------------------
iker
Sun Nov 13, 2005 2:51 pm


-----------------------------------
You could also use a counter variable to ensure that the user can only shoot once every so often.
You could also use a "cooldown" between shots, limiting how fast you can shoot.
same thing...
anyways I'd say do what cervantes is saying, create a boolean flag on the targets such as

var hit1 : boolean := false
var point : int := 0
loop
    drawbox (10,10,20,20,blue)
    %shot taken
    %check if box is hit
    if hit1 = false then
        if x>10 blablabla then
            hit1:=true
            point += 1
        end if 
    end if
end loop


anyways if you don't get what I'm saying, just ask

-----------------------------------
Cervantes
Sun Nov 13, 2005 4:04 pm


-----------------------------------

anyways I'd say do what cervantes is saying, create a boolean flag on the targets
I made the assumption that enemies are killed in one hit.  In more complex games, this may not be the case, and the other suggestion(s) is the way to go.

Also, just a comment on the code.  
if x>10 blablabla then 
Now, I'm not going to comment on the fact that this raises an error :wink:.  
Since this is for teaching purposes, its generally a bad idea to use blabla's.  Without previous knowledge on the topic, I wouldn't be sure what you were intending to do with this line.  Especially since you already seem to have "chedk[ed] if box is hit".

-----------------------------------
sniper
Mon Nov 14, 2005 8:21 am


-----------------------------------
to Iker 
quote "Code: 

var hit1 : boolean := false 
var point : int := 0 
loop 
    drawbox (10,10,20,20,blue) 
    %shot taken 
    %check if box is hit 
    if hit1 = false then 
        if x>10 blablabla then 
            hit1:=true 
            point += 1 
        end if 
    end if 
end loop  

I understand some of it but would you please type in the whole code just to give me an idea cause I don't understand the "blablabla"?
thanks though.

-----------------------------------
Albrecd
Mon Nov 14, 2005 9:42 am


-----------------------------------
I think that by x> 10 blablabla he's doing the colision detection.

Ex:
if x_shot > x_target and x_shot < x_target + target_width and
y_shot > y_target and y_shot < y_target + target_height then
hit := true

but I could be wrong... in any case, this should work.[/quote]

-----------------------------------
iker
Mon Nov 14, 2005 7:05 pm


-----------------------------------
nope, your right, sry I didn't get around to typing that in, my rents were rushing me off of my computer, but yah, its just the collision detection to see if the mouse is in the range of being able to shoot the target...
the actual code would be


var hit1 : boolean := false
var point : int := 0
var x, y, button : int
drawbox (10, 10, 20, 20, blue)
loop
    Mouse.Where (x, y, button)
    if button = 1 then
        if hit1 = false then
            if x > 10 and x < 20 and y > 10 and y < 20 then
                %i'm using these values because those are the dimensions of the
                %box
                hit1 := true
                point += 1
            end if
        end if
    end if
    if hit1 = true then
        cls
        locate (1, 1)
        put point ..
        delay (1000)
        hit1 := false
        drawbox (10, 10, 20, 20, blue)
    end if
    locate (1, 1)
    put point ..
end loop

in this code, it will set a delay time of 1000 before you may shoot again at the same target

anyways, hopefully that helped alot more :D

-----------------------------------
sniper
Mon Nov 14, 2005 9:43 pm


-----------------------------------
alright thanks dude, it helped alot thanks !!

-----------------------------------
sniper
Tue Nov 15, 2005 9:02 am


-----------------------------------
this is my game any help for only allowing the shooter to shoot once?

setscreen ("graphics")
var x, y, y2, x3 : int
var key : array char of boolean
var chars : array char of boolean
x := 100
y := 100
var x2, y3 : real
var count : int
var ctr : int
var a, b : int
var button: int
x := 200
x3 := 15
y := 100
y2 := 15
x2 := Rand.Int (1, maxx - 1)
y3 := Rand.Int (1, maxy - 1)
ctr := 0
count := 0

View.Set ("offscreenonly")
loop


    delay (8)
    Input.KeyDown (chars)
    if ctr = 100 then
        randint (a, 50, 590)
        randint (b, 50, 350)
        drawfilloval (a, b, 50, 50, brightred)
        drawfilloval (a, b, 40, 40, white)
        drawfilloval (a, b, 30, 30, brightred)
        drawfilloval (a, b, 20, 20, white)
        drawfilloval (a, b, 10, 10, brightred)

 end if
    if ctr >= 100 and ctr = 200 and ctr = 300 and ctr = 400 and ctr = 500 and ctr = 600 and ctr = 700 and ctr = 800 and ctr = 900 and ctr = 1000 and ctr = 1100 and ctr = 1200 and ctr = 1300 and ctr = 1400 and ctr = 1500 and ctr = 1600 and ctr = 1700 and ctr = 1800 and ctr = 1800 and ctr = 1800 and ctr = 1900 and ctr = 1900 and ctr = 1900 and ctr = 2000 and ctr = 2000 and ctr = 2100 and ctr = 2200 and ctr = 2300 and ctr = 2400 and ctr = 2500 and ctr  0 then
        drawoval (x, y, x3, y2, white)
        y := y - 7

        drawoval (x, y, x3, y2, black)
    elsif chars (KEY_RIGHT_ARROW) and y < 400 then
        drawoval (x, y, x3, y2, white)
        x := x + 7

        drawoval (x, y, x3, y2, black)

    elsif chars (KEY_LEFT_ARROW) and y2 > 0 then
        drawoval (x, y, x3, y2, white)
        x := x - 7

        drawoval (x, y, x3, y2, black)
    end if
    View.Update
    drawoval (x, y, 15, 15, black)
    ctr := ctr + 1
    exit when ctr = 2600
end loop

put count
if count = 0 then
put "0% shooting, never play again" 
end if
if count = 1 then
    put "4% shooting,you should quit right now"
end if
if count = 2 then
    put "8% shooting,you suck"
end if
if count = 3 then
    put "12% shooting,you really need practice"
end if
if count = 4 then
    put "15% shooting,you still suck"
end if
if count = 5 then
    put "19% shooting,nothing to say but YOU SUCK!"
end if
if count = 6 then
    put "23% shooting,you need practice"
end if
if count = 7 then
    put "27% shooting,you still need practice"
end if
if count = 8 then
    put "31% shooting,you're not practicing enough"
end if
if count = 9 then
    put "35% shooting,you need practice"
end if
if count = 10 then
    put "38% shooting,you need practice"
end if
if count = 11 then
    put "42% shooting,you need practice"
end if
if count = 12 then
    put "46% shooting ..."
end if
if count = 13 then
    put "50% shooting, you passed"
end if
if count = 14 then
    put "54% shooting..."
end if
if count = 15 then
    put "58% shooting..."
end if
if count = 16 then
    put "62% shooting..."
end if
if count = 17 then
    put "65% shooting..."
end if
if count = 18 then
    put "69% shooting..."
end if
if count = 19 then
    put "73% shooting, ok"
end if
if count = 20 then
    put "77% shooting, you're getting there"
end if
if count = 21 then
    put "81% shooting, nice"
end if
if count = 22 then
    put "85% shooting, nicely done"
end if
if count = 23 then
    put "88% shooting, well done!"
end if
if count = 24 then
    put "92% shooting, almost perfect!!"
end if
if count = 25 then
    put "96% shooting, excellent"
end if
if count = 26 then
    put " 100% shooting, you're too good"
    end if

-----------------------------------
sniper
Tue Nov 15, 2005 9:04 am


-----------------------------------
this is my game any help for only allowing the shooter to shoot once?

setscreen ("graphics")
var x, y, y2, x3 : int
var key : array char of boolean
var chars : array char of boolean
x := 100
y := 100
var x2, y3 : real
var count : int
var ctr : int
var a, b : int
var button: int
x := 200
x3 := 15
y := 100
y2 := 15
x2 := Rand.Int (1, maxx - 1)
y3 := Rand.Int (1, maxy - 1)
ctr := 0
count := 0

View.Set ("offscreenonly")
loop


    delay (8)
    Input.KeyDown (chars)
    if ctr = 100 then
        randint (a, 50, 590)
        randint (b, 50, 350)
        drawfilloval (a, b, 50, 50, brightred)
        drawfilloval (a, b, 40, 40, white)
        drawfilloval (a, b, 30, 30, brightred)
        drawfilloval (a, b, 20, 20, white)
        drawfilloval (a, b, 10, 10, brightred)

 end if
    if ctr >= 100 and ctr = 200 and ctr = 300 and ctr = 400 and ctr = 500 and ctr = 600 and ctr = 700 and ctr = 800 and ctr = 900 and ctr = 1000 and ctr = 1100 and ctr = 1200 and ctr = 1300 and ctr = 1400 and ctr = 1500 and ctr = 1600 and ctr = 1700 and ctr = 1800 and ctr = 1800 and ctr = 1800 and ctr = 1900 and ctr = 1900 and ctr = 1900 and ctr = 2000 and ctr = 2000 and ctr = 2100 and ctr = 2200 and ctr = 2300 and ctr = 2400 and ctr = 2500 and ctr  0 then
        drawoval (x, y, x3, y2, white)
        y := y - 7

        drawoval (x, y, x3, y2, black)
    elsif chars (KEY_RIGHT_ARROW) and y < 400 then
        drawoval (x, y, x3, y2, white)
        x := x + 7

        drawoval (x, y, x3, y2, black)

    elsif chars (KEY_LEFT_ARROW) and y2 > 0 then
        drawoval (x, y, x3, y2, white)
        x := x - 7

        drawoval (x, y, x3, y2, black)
    end if
    View.Update
    drawoval (x, y, 15, 15, black)
    ctr := ctr + 1
    exit when ctr = 2600
end loop

put count
if count = 0 then
put "0% shooting, never play again" 
end if
if count = 1 then
    put "4% shooting,you should quit right now"
end if
if count = 2 then
    put "8% shooting,you suck"
end if
if count = 3 then
    put "12% shooting,you really need practice"
end if
if count = 4 then
    put "15% shooting,you still suck"
end if
if count = 5 then
    put "19% shooting,nothing to say but YOU SUCK!"
end if
if count = 6 then
    put "23% shooting,you need practice"
end if
if count = 7 then
    put "27% shooting,you still need practice"
end if
if count = 8 then
    put "31% shooting,you're not practicing enough"
end if
if count = 9 then
    put "35% shooting,you need practice"
end if
if count = 10 then
    put "38% shooting,you need practice"
end if
if count = 11 then
    put "42% shooting,you need practice"
end if
if count = 12 then
    put "46% shooting ..."
end if
if count = 13 then
    put "50% shooting, you passed"
end if
if count = 14 then
    put "54% shooting..."
end if
if count = 15 then
    put "58% shooting..."
end if
if count = 16 then
    put "62% shooting..."
end if
if count = 17 then
    put "65% shooting..."
end if
if count = 18 then
    put "69% shooting..."
end if
if count = 19 then
    put "73% shooting, ok"
end if
if count = 20 then
    put "77% shooting, you're getting there"
end if
if count = 21 then
    put "81% shooting, nice"
end if
if count = 22 then
    put "85% shooting, nicely done"
end if
if count = 23 then
    put "88% shooting, well done!"
end if
if count = 24 then
    put "92% shooting, almost perfect!!"
end if
if count = 25 then
    put "96% shooting, excellent"
end if
if count = 26 then
    put " 100% shooting, you're too good"
    end if

-----------------------------------
ZeroPaladn
Tue Nov 15, 2005 10:02 am


-----------------------------------
whoa!!!!! too much code!!!!!!! just a few suggestions...

(1) when putting up this much code, upload the .t file instead, so you dont ahve to double post, and "flood" the forums.
(2) use the code | /code tags when posting code, this saves room as well as making it readable.
(3) for the love of god use procedures!

procedure shootingTargets
for i : 200 .. 2600 by 100
if ctr >= i and ctr 