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

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




PostPosted: Tue May 20, 2008 12:52 pm   Post subject: Shooting Mechanic Help

I'm making a little overhead GTA clone to refresh my Turing skills. I started with the shooting mechanic but i already have two problems. 1) Is it possible to use a multi button mouse and a keyboard at the same time in Turing and 2) How can i make it so that bullets land anywhere within the area of a circle.

Here's the code I have so far. I just started so please ignore the unused variables.

code:
setscreen ("graphics: 800;600")
View.Set ("offscreenonly")

drawfillbox (300, 100, 315, 150, black)

drawfillbox (300, 300, 315, 350, red)

var Weapon : string
var CoAx, CoAy, EnemyHP, FireMode, SemiAuto, Semi, Burst, Auto : int
var x, y, button : int
var chars : array char of boolean

Weapon := "AK-74"
Semi := 1
Burst := 0
Auto := 1
FireMode := 3
SemiAuto := 0
EnemyHP := 100
CoAx := 25
CoAy := 25
Mouse.ButtonChoose ("multibutton")

loop
    cls
    Mouse.Where (x, y, button)
    Text.Locate (1, 1)
    if FireMode = 1 then
        put "Semi"
    elsif FireMode = 2 then
        put "Burst"
    elsif FireMode = 3 then
        put "Auto"
    end if
    drawfillbox (300, 100, 315, 150, black)
    drawfillbox (300, 300, 315, 350, red)
    drawoval (x, y, CoAx, CoAy, black)
    drawfilloval (x, y, 2, 2, black)
    View.Update
    if CoAx > 25 and CoAy > 25 then
        CoAx := CoAx - 1
        CoAy := CoAx
    elsif CoAx < 25 and CoAy < 25 then
        CoAx := CoAx + 1
        CoAy := CoAx
    end if
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        if FireMode = 1 and Burst = 1 then
            FireMode := 2
        elsif FireMode = 1 and Burst = 0 and Auto = 1 then
            FireMode := 3
        elsif FireMode = 2 and Auto = 1 then
            FireMode := 3
        elsif FireMode = 2 and Auto = 0 then
            FireMode := 1
        elsif FireMode = 3 then
            FireMode := 1
        end if
    end if
    if button = 1 then
        CoAx := CoAx + 4
        CoAy := CoAx
        if CoAx > 65 then
            CoAx := 65
            CoAy := 65
        end if
    elsif button = 100 and CoAx <= 25 then
        CoAx := CoAx - 2
        CoAy := CoAx
        if CoAx < 2 then
            CoAx := 2
        end if
        if CoAy < 2 then
            CoAy := 2
        end if
    end if
    delay (25)
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 20, 2008 3:05 pm   Post subject: Re: Shooting Mechanic Help

Zeppelin @ Tue May 20, 2008 12:52 pm wrote:
Is it possible to use a multi button mouse and a keyboard at the same time in Turing

Yes. Mouse.Where and Input.KeyDown are independent.
Zeppelin @ Tue May 20, 2008 12:52 pm wrote:
How can i make it so that bullets land anywhere within the area of a circle.

This requires two random variables -- angle (between 0 and 360) and distance from the center (0 to radius). A combination of those two random values will cover the entire area of the circle.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zeppelin




PostPosted: Tue May 20, 2008 3:30 pm   Post subject: Re: Shooting Mechanic Help

Well I've been trying to figure out how to use the angles in the and I'm stumped. I got the distance from centre part but have no clue how to use angles for this.
Tony




PostPosted: Tue May 20, 2008 3:37 pm   Post subject: RE:Shooting Mechanic Help

Draw a triangle. If you know the angle and the distance from center, you can figure out the x/y points.

Sketch this out on paper. Use basic Trig.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zeppelin




PostPosted: Tue May 20, 2008 5:40 pm   Post subject: Re: Shooting Mechanic Help

I probably sound like an idiot at this point but I just can't figure out how to do this. If someone understands how to do this could you provide an example because I've been trying for 45 minutes to do this and still haven't been able to figure this out.
Zeppelin




PostPosted: Thu May 22, 2008 8:46 pm   Post subject: Re: Shooting Mechanic Help

Could someone please provide me with an example of the equasion Tony was talking about. I'm just not that great at understanding things without visuals.

EDIT: Nevermind. I asked my friend how to do this so he explained it to me.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: