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

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




PostPosted: Tue Jan 09, 2007 7:20 pm   Post subject: Delay help

I made a racing game where if you or the computer goes in a puddle of mud, your car slows down. My problem is that when the computer's car goes in the mud, it makes the other car slow even though it is not on the mud. How do i make only the car that goes in the mud slow down and not the other car that avoided the mud.

This is the part im having problems with:
code:
loop
            exit when GUI.ProcessEvent
            drawfillbox (startpointx + 1, 70, 0, 300, gray)
            drawfillbox (0, startpointy - 1, 760, 300, gray)
            drawfillbox (0, startpointy + 1, 760, 70, gray)
            drawfilloval (390, 190, 100, 50, 114)
            drawfilloval (390, 405, 100, 50, 114)
            Pic.Draw (pictureP1, startpointx + 1, startpointy + 1, 0)

            drawfillbox (startpointx2 + 1, 400 + 1, 0 + 1, 450 + 1, gray)

            Input.KeyDown (key)

            if key ('M') or key ('m') then
                mainMenu
            end if
            if key (KEY_UP_ARROW) and endpointy <= 80 then
                startpointy := startpointy + 10
                endpointy := endpointy + 10
            elsif key (KEY_DOWN_ARROW) and startpointy >= 85 then
                startpointy := startpointy - 10
                endpointy := endpointy - 10

            elsif key (KEY_RIGHT_ARROW) and endpointx <= 630 then
                startpointx := startpointx + 10
                endpointx := endpointx + 10
                if startpointx > 168 and startpointx < 450 and startpointy > 130 and startpointy < 220 then
                    startpointx := startpointx + 10
                    delay (30)
                end if
            else
                if key (KEY_LEFT_ARROW) and startpointx >= 1 then
                    startpointx := startpointx - 10
                    endpointx := endpointx - 10

                end if

            end if

            drawfilloval (390, 405, 100, 50, 114)

            Pic.Draw (pictureComp, startpointx2, startpointy2, 0)

            startpointx2 := startpointx2 + 8
            delay (2)

            if startpointx2 > 168 and startpointx2 < 450 and startpointy2 > 360 and startpointy2 < 450 then
                %or startpointx >168 and startpointx <450 and startpointy >160 and startpointy <250  then
                startpointx2 := startpointx2 + 8
                delay (30)
            else

            end if
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Jan 09, 2007 7:47 pm   Post subject: Re: Delay help

Instead of using a delay() which slows down the entire program, have a velocity variable, and lower the velocity when you go through the puddle
ericfourfour




PostPosted: Tue Jan 09, 2007 7:53 pm   Post subject: Re: Delay help

Instead of delaying the program, give each player a speed, speed effect, and total speed variable. The speed is the amount of pixels the player should move every frame. The speed effect is an effect on the speed that either increases or decreases it. The total speed is the actual amount of pixels the player moves every frame.
Turing:
var speed : real
var speedEffect : real
var totalSpeed : real

loop
    ...
    if speed changed then
        totalSpeed := speed + speedEffect
    end if
    ...
end loop
Ldomi




PostPosted: Thu Jan 11, 2007 9:41 pm   Post subject: Re: Delay help

ericfourfour wrote:


Turing:
var speed : real
var speedEffect : real
var totalSpeed : real

loop
    ...
    if speed changed then
        totalSpeed := speed + speedEffect
    end if
    ...
end loop



What's the "..."?
Ultrahex




PostPosted: Thu Jan 11, 2007 11:10 pm   Post subject: Re: Delay help

Basically what he is saying is you need to have speeds on your vechiles say you are moving at a rate of 2m/s on road, and 1m/s on dirt

then you would set the current velocity to whatever one its on. so you need a set of data for each car saying its speed and you need to move it by that speed.

code:
var speed : int := 5
var chars : array char of boolean

var x : int := 50
View.Set ("offscreenonly")
loop
    cls
    drawfillbox (200, 0, maxx, maxy, brown)
    drawfilloval (x, 200, 5, 5, blue)
    Input.KeyDown (chars)
    if x > 200 then
        speed := 1
    else
        speed := 5
    end if
    x += speed
    if x > 400 then
        x := 50
    end if
    delay (20)
    View.Update
end loop
Clayton




PostPosted: Thu Jan 11, 2007 11:16 pm   Post subject: Re: Delay help

Ldomi @ Thu Jan 11, 2007 9:41 pm wrote:
ericfourfour wrote:


Turing:
var speed : real
var speedEffect : real
var totalSpeed : real

loop
    ...
    if speed changed then
        totalSpeed := speed + speedEffect
    end if
    ...
end loop



What's the "..."?


The ellipses just show you that there is other code in it's place. He just did that to show you the main point instead of hiding it in a mass of variables and statements.
Ldomi




PostPosted: Sat Jan 13, 2007 4:44 pm   Post subject: Re: Delay help

ok, thank you very much =)
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  [ 7 Posts ]
Jump to:   


Style:  
Search: