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

Username:   Password: 
 RegisterRegister   
 small car tips
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dying to live




PostPosted: Mon Oct 25, 2004 7:38 am   Post subject: small car tips

can anyone help me change my ball to a small car? heres is what i have so far....i just want to get the hang o fthis so i can make a game but everytime i make my car, i start with drawbox then when i run it the bottom left corner of the box stays were it is and the box just gets bigger with the input:( can anyone help Rolling Eyes

code:

var x,y : int
x:=100
y:=100
var chars : array char of boolean

loop
Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
    y:=y+5
    end if
   
    if chars (KEY_RIGHT_ARROW) then
    x:=x+5
    end if
   
    if chars (KEY_LEFT_ARROW) then
    x:=x-5
    end if
   
    if chars (KEY_DOWN_ARROW) then
    y:=y-5
    end if
           
            drawoval(x,y,4,4,red)
            delay(10)
cls
end loop
Sponsor
Sponsor
Sponsor
sponsor
josh




PostPosted: Mon Oct 25, 2004 7:45 am   Post subject: (No subject)

what u need to do is draw the car at the begining of the program. Then u need to look up Pic.New and Pic.Draw in the turing help file Very Happy
dying to live




PostPosted: Mon Oct 25, 2004 7:49 am   Post subject: (No subject)

im not sure i understand that but ok Laughing
josh




PostPosted: Mon Oct 25, 2004 8:29 am   Post subject: (No subject)

srry, basically what the Pic.New command does is it takes all the shapes that u have drawn in a specified area, or box defined in the Pic.New command, (see the syntax in the code below), that make up the car, e.g. a rectangle, wheels... and "takes a picture of them" and stores that picture in a variable. You can then change the x and y coordinates of jus that picture to move it instead of moving each shape individually.

To display the picture that u took u use the Pic.Draw command.

for ecample, this program draws a stickman and makes him bounce around the screen:

code:

setscreen ("graphics:640;480")

%Declare Variables Here
var stickman : int
var x, y, col : int
var dx,dy : int


x := 0
y := 0
dx := 10
dy := 10

%draw the shapes that make up the stickman
drawoval (100,175,20,20,7)
drawline (100,155,100,50,7)
drawline (100,130,50,175,7)
drawline (100,130,150,175,7)
drawline (100,50,50,5,7)
drawline (100,50,150,5,7)
Draw.Arc (100,165,5,5,180,360,7)
Draw.FillOval(95,185,3,3,7)
Draw.FillOval(105,185,3,3,7)

%take the picture of the stickman
stickman := Pic.New (0, 0, 200, 200)
loop
    cls
    x += dx
    y += dy
    %draws the pic of the stickman
    Pic.Draw (stickman, x, y, picCopy)
        if x > maxx-200 then
       dx := -10
    elsif x < 0 then
        dx := 10
    end if
    if y > maxy - 200 then
        dy := -10
    elsif y < 0 then
        dy := 10
    end if
    delay (10)
end loop


so in your code, u would draw the individual shapes before the loop and take the pic after the shapes are drawn and before the loop

u then replace the line where u draw the oval witht he Pic.Draw line
dying to live




PostPosted: Mon Oct 25, 2004 8:58 am   Post subject: (No subject)

haha thats awosme, but yeah i still cant quite figure out how to apply this to my program cuz im not sure i understand the elsif, and if commands yet, im new at this. but thanks.
josh




PostPosted: Mon Oct 25, 2004 9:01 am   Post subject: (No subject)

np, U can keep the if's and else ifs and just do like I said, and use the same x and y variables to move the picture u took
dying to live




PostPosted: Mon Oct 25, 2004 6:51 pm   Post subject: (No subject)

your explaining it god i just dont get it sorry
Cervantes




PostPosted: Mon Oct 25, 2004 6:59 pm   Post subject: (No subject)

if you are confused about the ifs and elsifs:

code:

    if x > maxx - 200 then
        dx := -10
    elsif x < 0 then
        dx := 10
    end if
    if y > maxy - 200 then
        dy := -10
    elsif y < 0 then
        dy := 10
    end if

is the same as
code:

if x > maxx - 200 then
    dx := -10
else
    if x < 0 then
        dx := 10
    end if
end if
if y > maxy - 200 then
    dy := -10
else
    if y < 0 then
        dy := 10
    end if
end if
Sponsor
Sponsor
Sponsor
sponsor
josh




PostPosted: Mon Oct 25, 2004 9:15 pm   Post subject: (No subject)

kk, that program is definantly good for a n00b though. I keep up the good work Very Happy
dying to live




PostPosted: Thu Oct 28, 2004 9:39 am   Post subject: (No subject)

hah thanks man ive changes it a bit so now its a ufo not a car lol...heres what i got.

code:
var x,y : int
x:=100
y:=100
var chars : array char of boolean
var ufo :int

%draws the ufo
drawfillbox(15,15,50,20,red)
drawfillbox(20,20,45,15,9)
drawfillbox(20,20,45,25,8)
drawline(15,5,23,15,7)
drawline(23,15,43,15,7)
drawline(43,15,50,5,7)
drawline(50,5,15,5,7)
drawfill(35,10,yellow,7)
drawbox(15,15,50,20,7)
drawbox(20,15,45,20,7)
drawbox(20,20,45,25,7)

%takes the picture of the ufo
ufo := Pic.New (15,5,50,25)


loop
Input.KeyDown (chars)

Pic.Draw (ufo, x, y, picCopy)
    if chars (KEY_UP_ARROW) then
    y:=y+5
    end if
   
    if chars (KEY_RIGHT_ARROW) then
    x:=x+5
    end if
   
    if chars (KEY_LEFT_ARROW) then
    x:=x-5
    end if
   
    if chars (KEY_DOWN_ARROW) then
    y:=y-5
    end if
           
            drawbox(x,y,x,y,red)
            delay(50)
cls
end loop
rollerdude




PostPosted: Thu Oct 28, 2004 5:52 pm   Post subject: (No subject)

in our class we have to do animation, my car kicks ass however the program is on th eschool computer so i'll give you my car program when i get to school tommorow

the rollerdude
dying to live




PostPosted: Fri Oct 29, 2004 7:20 am   Post subject: (No subject)

if you can that would be awsome! just pm it to me. Very Happy
Flea




PostPosted: Fri Oct 29, 2004 10:48 am   Post subject: (No subject)

you can stop that annoying blinking by using View.Update:

code:
setscreen("offscreenonly")
loop
View.Update
Input.KeyDown (chars)

Pic.Draw (ufo, x, y, picCopy)
    if chars (KEY_UP_ARROW) then
    y:=y+5
    end if
   
    if chars (KEY_RIGHT_ARROW) then
    x:=x+5
    end if
   
    if chars (KEY_LEFT_ARROW) then
    x:=x-5
    end if
   
    if chars (KEY_DOWN_ARROW) then
    y:=y-5
    end if
           
            drawbox(x,y,x,y,red)
            delay(50)
cls
end loop
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  [ 13 Posts ]
Jump to:   


Style:  
Search: