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

Username:   Password: 
 RegisterRegister   
 Game question
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Morice




PostPosted: Sat Dec 17, 2005 9:48 am   Post subject: Game question

code:

%--------------------------------------------------First Good Game-----------------------------------------------------%
%-----------------------------------------------------By Marius--------------------------------------------------------%


setscreen ("graphics:640;480,nobuttonbar,position:192;100,noecho")
View.Set ("offscreenonly")
var chars : array char of boolean
var x, y : int
var counter : int := 0
var font : int
var this : string
var timeRunning : int
timeRunning := Time.Elapsed

font := Font.New ("Comic Sans MS:10:bold")

x := 285
y := 30
%---------------------------------------------------Background----------------------------------------------------------%
drawfillbox (0, 0, maxx, maxy, 121)
for i : 1 .. 6
    drawbox (0 + i, 0 + i, maxx - i, maxy - i, 69)
end for
drawfillbox (1, 400, maxx - 1, 405, 69)
drawbox (6, 406, maxx - 6, maxy - 6, black)
drawbox (6, 6, maxx - 6, 398, black)
%-------------------------------------------------Background end-------------------------------------------------------%
Font.Draw ("Lap: ", 10, 460, font, 69)
Font.Draw ("Time: ", 10, 440, font, 69)
%-----------------------------------------------------Track------------------------------------------------------------%
proc track
    drawfillbox (300, 7, 304, 40, 0)  %
    drawfillbox (300, 16, 304, 22, 7) %<<<<<Start line
    drawfillbox (300, 28, 304, 34, 7) %

    drawfillbox (7, 7, 633, 11, 21)
    drawfillbox (627, 11, 633, 99, 21)
    drawfillbox (627, 119, 633, 300, 21)
    drawfillbox (627, 321, 633, 397, 21)
    drawfillbox (626, 397, 100, 392, 21)
    drawfillbox (7, 12, 12, 100, 21)

    drawfillbox (60, 40, 580, 60, 21)
    drawfillbox (500, 100, 633, 120, 21)
    drawfillbox (250, 61, 440, 160, 21)
    drawfillbox (100, 160, 580, 180, 21)
    drawfillbox (560, 180, 580, 260, 21)
    drawfillbox (633, 300, 500, 320, 21)
    drawfillbox (500, 220, 520, 300, 21)
    drawfillbox (420, 180, 440, 360, 21)
    drawfillbox (140, 340, 577, 360, 21)
    drawfillbox (7, 280, 100, 397, 21)
    drawfillbox (100, 280, 380, 300, 21)
    drawfillbox (360, 200, 380, 280, 21)
    drawfillbox (150, 200, 360, 220, 21)
    drawfillbox (100, 180, 120, 240, 21)
    drawfillbox (100, 240, 320, 260, 21)
    drawfillbox (7, 100, 53, 279, 21)
    drawfillbox (53, 100, 220, 120, 21)

    %------------------------------Outline of the track------------------------%
    drawline (13, 11, 627, 11, 27)
    drawline (627, 11, 627, 99, 27)
    drawline (627, 121, 627, 299, 27)
    drawline (627, 321, 627, 392, 27)
    drawline (626, 392, 101, 392, 27)
    drawline (12, 11, 12, 99, 27)
    drawline (60, 40, 580, 40, 27)
    drawline (60, 40, 60, 60, 27)
    drawline (60, 60, 250, 60, 27)
    drawline (250, 60, 250, 159, 27)
    drawline (12, 100, 220, 100, 27)
    drawline (220, 100, 220, 120, 27)
    drawline (220, 120, 54, 120, 27)
    drawline (54, 120, 54, 280, 27)
    drawline (54, 280, 360, 280, 27)
    drawline (360, 280, 360, 220, 27)
    drawline (360, 220, 151, 220, 27)
    drawline (151, 220, 151, 200, 27)
    drawline (151, 200, 380, 200, 27)
    drawline (380, 200, 380, 300, 27)
    drawline (380, 300, 101, 300, 27)
    drawline (101, 300, 101, 391, 27)
    drawline (250, 160, 100, 160, 27)
    drawline (100, 160, 100, 260, 27)
    drawline (100, 260, 320, 260, 27)
    drawline (320, 260, 320, 240, 27)
    drawline (320, 240, 120, 240, 27)
    drawline (120, 240, 120, 180, 27)
    drawline (120, 180, 420, 180, 27)
    drawline (420, 180, 420, 340, 27)
    drawline (420, 340, 140, 340, 27)
    drawline (140, 340, 140, 360, 27)
    drawline (140, 360, 577, 360, 27)
    drawline (577, 360, 577, 340, 27)
    drawline (577, 340, 440, 340, 27)
    drawline (440, 340, 440, 180, 27)
    drawline (440, 180, 560, 180, 27)
    drawline (560, 180, 560, 260, 27)
    drawline (560, 260, 580, 260, 27)
    drawline (580, 260, 580, 160, 27)
    drawline (580, 160, 440, 160, 27)
    drawline (440, 160, 440, 60, 27)
    drawline (440, 60, 580, 60, 27)
    drawline (580, 60, 580, 40, 27)
    drawline (500, 100, 627, 100, 27)
    drawline (500, 100, 500, 120, 27)
    drawline (500, 120, 627, 120, 27)
    drawline (520, 300, 627, 300, 27)
    drawline (520, 220, 520, 300, 27)
    drawline (500, 220, 520, 220, 27)
    drawline (500, 220, 500, 320, 27)
    drawline (500, 320, 627, 320, 27)
end track
%---------------------------------------------------Track end----------------------------------------------------------%
track

%------------------------------------------------Speed Boosters--------------------------------------------------------%
proc espeed
    drawfillbox (315, 385, 330, 387, yellow)
    drawfillbox (150, 200, 165, 202, yellow)
end espeed
espeed
%----------------------------------------------Speed Boosters end------------------------------------------------------%
%----------------------------------------------------Player------------------------------------------------------------%
drawfillbox (x, y, x + 10, y + 5, 113)
drawbox (x, y, x + 10, y + 5, 41)
loop
    %------------------------------------------------Player control--------------------------------------------------------%
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
        drawfillbox (x, y, x + 10, y + 5, 113)
        drawbox (x, y, x + 10, y + 5, 41)
        View.Update
        delay (2)
        drawfillbox (x - 1, y - 1, x + 10, y + 5, 121)
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 1
        drawfillbox (x, y, x + 10, y + 5, 113)
        drawbox (x, y, x + 10, y + 5, 41)
        View.Update
        delay (2)
        drawfillbox (x - 1, y - 1, x + 11, y + 5, 121)
    end if
    if chars (KEY_UP_ARROW) then
        y := y + 1
        drawfillbox (x, y, x + 10, y + 5, 113)
        drawbox (x, y, x + 10, y + 5, 41)
        View.Update
        delay (2)
        drawfillbox (x - 1, y - 1, x + 10, y + 5, 121)
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 1
        drawfillbox (x, y, x + 10, y + 5, 113)
        drawbox (x, y, x + 10, y + 5, 41)
        View.Update
        delay (2)
        drawfillbox (x - 1, y - 1, x + 10, y + 6, 121)
    end if
    %------------------------------------------Player control end---------------------------------------------------%
    %------------------------------------------Track Restrictions---------------------------------------------------%
    if x >= 49 and x <= 580 and y = 34 then
        y := y - 1
    end if
    if x = 582 and y + 6 >= 40 and y + 6 <= 67 then
        x := x + 1
    end if
    if x >= 60 and x <= 580 and y = 62 then
        y := y + 1
    end if
    if x = 442 and y >= 61 and y <= 160 then
        x := x + 1
    end if
    if x >= 489 and x <= 633 and y = 94 then
        y := y - 1
    end if
    if x = 489 and y >= 94 and y <= 120 then
        x := x - 1
    end if
    if x >= 489 and x <= 633 and y = 122 then
        y := y + 1
    end if
    if x >= 442 and x <= 580 and y = 153 then
        y := y - 1
    end if
    if x = 582 and y >= 153 and y <= 260 then
        x := x + 1
    end if
    if x >= 550 and x <= 582 and y = 260 then
        y := y + 1
    end if
    if x = 550 and y <= 260 and y >= 180 then
        x := x - 1
    end if
    if x <= 555 and x >= 442 and y = 182 then
        y := y + 1
    end if
    if x = 442 and y >= 182 and y <= 335 then
        x := x + 1
    end if
    if x >= 442 and x <= 576 and y = 333 then
        y := y - 1
    end if
    if x = 579 and y >= 333 and y <= 360 then
        x := x + 1
    end if
    if x <= 579 and x >= 130 and y = 361 then
        y := y + 1
    end if
    if x = 128 and y <= 362 and y >= 337 then
        x := x - 1
    end if
    if x >= 128 and x <= 420 and y = 333 then
        y := y - 1
    end if
    if x = 408 and y <= 333 and y >= 181 then
        x := x - 1
    end if
    if x <= 408 and x >= 122 and y = 181 then
        y := y + 1
    end if
    if x = 122 and y >= 181 and y <= 240 then
        x := x + 1
    end if
    if x >= 122 and x <= 320 and y = 233 then
        y := y - 1
    end if
    if x = 322 and y >= 233 and y <= 261 then
        x := x + 1
    end if
    if x <= 322 and x >= 90 and y = 261 then
        y := y + 1
    end if
    if x = 90 and y <= 261 and y >= 155 then
        x := x - 1
    end if
    if x >= 90 and x <= 238 and y = 153 then
        y := y - 1
    end if
    if x = 238 and y <= 153 and y >= 62 then
        x := x - 1
    end if
    if x <= 238 and x >= 50 and y = 62 then
        y := y + 1
    end if
    if x = 48 and y <= 62 and y >= 38 then
        x := x - 1
    end if
    if x >= 14 and x <= 222 and y = 93 then
        y := y - 1
    end if
    if x = 222 and y >= 93 and y <= 120 then
        x := x + 1
    end if
    if x <= 222 and x >= 52 and y = 122 then
        y := y + 1
    end if
    if x = 56 and y >= 122 and y <= 280 then
        x := x + 1
    end if
    if x >= 56 and x <= 347 and y = 273 then
        y := y - 1
    end if
    if x = 347 and y <= 273 and y >= 222 then
        x := x - 1
    end if
    if x <= 347 and x >= 140 and y = 222 then
        y := y + 1
    end if
    if x = 139 and y >= 196 and y <= 222 then
        x := x - 1
    end if
    if x >= 139 and x <= 380 and y = 193 then
        y := y - 1
    end if
    if x = 382 and y >= 193 and y <= 300 then
        x := x + 1
    end if
    if x <= 382 and x >= 100 and y = 302 then
        y := y + 1
    end if
    if x = 103 and y >= 302 and y <= 387 then
        x := x + 1
    end if
    if x <= 627 and x >= 520 and y = 293 then
        y := y - 1
    end if
    if x = 522 and y <= 293 and y >= 217 then
        x := x + 1
    end if
    if x >= 489 and x <= 522 and y = 214 then
        y := y - 1
    end if
    if x = 489 and y >= 214 and y <= 322 then
        x := x - 1
    end if
    if x >= 489 and x <= 627 and y = 322 then
        y := y + 1
    end if
    if x = 305 and y >= 7 and y <= 40 then
        x := x + 1
    end if
    %----------------------------------------Track Restrictions end--------------------------------------------------%
    %---------------------------------------------Speed Boosters-----------------------------------------------------%
    if x >= 315 and x <= 330 and y >= 385 and y <= 387 then
        x := x - 50
    end if
    %------------------------------------------Border Restrictions---------------------------------------------------%
    if x >= 13 and x <= 615 and y = 13 then
        y := y + 1
    end if
    if x = 14 and y >= 8 and y <= 393 then
        x := x + 1
    end if
    if x >= 8 and x <= 621 and y = 386 then
        y := y - 1
    end if
    if x = 615 and y >= 8 and y <= 393 then
        x := x - 1
    end if
    espeed
    track
    View.Update
    drawfillbox (x, y, x + 10, y + 5, 113)
    drawbox (x, y, x + 10, y + 5, 41)

    %---------------------------------------Border Restrictions end--------------------------------------------------%
    %------------------------------------------------Winning---------------------------------------------------------%
    if x = 300 and y >= 7 and y <= 40 and chars (KEY_RIGHT_ARROW) then
        drawfillbox (40, 460, 50, 469, 122)
        drawfillbox (50, 440, 60, 450, 122)
        counter := counter + 1
        Font.Draw ("Lap:", 10, 460, font, 69)
        this := intstr (counter)
        Font.Draw (this, 40, 460, font, 69)
        this := intstr (timeRunning)
        Font.Draw (this, 50, 440, font, 69)


    end if
    %----------------------------------------------Winning end-------------------------------------------------------%

end loop


This is what i have so far
Im trying to make this racing, however i dont know how to do the time count.
Later after i finish with all of this i will make it a 2 player game and add some more levels, but for now im trying to get time, so can anybody teach me?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Dec 17, 2005 9:57 am   Post subject: (No subject)

Wow, that's a lot of hardcoding.

I'm not really sure what you're asking, but I'm going to point you to Time.Elapsed. Check the Turing Help Manual, it should be pretty self explanitory.
Morice




PostPosted: Sat Dec 17, 2005 10:01 am   Post subject: (No subject)

I tried using the Time.Elapsed command as u can see almost at the end however it doesnt really work cause it gives me milliseconds instead of seconds and i can convert, i tried but couldnt, isnt there a much easier way. Oh ya also with restrictions u know so that my "car" wont touch the walls is ther an easier way....
Morice




PostPosted: Sat Dec 17, 2005 10:08 am   Post subject: (No subject)

Ok nevermind with the time i serchead and figured it out, however i would still want to learn how to use restrictions an easier way, is it with whatdotcolor???/
Morice




PostPosted: Sat Dec 17, 2005 10:19 am   Post subject: (No subject)

And one more thing... how to use acceleration to make my program a little bit more realistic.... thanks
Cervantes




PostPosted: Sat Dec 17, 2005 10:23 am   Post subject: (No subject)

Morice wrote:
Ok nevermind with the time i serchead and figured it out, however i would still want to learn how to use restrictions an easier way, is it with whatdotcolor???/


whatdotcolour is one way. It'd probably be the easiest, but it's definately not the best. A better way might be to read your "map" in from a text file into a 2D array. Although I haven't actually run your program. Sad
Cervantes




PostPosted: Sat Dec 17, 2005 10:34 am   Post subject: (No subject)

Morice wrote:
And one more thing... how to use acceleration to make my program a little bit more realistic.... thanks


Acceleration is to velocity as velocity is to displacement.
In scalar form:
Acceleration is to speed as speed is to distance.

Let's set up a record for our car. Note that you don't actually have to use a record, but it keeps things nice and tidy.
code:

var car :
   record
      x, y : real  %position
      vx, vy : real %velocity
      ax, ay : real %acceleration
   end record


Now, let's give that some values.
code:

car.x := maxx div 2
car.y := maxy div 2
car.vx := 0
car.vy := 0.5
car.ax := 0.1
car.ay := 0

So, what should this car be doing? It should start in the middle and move up by 0.5 pixels each time through the loop (since we aren't going to bother with fps restrictions). It should accelerate by 0.1 pixels per frame^2 in the positive x direction. Now, let's apply this
code:

View.Set ("offscreenonly")
loop

    % Update the motion of the car
    car.vx += car.ax   %same as 'car.vx := car.vx + car.ax'
    cay.vy += car.ay
    car.x += car.vx
    car.y += car.vy

    % Draw
    cls
    Draw.FillOval (round (car.x), round (car.y), 5, 5, green)
    View.Update
    delay (10)
end loop


So, what does this all mean to you? When you press the up arrow, you want to accelerate your car up:
code:

if keys (KEY_UP_ARROW) then
     car.ay := 0.5
end if

Alternatively, you could make yourself accerlerate forwards, and have the left and right arrow keys turn you, while the down arrow accelerates you backwards. For this, you'll need to know some trig, but it's not hard. zylum wrote a good tutorial on this topic: http://www.compsci.ca/v2/viewtopic.php?t=3714.
Morice




PostPosted: Sat Dec 17, 2005 10:49 am   Post subject: (No subject)

Thanks, Cervants, i think i get it now, however i havent learned about record yet. But i get wat u did with the other stuff.
Sponsor
Sponsor
Sponsor
sponsor
Morice




PostPosted: Sat Dec 17, 2005 11:24 am   Post subject: (No subject)

ok now my restrictions wont work and i cant get it to stop, can somebody teach me how to use whatdotcolor...cause i hear that its much easier than my restrictions heres the new code
code:

%--------------------------------------------------First Good Game-----------------------------------------------------%
%-----------------------------------------------------By Marius--------------------------------------------------------%


setscreen ("graphics:640;480,nobuttonbar,position:192;100,noecho")
View.Set ("offscreenonly")
const decay := .985
var chars : array char of boolean
var counter : int := 0
var font : int
var this : string
var timeRunning : int
timeRunning := Time.Elapsed
var x := 285.0
var vx := 0.0
var y := 30.0
var vy := 0.0
var counter2 : int := 0
var endStatement : int

font := Font.New ("Comic Sans MS:10:bold")

%---------------------------------------------------Background----------------------------------------------------------%
drawfillbox (0, 0, maxx, maxy, 121)
for i : 1 .. 6
    drawbox (0 + i, 0 + i, maxx - i, maxy - i, 69)
end for
drawfillbox (1, 400, maxx - 1, 405, 69)
drawbox (6, 406, maxx - 6, maxy - 6, black)
drawbox (6, 6, maxx - 6, 398, black)
%-------------------------------------------------Background end-------------------------------------------------------%
Font.Draw ("Lap: ", 10, 460, font, 69)
Font.Draw ("Time: ", 10, 440, font, 69)
%-----------------------------------------------------Track------------------------------------------------------------%
proc track
    drawfillbox (300, 7, 304, 40, 0)  %
    drawfillbox (300, 16, 304, 22, 7) %<<<<<Start line
    drawfillbox (300, 28, 304, 34, 7) %

    drawfillbox (7, 7, 633, 11, 21)
    drawfillbox (627, 11, 633, 99, 21)
    drawfillbox (627, 119, 633, 300, 21)
    drawfillbox (627, 321, 633, 397, 21)
    drawfillbox (626, 397, 100, 392, 21)
    drawfillbox (7, 12, 12, 100, 21)

    drawfillbox (60, 40, 580, 60, 21)
    drawfillbox (500, 100, 633, 120, 21)
    drawfillbox (250, 61, 440, 160, 21)
    drawfillbox (100, 160, 580, 180, 21)
    drawfillbox (560, 180, 580, 260, 21)
    drawfillbox (633, 300, 500, 320, 21)
    drawfillbox (500, 220, 520, 300, 21)
    drawfillbox (420, 180, 440, 360, 21)
    drawfillbox (140, 340, 577, 360, 21)
    drawfillbox (7, 280, 100, 397, 21)
    drawfillbox (100, 280, 380, 300, 21)
    drawfillbox (360, 200, 380, 280, 21)
    drawfillbox (150, 200, 360, 220, 21)
    drawfillbox (100, 180, 120, 240, 21)
    drawfillbox (100, 240, 320, 260, 21)
    drawfillbox (7, 100, 53, 279, 21)
    drawfillbox (53, 100, 220, 120, 21)

    %------------------------------Outline of the track------------------------%
    drawline (13, 11, 627, 11, 27)
    drawline (627, 11, 627, 99, 27)
    drawline (627, 121, 627, 299, 27)
    drawline (627, 321, 627, 392, 27)
    drawline (626, 392, 101, 392, 27)
    drawline (12, 11, 12, 99, 27)
    drawline (60, 40, 580, 40, 27)
    drawline (60, 40, 60, 60, 27)
    drawline (60, 60, 250, 60, 27)
    drawline (250, 60, 250, 159, 27)
    drawline (12, 100, 220, 100, 27)
    drawline (220, 100, 220, 120, 27)
    drawline (220, 120, 54, 120, 27)
    drawline (54, 120, 54, 280, 27)
    drawline (54, 280, 360, 280, 27)
    drawline (360, 280, 360, 220, 27)
    drawline (360, 220, 151, 220, 27)
    drawline (151, 220, 151, 200, 27)
    drawline (151, 200, 380, 200, 27)
    drawline (380, 200, 380, 300, 27)
    drawline (380, 300, 101, 300, 27)
    drawline (101, 300, 101, 391, 27)
    drawline (250, 160, 100, 160, 27)
    drawline (100, 160, 100, 260, 27)
    drawline (100, 260, 320, 260, 27)
    drawline (320, 260, 320, 240, 27)
    drawline (320, 240, 120, 240, 27)
    drawline (120, 240, 120, 180, 27)
    drawline (120, 180, 420, 180, 27)
    drawline (420, 180, 420, 340, 27)
    drawline (420, 340, 140, 340, 27)
    drawline (140, 340, 140, 360, 27)
    drawline (140, 360, 577, 360, 27)
    drawline (577, 360, 577, 340, 27)
    drawline (577, 340, 440, 340, 27)
    drawline (440, 340, 440, 180, 27)
    drawline (440, 180, 560, 180, 27)
    drawline (560, 180, 560, 260, 27)
    drawline (560, 260, 580, 260, 27)
    drawline (580, 260, 580, 160, 27)
    drawline (580, 160, 440, 160, 27)
    drawline (440, 160, 440, 60, 27)
    drawline (440, 60, 580, 60, 27)
    drawline (580, 60, 580, 40, 27)
    drawline (500, 100, 627, 100, 27)
    drawline (500, 100, 500, 120, 27)
    drawline (500, 120, 627, 120, 27)
    drawline (520, 300, 627, 300, 27)
    drawline (520, 220, 520, 300, 27)
    drawline (500, 220, 520, 220, 27)
    drawline (500, 220, 500, 320, 27)
    drawline (500, 320, 627, 320, 27)
end track
%---------------------------------------------------Track end----------------------------------------------------------%
track

%------------------------------------------------Speed Boosters--------------------------------------------------------%
proc espeed
    drawfillbox (315, 385, 330, 387, yellow)
    drawfillbox (150, 200, 165, 202, yellow)
end espeed
espeed
%----------------------------------------------Speed Boosters end------------------------------------------------------%
%----------------------------------------------------Player------------------------------------------------------------%
loop
    %------------------------------------------------Player control--------------------------------------------------------%
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        vx += 0.04
    end if
    if chars (KEY_LEFT_ARROW) then
        vx -= 0.04
    end if
    if chars (KEY_UP_ARROW) then
        vy += 0.04
    end if
    if chars (KEY_DOWN_ARROW) then
        vy -= 0.04
    end if
    vx *= decay
    vy *= decay
    x += vx
    y += vy
    drawfillbox (round (x), round (y), round (x) + 10, round (y) + 5, 113)
    View.Update
    delay (10)
    drawfillbox (round (x), round (y), round (x) + 10, round (y) + 5, 0)
    %------------------------------------------Player control end---------------------------------------------------%
    %---------------------------------------------Speed Boosters-----------------------------------------------------%
    if x >= 315 and x <= 330 and y >= 385 and y <= 387 then
        x := x - 50
    end if
    espeed
    track
    %------------------------------------------------Winning---------------------------------------------------------%
    if x = 300 and y >= 7 and y <= 40 and chars (KEY_RIGHT_ARROW) then
        drawfillbox (40, 460, 50, 469, 122)
        counter := counter - 1
        Font.Draw ("Lap:", 10, 460, font, 69)
        this := intstr (counter)
        Font.Draw (this, 40, 460, font, 69)
    end if
    %----------------------------------------------Winning end-------------------------------------------------------%
    drawfillbox (50, 440, 65, 450, 122)
    endStatement := counter2 + round (Time.Elapsed / 1000)
    this := intstr (endStatement)
    Font.Draw (this, 50, 440, font, 69)
    View.Update
end loop


thanks....
Cervantes




PostPosted: Sat Dec 17, 2005 11:45 am   Post subject: (No subject)

If the dot colour just ahead of the car is the colour of the edge of the track or the grass beyond it, stop the car. This would be easier if you were using rotation and forwards/backwards.
code:

if whatdotcolour (x + cos (arctan (vy / vx)) * car.radius, y + sin (arctan (vy / vx)) * car.radius then
    % All stop! 
    % Really, you would just stop the velocity of the car that is perpendicular
    % to the surface you just smacked in to, but that's still more difficult. 
    % Let's do an all stop for now.
    car.vx := 0
    car.vy := 0

You would also need to reverse the car a little bit, so that the car is free to move again. Again, this would be much easier with the rotation-backward/forward approach, and that approach suites a racing game better, IMO.
Morice




PostPosted: Sat Dec 17, 2005 11:50 am   Post subject: (No subject)

Cervantes wrote:
If the dot colour just ahead of the car is the colour of the edge of the track or the grass beyond it, stop the car. This would be easier if you were using rotation and forwards/backwards.
code:

if whatdotcolour (x + cos (arctan (vy / vx)) * car.radius, y + sin (arctan (vy / vx)) * car.radius then
    % All stop! 
    % Really, you would just stop the velocity of the car that is perpendicular
    % to the surface you just smacked in to, but that's still more difficult. 
    % Let's do an all stop for now.
    car.vx := 0
    car.vy := 0

You would also need to reverse the car a little bit, so that the car is free to move again. Again, this would be much easier with the rotation-backward/forward approach, and that approach suites a racing game better, IMO.



lol all i understood from ther was if whatdotcolor,btw i have turing 4.0.5 and some stuff dont work....
Morice




PostPosted: Sat Dec 17, 2005 11:53 am   Post subject: (No subject)

i meant 4.0.3 dont know y i type 4.0.5
Cervantes




PostPosted: Sat Dec 17, 2005 11:55 am   Post subject: (No subject)

You mean, you didn't understand the trig? No problem.

I used arctan (which is the inverse tan function. Normall written on calculators as tan^-1) to find the angle that the player is moving. I then took the cos of that to get the component of that angle for a unit circle. I then multiplied it by car.radius so that we're checking out from a bit. This is assuming that the car is a circle. Further, it should have been multiplied by (car.radius + 1), because we want to check just beyond the edge of the car. I did similarly for the y plane, except I used sine.
Morice




PostPosted: Sat Dec 17, 2005 11:57 am   Post subject: (No subject)

ohhh ok....
so if its a box then i shoud do this

code:

 if whatdotcolor (x, y+5) = 27 then      %since the box is 5 pixels high
        vx := 0
        vy := 0
    end if
Cervantes




PostPosted: Sat Dec 17, 2005 12:10 pm   Post subject: (No subject)

Right, assuming the car is moving up. You could probably just check all around the car, and answer an all stop if the track colour is found. To allow for the car to be released from the track's edge, you might want to create a boolean flag that will say whether the car to check for a collision with the edge of the track or not. If you crash, set that flag to false, and by the time you're released again, set it back to true.
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: