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

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




PostPosted: Sun Jan 01, 2006 3:08 pm   Post subject: Parabola issue

Okay, heres the deal, I'm working on an artillery style game, with two tanks on a random terrain, which shoot (turn based) at each other. The player chooses the angle (left and right arrows) and the power (up and down arrows) of the shot. However, to simulate gravity, im using parabolas, which is very hard to do, considering i've only learned how to graph parabolas using the vertex in math. I have a good chunk of it down pat, but it seems the parabola always starts at the wrong height (sometimes even off the screen). I was wondering if anyone could give me a hand with this.

(Please note the messyness, im just learning Razz )

code:

cls
setscreen ("Graphics: 1000;500")

%TERRAIN GENERATOR
var upordown, y1, yfill : int
randint (y1, 100, 150)

for x1 : 1 .. 1000
    randint (upordown, 1, 2)
    yfill := y1
    loop
        drawdot (x1, yfill, black)
        yfill := yfill - 1
        exit when yfill = 0
    end loop


    if upordown = 1 then
        y1 := y1 + 1
    else
        y1 := y1 - 1
    end if


end for
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%PLAYER PERAMITERS
var p1health, p2health : int
var p1angle, p2angle : real
var p1power, p2power : int
var p1locationy, p1locationx, p2locationy, p2locationx : int
p1power := 200
p2power := 200
p1angle := 0.0001
p2angle := 0.005



%PLAYER 1 LOCATION GENERATOR
randint (p1locationx, 10, 450)
p1locationy := 400
loop
    if whatdotcolor (p1locationx, p1locationy) not= black then
        p1locationy := p1locationy - 2
    end if
    exit when whatdotcolor (p1locationx, p1locationy) = black
end loop

%TANK LOCATION
var player1tank : int
player1tank := Pic.FileNew ("orange_tank.jpg")
Pic.Draw (player1tank, p1locationx, p1locationy, picCopy)
Pic.Free (player1tank)

%TURRET LOCATION
var player1turretx, player1turrety : int
player1turretx := p1locationx + 25
player1turrety := p1locationy + 22
drawline (p1locationx + 15, p1locationy + 12, player1turretx, player1turrety, black)




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%PLAYER 2 LOCATION GENERATOR
randint (p2locationx, 460, 690)
p2locationy := 400
loop
    if whatdotcolor (p2locationx, p2locationy) not= black then
        p2locationy := p2locationy - 2
    end if
    exit when whatdotcolor (p2locationx, p2locationy) = black
end loop


%TANK LOCATION
var player2tank : int
player2tank := Pic.FileNew ("blue_tank.jpg")
Pic.Draw (player2tank, p2locationx, p2locationy, picCopy)
Pic.Free (player2tank)

%TURRET LOCATION
var player2turretx, player2turrety : int
player2turretx := p2locationx + 25
player2turrety := p2locationy + 22
drawline (p2locationx + 15, p2locationy + 12, player2turretx, player2turrety, black)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PLAYER 1 MOVE

var p1prepare : string (1)
var p1shotx2, p1shoty2 : int
var newplayer1turrety, newplayer2turrrety : int
newplayer1turrety := -10


%%%ANGLE%%%


%MOVE TURRET TO THE LEFT
process turretmoveleft
    loop
        getch (p1prepare)
        if ord (p1prepare) = 203 then
            drawline (p1locationx + 15, p1locationy + 12, player1turretx, player1turrety, white)     %ERASE OLD TURRET
            if player1turretx >= p1locationx + 15 then
                player1turretx := player1turretx - 2
                player1turrety := player1turrety + 1
                p1angle := p1angle - 0.0005
                newplayer1turrety := newplayer1turrety - 5
            else
                player1turretx := player1turretx + 2
                player1turrety := player1turrety - 1
                p1angle := p1angle + 0.0005
                newplayer1turrety := newplayer1turrety + 5
            end if
            drawline (p1locationx + 15, p1locationy + 12, player1turretx, player1turrety, black)     %DRAW TURRET WITH NEW INFO
        end if
    end loop
end turretmoveleft

%MOVE TURRET TO THE RIGHT
process turretmoveright
    loop
        getch (p1prepare)
        if ord (p1prepare) = 205 then
            drawline (p1locationx + 15, p1locationy + 12, player1turretx, player1turrety, white)     %ERASE OLD TURRET
            if player1turretx >= p1locationx + 15 then
                player1turretx := player1turretx + 2
                player1turrety := player1turrety - 1
                p1angle := p1angle + 0.0005
                newplayer1turrety := newplayer1turrety + 5
            elsif player1turretx >= p1locationx + 21 then
                player1turretx := player1turretx - 2
                player1turrety := player1turrety + 1
                p1angle := p1angle - 0.0005
                newplayer1turrety := newplayer1turrety - 5
            else
                player1turretx := player1turretx - 2
                player1turrety := player1turrety + 1
                newplayer1turrety := newplayer1turrety - 5
            end if
            drawline (p1locationx + 15, p1locationy + 12, player1turretx, player1turrety, black)     %DRAW TURRET WITH NEW INFO
        end if
    end loop
end turretmoveright
fork turretmoveleft
fork turretmoveright
delay (1000)

%GRAVITY/SHOT

process p1fire
    var p1x, p1y : real
    var p1x1, p1y1 : int
    p1x := player1turretx

    %fire the shot
    loop
        p1x1 := player1turretx + 20
        p1y1 := player1turrety
        p1y := p1angle * p1x * (p1power - p1x) + player1turrety
        p1x := p1x + 1
        p1x1 := floor (p1x)
        p1y1 := floor (p1y)
        drawdot (p1x1, p1y1, blue)
        delay (12)
        exit when whatdotcolor (p1x1 + 1, p1y1) not= white
    end loop

    %explosion
    for a : 1 .. 50
        drawfilloval (p1x1, p1y1, a, a, white)
        delay (10)
    end for
end p1fire
fork p1fire








artillery game.zip
 Description:

Download
 Filename:  artillery game.zip
 Filesize:  22.78 KB
 Downloaded:  82 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Jan 01, 2006 5:27 pm   Post subject: (No subject)

Why "simulate" gravity using parabolas when you can easily apply the force of gravity to your shell. On the surface of Earth, gravity accelerates us down. We'll say, for your game, that it accelerates everything down at one pixel per (loop execution)^2. (Standard units of acceleration are m/s^2.)

code:

View.Set ("offscreenonly")

var shell :
    record
        x, y, vx, vy : real
    end record
    := init (0, 0, 5, 15)

loop

    shell.vy -= 0.3         % Accelerate the shell down by reducing its velocity at a constant rate
    shell.x += shell.vx     % Apply the shell's horiz. velocity to its horiz. position
    shell.y += shell.vy     % Apply the shell's vertical velocity to its vertical position


    cls
    Draw.FillOval (round (shell.x), round (shell.y), 5, 5, black)
    View.Update
    delay (10)

end loop
jeo77




PostPosted: Sun Jan 01, 2006 10:20 pm   Post subject: (No subject)

wow, thanks, thats much easier, and is working perfectly!
2 Bits for you!
Geminias




PostPosted: Sun Jan 01, 2006 11:36 pm   Post subject: (No subject)

what do bits do?
MysticVegeta




PostPosted: Sun Jan 01, 2006 11:54 pm   Post subject: (No subject)

Frankly, I don't see a purpose but here is always a link to tell you what they do
Cervantes




PostPosted: Mon Jan 02, 2006 9:07 am   Post subject: (No subject)

Ah, jeo77 catches on fast! Wink

But there's one thing you didn't realize. Moderator's bits are locked at 1000 (set back to 1000 after each post). I'll give you your 2 bits back. Thanks is all I need. Smile

Also, the wiki is a good source of information.
Geminias




PostPosted: Mon Jan 02, 2006 10:12 am   Post subject: (No subject)

lol @ hacker dan. Well heck, remind me not to get bits in the future. That's kind of cruel, having a "currency" but being unable to do anything with it.

You should have to contribute to get bits awarded to you, and you shouldn't be allowed to post your own topics and ask questions unless you have bits. That would be a way to force people to share their knowledge, else get none in return. But, that's just my crazy-nobodylikes kind of thoughts.
Cervantes




PostPosted: Mon Jan 02, 2006 10:25 am   Post subject: (No subject)

Geminias wrote:

You should have to contribute to get bits awarded to you, and you shouldn't be allowed to post your own topics and ask questions unless you have bits. That would be a way to force people to share their knowledge, else get none in return. But, that's just my crazy-nobodylikes kind of thoughts.

So, you are only allowed to post topics if you have bits. So, you have to reply to topics before you can post your own topics. Think what that would do to the people who come here looking for help: they wouldn't be able to post, and probably never would. CompSci.ca growth plummets.

Now, let's stop spamming, shall we?
Sponsor
Sponsor
Sponsor
sponsor
jeo77




PostPosted: Mon Jan 02, 2006 11:21 pm   Post subject: (No subject)

Thanks again Cervantes, but now I got another question for ya.
So far my whole program involves processes, but my 'partner' for this project made a menu screen, with a GUI, which has the whole game fitting into one process. Now normally I'd rip the menu to shreds and do it different (Very Happy) but it's a 2-person project, and this is about all the guy has done (cause he's not really good at it, I don't blame him). So I need to incorperate it into the overall program... Here's the menu part (took sum stuff out, cause it has nothin to do with the actuall programming it self...

code:

import GUI



%START THE GAME
procedure startgame

end startgame




%HOW TO PLAY

procedure controlls
    colorback (black)
    cls
    color (green)
    put "How To Play"
    delay (5000)
end controlls







%MAIN MENU
View.Set ("graphics:1000;500,nobuttonbar")

var menuscreen : int
menuscreen := Pic.FileNew ("menu_screen.jpg")
Pic.Draw (menuscreen, 0, 0, picCopy)
Pic.Free (menuscreen)


var draw : int := GUI.CreateButtonFull (100, 10, 0, "Go To War",
    startgame, 0, '^D', true)
var draw2 : int := GUI.CreateButtonFull (500, 10, 0, "Controlls",
    controlls, 0, '^D', true)
var quitBtn : int := GUI.CreateButton (900, 10, 0, "Quit", GUI.Quit)
loop
    exit when GUI.ProcessEvent
end loop



The problem is that you can't put a process in a process, so what should I do?
Cervantes




PostPosted: Tue Jan 03, 2006 9:09 am   Post subject: (No subject)

First, you should read about why you should avoid processes.

Second, you should consider the possibility of changing the code a bit so as to avoid processes.

Third, if you must keep processes, you don't need to define a process within the definition of another. You need to call a process from another. Can you not fork the play_game process from the menu process, if the appropriate conditions are met?

I assume the menu contains a "Play Game" type button. Since you're using Turing's GUI, that button requires an action procedure. That procedure should contain the following line (in some manifestation or another):
code:

fork play_game
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  [ 10 Posts ]
Jump to:   


Style:  
Search: