
-----------------------------------
upthescale
Sat Apr 01, 2006 12:42 pm

shooting problems
-----------------------------------
Ok, down below is some code. I want it to, when I  hit enter, shoot the square from the first square on the left.


setscreen ("graphics:300;250")
%Variables
var move : array char of boolean
var x, y, x2, y2, button, button2 : int %Snake
var foodx, foody : int %Food
var score : int := 0
var bulletx, bullety : int
%variables

bulletx := 100
bullety := 200

mousewhere (x, y, button)
process movement
    x := 10
    y := 10
    drawfillbox (x, y, x + 10, y + 10, 7)
    loop

        Input.KeyDown (move)
        if move (KEY_UP_ARROW) then
            drawfillbox (x, y, x + 10, y + 10, 7)
            delay (30)
            drawfillbox (x, y, x + 10, y + 10, 0)
            y := y + 4
        end if
        if move (KEY_DOWN_ARROW) then
            drawfillbox (x, y, x + 10, y + 10, 7)
            delay (30)
            drawfillbox (x, y, x + 10, y + 10, 0)
            y := y - 4
        end if
        if move (KEY_LEFT_ARROW) then
            drawfillbox (x, y, x + 10, y + 10, 7)
            delay (30)
            drawfillbox (x, y, x + 10, y + 10, 0)
            x := x - 4
        end if
        if move (KEY_RIGHT_ARROW) then
            drawfillbox (x, y, x + 10, y + 10, 7)
            delay (30)
            drawfillbox (x, y, x + 10, y + 10, 0)
            x := x + 4
        elsif move (KEY_ENTER) then
            mousewhere (x, x, x)
            loop
                drawfillbox (bulletx, bullety, bulletx + 20, bullety + 20, 7)
                delay (30)
                drawfillbox (bulletx, bullety, bulletx + 20, bullety + 20, 0)
                bulletx := bulletx + 2
                exit when bulletx > 200
            end loop
        else
            drawfillbox (x, y, x + 10, y + 10, 7)
        end if
        if x < -5 then
            break
        end if
        if x > 290 then
            break
        end if
        if y < 0 then
            break
        end if
        if y > 240 then
            break
        end if
        if bulletx >= x2 and bulletx = y2 and bullety  290 then
            break
        end if
        if y2 < 0 then
            break
        end if
        if y2 > 240 then
            break
        end if
        if bulletx >= x2 and bulletx = y2 and bullety  200
            end loop 


This is a problem. This means that whenever you press enter, a box will move, but the rest of your program will halt completely. No, the solution to this does not involve a process. Rather, you need to make a new pseudo-object (easily done with records and flexible arrays [see below]) that has certain properties such as position and velocity. Apply these properties (position += velocity) in the main loop.

Check out the [url=http://www.compsci.ca/v2/viewtopic.php?t=6723]Flexible Arrays Tutorial (link in Turing Walkthrough). It's got an example of shooting.

-----------------------------------
pavol
Sat Apr 01, 2006 1:04 pm


-----------------------------------
all you have to do is make bulletx and bullety equal x and y that way the bullet will come out of the box on the bottom left. and i am curious as to why you are using mousewhere :?: 
otherwise i hope it helps :)
