Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 shooting problems
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
upthescale




PostPosted: Sat Apr 01, 2006 12:42 pm   Post subject: 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.

code:

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 <= x2 + 20 and bullety >= y2 and bullety <= y2 + 20 then %%
            break
        end if
    end loop
end movement

mousewhere (x2, y2, button2)
process movement1
    x2 := 140
    y2 := 200
    drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
    loop
        Input.KeyDown (move)
        if move ('w') then
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
            delay (30)
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 0)
            y2 := y2 + 4
        end if
        if move ('s') then
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
            delay (30)
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 0)
            y2 := y2 - 4
        end if
        if move ('a') then
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
            delay (30)
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 0)
            x2 := x2 - 4
        end if
        if move ('d') then
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
            delay (30)
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 0)
            x2 := x2 + 4
        else
            drawfillbox (x2, y2, x2 + 10, y2 + 10, 7)
        end if
        if x2 < -5 then
            break
        end if
        if x2 > 290 then
            break
        end if
        if y2 < 0 then
            break
        end if
        if y2 > 240 then
            break
        end if
        if bulletx >= x2 and bulletx <= x2 + 20 and bullety >= y2 and bullety <= y2 + 20 then %%
            break


        end if
    end loop
end movement1


%Forks
fork movement
fork movement1
%Forks



If you can fix it up it would be great!

Mod Edit: Sure thing. Spelling and grammar has been fixed up and code tags added.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Apr 01, 2006 1:00 pm   Post subject: (No subject)

Avoid processes!

You don't need them for this sort of thing (if I understand what you're trying to do -- haven't run the code).

upthescale wrote:

code:

        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


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 Flexible Arrays Tutorial (link in Turing Walkthrough). It's got an example of shooting.
pavol




PostPosted: Sat Apr 01, 2006 1:04 pm   Post subject: (No subject)

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 Question
otherwise i hope it helps Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: