Computer Science Canada

Help with Tony's Oval Collision.

Author:  recneps [ Wed Jan 28, 2004 6:46 pm ]
Post subject:  Help with Tony's Oval Collision.

Help with Tony's Oval Collision please! I'm going to include a racing game in my FP (a real crappy one, but its better than my High/Low game ;p)
Anyways, i got the car movement down, and i tried tony's oval collison so that it would stop at the oval (well move back 10 spots) but its not working... anyone help me? Very Happy (Credit will be shown on the FP submission Smile)

Author:  poly [ Wed Jan 28, 2004 6:49 pm ]
Post subject: 

so when the car hits the oval, it gets sent flying back 10 spots?
- try using View.Update so there is no blinking

Author:  recneps [ Wed Jan 28, 2004 6:52 pm ]
Post subject: 

I have view.update in there... im thinking i put one in the procedure, but not the loop Smile (too lazy to check right now) and yeah, i have it move back 10 pixels, just cause i dont know how far forward its going Very Happy (because of the two lines i borrowed, because i dont know sine and cosine yet)

Author:  santabruzer [ Wed Jan 28, 2004 6:57 pm ]
Post subject: 

dont' forgot to put the screen mode before the procedure, or the other way around example :

code:
setscreen ("graphics,offscreenonly")


instead of
code:
setscreen ("graphics:offscreenonly")


Reduces Flicker

Author:  McKenzie [ Wed Jan 28, 2004 7:04 pm ]
Post subject: 

Distance formula is wrong. (no need for credit)

Author:  Cervantes [ Thu Jan 29, 2004 8:30 am ]
Post subject: 

If you're using turing 4.0.5 you can just use Math.Distance (x1, y1, x2, y2)

cheers

Author:  shorthair [ Thu Jan 29, 2004 8:55 am ]
Post subject: 

im not to sure how exactly t ochange this , but i am aware that you can have a much better turning and drving game , so that you can drive while your turning , that would be really cool

Author:  Delta [ Thu Jan 29, 2004 9:11 am ]
Post subject: 

you should have the turning do like a little arc (sin or cos type deal) so the car doesn't just go up,down,left,right... as for the turning a moving at the same time use Key.Down ... ummm ya... have fuN!

Author:  McKenzie [ Thu Jan 29, 2004 9:57 am ]
Post subject: 

basically you want to see the velocity of the car as a vector (magnitude (speed) and direction (angle that you already have)). Just break this vector into it's x any components and that is how much to add on when it moves. Here is a simple vector example to get you on your way.

Author:  Delta [ Thu Jan 29, 2004 11:45 am ]
Post subject: 

wow... mckenzie you should make a yo yo game with that code... it'd be super kewl.. like wow... now if you don't (i think you should Smile ) then I'm going to later on ... after the pic2code program Smile

Author:  Cervantes [ Fri Jan 30, 2004 9:30 am ]
Post subject: 

wow I like that program McKenzie.... yeeees.. like it I do...

a yoyo program, that is original!! but it would only be cool if you could do all sorts of cool tricks... but the tricks would have to actually be done, not by hitting a certain button comination and then it does the trick (like what you have in mortal combat or games like those)

Cheers

Author:  recneps [ Fri Jan 30, 2004 6:44 pm ]
Post subject: 

ok, i got it to stop at the edge of the circle, but how can i get it to move out of it?


code:
const maxframerate : int := 30
const numframes : int := 18
var keys : array char of boolean
const up : char := chr (200)
const left : char := chr (203)
const right : char := chr (205)
const esc : char := chr (27)
const carrad : int := 19
var car : array 0 .. (numframes - 1) of int
var angle : int
var x, y, dx, dy : real

var midx : int := maxx div 2
var midy : int := maxy div 2
var radius : int := maxx div 5
procedure drawscreen

    delay (10)
    cls
    %draw the center Ring
    drawoval (midx, midy, radius, radius, 0)
    %draw the car with the appropriate angle.
    Pic.Draw (car (angle),
        round (x) - carrad,
        round (y) - carrad, picMerge)

    View.Update
end drawscreen

setscreen ("graphics:nooffscreenonly")
car (0) := Pic.FileNew ("crappycar.bmp")
Pic.SetTransparentColour (car (0), black)
for i : 1 .. (numframes - 1) %make all frames of the ship.(-1 because the 0 is already set.)
    car (i) := Pic.Rotate (car (0), i * (360 div numframes), carrad, carrad)
end for
angle := 0
x := midx - radius - 10
y := midy
dx := 0
dy := 0

colourback (black)
loop %get key info
   
    Input.KeyDown (keys)
    if keys (up) then
        dx -= sind (angle * 20) %This and next line only two lines that arent mine :(
        dy += cosd (angle * 20) %^^^^^^^^
    end if
    if keys (right) then %rotate if right
        angle := (angle - 1) mod numframes
        delay (50)
    end if
    if keys (left) then %rotate if left
        angle := (angle + 1) mod numframes
        delay (50)
    end if
    if keys (esc) then %exit when hit esc
        exit
    end if
    dx := min (max (dx, -20), 20) %Set "speed limit"
    dy := min (max (dy, -20), 20)
   
    if x > maxx then
        x := maxx %keep car in bounds for x
    end if
    if x < 0 then
        x := 0
    end if
    if y > maxy then
        y := maxy %keep car in bounds for y
    end if
    if y < 0 then
        y := 0
    end if
 if Math.Distance (x, y, midx, midy) < radius then
        dx:=0
        dy:=0
    end if
    x += dx
    y += dy
    drawscreen
    dx := 0
    dy := 0
end loop

Author:  McKenzie [ Sat Jan 31, 2004 12:50 am ]
Post subject: 

Prevention is the key (see code)

Author:  Andy [ Sat Jan 31, 2004 3:35 pm ]
Post subject: 

turing now has a built in function to check the distance between two points

Author:  Cervantes [ Sat Jan 31, 2004 3:43 pm ]
Post subject: 

called Math.Distance
*points to 6th post from top*

Author:  recneps [ Sat Jan 31, 2004 5:45 pm ]
Post subject: 

I also used that Math Distance thing in my "updated code"


: