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

Username:   Password: 
 RegisterRegister   
 basic tutorial on simple projectle movement(a bit advanced)
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Wed Dec 03, 2003 9:26 pm   Post subject: basic tutorial on simple projectle movement(a bit advanced)

code:
View.Set ("offscreenonly")
%%%%%%%%%%Declaring projectile type as an object%%%%%%%%%%5
type projectile_t :
    record
        startx, starty, x, y, angle, weight, velocity : real
    end record

var projectile_1 : projectile_t

%set start point to 0,0
projectile_1.startx := 0
projectile_1.starty := 0
%setting the velocity(the throw power to 80
projectile_1.velocity := 80
%The angle that the projectile's thrown in
projectile_1.angle := 60
%how heavy the object is...
projectile_1.weight := 10
%setting the initial time to 0
var time1 := 0.0

procedure Projectile (var obj : projectile_t, t : real)
    obj.x := (obj.velocity * cosd (obj.angle) * t) + obj.startx
    obj.y := (obj.velocity * sind (obj.angle) * t - (obj.weight) * t ** 2 / 2) + obj.starty
end Projectile

loop
    time1 += .1 %The time and how fast it is moving
    Projectile (projectile_1, time1) %applying movements to the projectile
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 5, 5, 12) %draw the projectile
    View.Update
    delay (10)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 5, 5, white) %erase the projectile
end loop
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Wed Dec 03, 2003 9:38 pm   Post subject: (No subject)

here's one a bit more advanced...
code:
View.Set ("offscreenonly")
%%%%%%%%%%Declaring projectile type as an object%%%%%%%%%%5
type projectile_t :
    record
        startx, starty, x, y, angle, weight, velocity, bounciness : real
    end record

var projectile_1 : projectile_t

%set start point to 0,0
projectile_1.startx := 0
projectile_1.starty := 200
%setting the velocity(the throw power to 80
projectile_1.velocity := 60
%The angle that the projectile's thrown in
projectile_1.angle := 80
%how heavy the object is...
projectile_1.weight := 10
%setting the bounciness
projectile_1.bounciness := 10
%setting the initial time to 0
var time1 := 0.0

procedure Projectile (var obj : projectile_t, t : real)
    obj.x := (obj.velocity * cosd (obj.angle) * t) + obj.startx
    obj.y := (obj.velocity * sind (obj.angle) * t - (obj.weight) * t ** 2 / 2) + obj.starty
end Projectile

procedure Bounce (var obj : projectile_t, var t : real)
    if obj.y <= obj.starty then
        if (obj.velocity) > 0 then
            t := 0
            obj.startx := obj.x
            obj.starty := obj.y
            obj.velocity -= obj.bounciness
        end if
        if (obj.velocity) < 0 then
            obj.velocity := 0
        end if
    end if
end Bounce
loop
    time1 += .1 %The time and how fast it is moving
    Projectile (projectile_1, time1) %applying movements to the projectile
    Bounce (projectile_1, time1)%Detect ground and bounce back
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 5, 5, 12) %draw the projectile
    View.Update
    delay (10)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 5, 5, white) %erase the projectile
    exit when projectile_1.velocity <= 0
end loop
HeTeRiC




PostPosted: Thu Dec 11, 2003 10:45 pm   Post subject: (No subject)

That second one is cool, looks like interactive physics. there both sweet tho, good job!

how would i make a program that gets the variables like throw speed ect and the sets them??
so i could play cannons Wink
Homer_simpson




PostPosted: Thu Dec 11, 2003 11:13 pm   Post subject: (No subject)

well... i've basically given u everything u need to know... but if u want something more clear to make cannons check out my "turing worms" post...
Andy




PostPosted: Fri Dec 19, 2003 10:28 am   Post subject: (No subject)

i don't understand physics x_X
Triple Five




PostPosted: Tue Jan 06, 2004 7:44 pm   Post subject: (No subject)

thanks man! Very Happy really helped when i tried to make a sun make make it so that it went throughout the day from east to west in a projectile movenment! Very Happy i also tried to understand it along the way! Very Happy
Homer_simpson




PostPosted: Tue Jan 06, 2004 8:59 pm   Post subject: (No subject)

well to make a sun... i would just use parabola...
Triple Five




PostPosted: Wed Jan 07, 2004 12:30 pm   Post subject: (No subject)

how would u use that! Confused can u give an eg. or maybe a link to a tutorial! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Wed Jan 07, 2004 8:50 pm   Post subject: (No subject)

how bout this one?
code:
colorback (black)
cls
View.Set ("offscreenonly")
var y := 0.0
for x : -320 .. 320
    y := .001 * (-x ** 2)
    drawdot (x + 320, round (y) + 100, black)
    drawfilloval (x + 320, round (y) + 100, 20, 20, 14)
    View.Update
    drawfilloval (x + 320, round (y) + 100, 20, 20, black)
end for
Triple Five




PostPosted: Thu Jan 08, 2004 10:30 am   Post subject: (No subject)

thanks man i find it much better for sun movement than the projectile one! Very Happy
Leiak




PostPosted: Sun Jan 18, 2004 12:03 am   Post subject: im confused

whenever i try to run 95% of the programs on this site on my object oriented turing program it says Update is not part of export list View or something like that do i need a new program to run these or wut im lost plz help
Tony




PostPosted: Sun Jan 18, 2004 2:31 am   Post subject: (No subject)

yes, you need the new program... You need 4.0.x for View.Update.

as a matter of fact, 4.0.5 came out today and there's a link for it on the main page (along with other news)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Schaef




PostPosted: Mon Jan 19, 2004 4:40 pm   Post subject: (No subject)

where does the 0.001 come from in the y:=0.001 * (-x**2)? i dont get how that works. if i change it to 0.01 then it doesnt show nething
Cervantes




PostPosted: Wed Jan 21, 2004 5:21 pm   Post subject: (No subject)

damn I can't wait till I can take gr 11 physics Razz
Homer_simpson




PostPosted: Thu Jan 22, 2004 12:20 pm   Post subject: (No subject)

lol... i still haven't had physics! Laughing taking it next semester...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 30 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: