Computer Science Canada

Basic car movement game thing.

Author:  recneps [ Sat Jan 17, 2004 9:40 pm ]
Post subject:  Basic car movement game thing.

This shows how to make a car move around using angles and stuff. more explained in code Smile (well, 2 lines of text explains it.)
bits are nice if you use this (i know SOMEONE will try to use this as their own for final prog Smile )

Author:  sport [ Sat Jan 17, 2004 10:04 pm ]
Post subject:  Useful Code

Excellent Program. It will be put to good use.

Author:  DanShadow [ Sat Jan 17, 2004 10:10 pm ]
Post subject: 

hm...pretty nice, I remember doing a program similar to this before. Although, I wish you would have developed your own code without taking some from another program, but have some bits anyway. Smile
+5 Bits

Author:  Leiak [ Sat Jan 17, 2004 11:22 pm ]
Post subject: 

i cant get it to work on my program can someone direct me towards a url that i can download a better turing program plz and thankie

Author:  recneps [ Sun Jan 18, 2004 4:26 pm ]
Post subject: 

i would, but i have gr 10 math next sem, and i dunno how i would make it move forward at that angle:) (i only borrowed 2 lines Very Happy)

Author:  recneps [ Sun Jan 18, 2004 4:27 pm ]
Post subject: 

and about the turing download, go to compsci main page, theres a linkto turing 4.0.5 update

Author:  shorthair [ Sun Jan 18, 2004 4:45 pm ]
Post subject: 

Rolling Eyes do you mind if i steal like 20 lines of that code for a game of mine , Rolling Eyes il give you a bit

Author:  recneps [ Wed Jan 21, 2004 4:02 pm ]
Post subject: 

doesnt matter Very Happy (i borrowed 2 lines anyway Very Happy)

Author:  netninja [ Wed Feb 11, 2004 10:35 pm ]
Post subject: 

The car was really screwed up so i looked over the code, and i found that you put setscreen ("graphics:nooffscreenonly") instead of setscreen ("offscreenonly").

Once i fixed that, the choppy graphics dissappeared Very Happy Did anyone else get that flashing car instead of a nice solid car?

Author:  Maverick [ Wed Feb 11, 2004 10:42 pm ]
Post subject: 

hey really sweet prog man

Author:  GUI.GetScrollBarWidth : i [ Fri Feb 13, 2004 5:56 pm ]
Post subject: 

super cool. cars r fun. but the graphics r choppy

Author:  rizzix [ Sun Feb 15, 2004 9:59 pm ]
Post subject: 

hehe wanna fix the graphics?

here's the modified code using my library..
code:

include "stdlib.t"

%Made by receneps. Yay.
%Some code taken from spacegame example (but i made it easier to understand :D)
%Use up, left and right to move. Esc to quit.

%All variable names are self explanatory :)
const maxframerate : int := 30
const numships : int := 36
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 shiprad : int := 19
const shipfrad : int := 23
var ship : array 0 .. 35 of int
var shipf : array 0 .. 35 of int
var angle : int
var x, y, dx, dy : real


procedure drawscreen
    %draw the ship with the appropriate angle.

    GFXDrawRefreshPic (ship (angle), round (x) - shiprad, round (y) - shiprad)

    %Pic.Draw (ship (angle), round (x) - shiprad, round (y) - shiprad, picMerge)
    %View.Update
end drawscreen

drawfillbox (0, 0, maxx, maxy, black)
setscreen ("offscreenonly")
ship (0) := Pic.FileNew ("crappycar.bmp")
Pic.SetTransparentColour (ship (0), black)

for i : 1 .. numships - 1 %make all frames of the ship.(-1 because the 0 is already set.)
    ship (i) := Pic.Rotate (ship (0), i * (360 div numships), shiprad, shiprad)
end for
angle := 0
x := maxx div 2
y := maxy div 2
dx := 0
dy := 0
colourback (black)
loop %get key info
    Input.KeyDown (keys)
    if keys (up) then
        dx -= sind (angle * 10) %dont ask me, only gr 9 math (gr 10 next sem!)
        dy += cosd (angle * 10) %got from spacegame exmaple :D lol
    end if
    if keys (right) then %rotate if right
        angle := (angle - 1) mod numships
        delay (25)
    end if
    if keys (left) then %rotate if left
        angle := (angle + 1) mod numships
        delay (25)
    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)
    x += dx
    y += dy
    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
    drawscreen
    dx := 0
    dy := 0
end loop



and attached is the library...


: