Physics, motion, and gravity in a Turing game
Author |
Message |
isaiahk9
![](http://compsci.ca/v3/uploads/user_avatars/1465120414488e669e1f83a.jpg)
|
Posted: Thu Apr 24, 2008 5:19 pm Post subject: Physics, motion, and gravity in a Turing game |
|
|
I need to make a game in Turing for a final project, worth 15% of my overall mark, which is life-and-death with me right now. So, my game is going to be a 2D fighter game - in real time you will attack an opponent, and the opponent will do vice-versa. I already know how to do most of the code except I have run into a block. I have honestly no clue how to do the following :
Gravity.
Trajectory.
"Throw"
Gravity is simply that the players will always contently be attracted to the bottom of the screen, but smoothly so that previous motion will affect the direction of the fall.
Trajectory is when one character shoots a projectile weapon, (like a bow and arrow), it will smoothly fall to the screen in a realistic-arc.
"Throw" is by far the most tricky. In my game, when you are hit by your opponent, your "damage meter" increases. The more damage, the farther each attack that your opponent lands on you will send you flying. You lose the game by being thrown off the screen. As well, different moves have more and less "throw" - how far the attack will send the foe flying. 1 is less throw and 2 is more throw. For example :
A punch (1 throw) will send the foe 20 pixels flying at 0% damage.
A kick (2 throw) will send the foe flying 30 pixels flying when at 0% damage.
A sword (3 throw) will send the foe flying 40 pixels flying at 0% damage.
A punch (1 throw) will send the foe 25 pixels flying at 10% damage.
A kick (2 throw) will send the foe flying 38 pixels flying when at 10% damage.
A sword (3 throw) will send the foe flying 50 pixels flying at 10% damage.
A punch (1 throw) will send the foe 30 pixels flying at 20% damage.
A kick (2 throw) will send the foe flying 45 pixels flying when at 20% damage.
A sword (3 throw) will send the foe flying 60 pixels flying at 20% damage.
I have no clue how to do these three things, and I would appreciate it greatly if somebody could help. If you do help me, thank you so much. Your name and anyone you reference will have full credit for your aid, and included in the credits.
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
metachief
![](http://compsci.ca/v3/uploads/user_avatars/59969875948ed1e6be9fb0.jpg)
|
Posted: Thu Apr 24, 2008 6:18 pm Post subject: Re: Physics, motion, and gravity in a Turing game |
|
|
ok..first of all you have to take it one step at a time. considering the fact that youre a noob (not in a bad way) and only started this, you will not be able to make your game with all those graphics and advanced actions. when i started out i had many ideas and in the end i found out that its not that easy. so stick to siple things for now, i dont mean boring and usless, but simple and well made.
i can help you with the gravity (pretty simple if you would actually think for a bit). trajectory is asociated with gravity if youre talking about arrows flying accross the screen (the problem with that is you should learn how to use arrays first, makes your programming life easier)
Heres a gravity simulation (box jumping around):
ps: spend more time thinking and less time typing and getting errors, proffesionals usually spend 3 hours thinking and 20 min typing.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
New Compressed (zipped) Folder.zip |
Filesize: |
462 Bytes |
Downloaded: |
359 Time(s) |
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
gravity.t |
Filesize: |
673 Bytes |
Downloaded: |
1223 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Thu Apr 24, 2008 8:36 pm Post subject: RE:Physics, motion, and gravity in a Turing game |
|
|
isaiahk9 you obviously don't really understand gravity if you have to ask about trajectory, and how to increase it. I'm not sure what your perception is about gravity, but here's how it works.
Basically you have and object that has a varying y velocity, and a constant x velocity. You will have acceleration of gravity pulling down on the object, decreasing the y velocity. Your x velocity is constant so your displacement in the x plane is linear. Increasing the x velocity will "push you back further".
|
|
|
|
|
![](images/spacer.gif) |
I Smell Death
|
Posted: Fri Apr 25, 2008 10:42 am Post subject: Re: Physics, motion, and gravity in a Turing game |
|
|
Here is a simulation that i did using some real world numbers for the physics calculations. I realise that there are some problems with it like it actually adds the acceleration to the velocity every frame instead of only a fraction of it.
Turing: |
%Bouncing Ball
%? I Smell Death 2007-2008
View.Set ("graphics:max;max,offscreenonly,nobuttonbar")
const accG := - 9. 804
const scale := 5
const friction := 0. 57
const mass := 5
const Fn := mass * accG
const FPS := 30
const minWait := 1000 div FPS
var lastFrame : int := 0
var accX : flexible array 1 .. 0 of real
var Ff : real
var Vx, Vy : flexible array 1 .. 0 of real
var x, y : flexible array 1 .. 0 of real
type shape :
record
x1 : int
y1 : int
x2 : int
y2 : int
x3 : int
y3 : int
end record
var triangle : shape
proc newball (tx, ty : real)
var top : int := upper (x ) + 1
new x, top
new y, top
new Vx, top
new Vy, top
new accX, top
Vx (top ) := 0
Vy (top ) := 0
accX (top ) := 0
x (top ) := tx
y (top ) := ty
end newball
newball (maxx / 2, 3000)
function newvel (vel, accel : real) : real
var temp : real := vel + accel
result temp
end newvel
function ptan (deg : real) : real
var out : real := sind (deg ) / cosd (deg )
result out
end ptan
proc groundhit (ball : int)
var ty : real := y (ball ) + Vy (ball )
if ty <= 10 and Vx (ball ) ~ = 0 then
Ff := friction * Fn
accX (ball ) := Ff / mass
if Vx (ball ) < 0 then
accX (ball ) * = - 1
end if
Vx (ball ) := newvel (Vx (ball ), accX (ball ))
else
accX (ball ) := 0
end if
end groundhit
procedure move (ball : int)
var tTime : real := (Time.ElapsedCPU - lastFrame ) / 1000
put tTime
%break
x (ball ) + = Vx (ball ) % * tTime)
y (ball ) + = Vy (ball ) %* tTime)
if x (ball ) <= 10 or x (ball ) >= maxx * scale - 10 then
Vx (ball ) * = - 1
x (ball ) + = Vx (ball )
end if
if y (ball ) <= 10 then
Vy (ball ) * = - 1
y (ball ) + = Vy (ball )
end if
groundhit (ball )
end move
function colide (ball : int) : real
var prevx, prevy : real
prevx := x (ball ) - Vx (ball )
prevy := y (ball ) - Vy (ball )
var mx, my, but : int
Mouse.Where (mx, my, but )
mx * = scale
my * = scale
if x (ball ) - mx >= 0 and x (ball ) - mx <= 40 * scale then
if prevy - my >= - (prevx - mx ) + 40 * scale and y (ball ) - my <= - (x (ball ) - mx ) + 40 * scale then
result - 45
end if
end if
%put "angles: ", mx, " ", my
result 0
end colide
proc speedbox (ball : int)
var prevx, prevy : real
prevx := x (ball ) + Vx (ball )
prevy := y (ball ) + Vy (ball )
if x (ball ) <= 100 * scale and y (ball ) >= 10 and prevy <= 10 then
Vy (ball ) + = 1
end if
end speedbox
proc deflect (ang : real, var Vxt, Vyt : real)
var tVx : real
tVx := Vxt
Vxt := Vyt / ptan (ang )
Vyt := ptan (ang ) * tVx
end deflect
proc drawball
for ball : 1 .. upper (x )
drawfilloval (round (x (ball ) / scale ), round (y (ball ) / scale ) + 9, 10, 10, black)
end for
drawline (0, 1, maxx, 1, grey)
drawline (0, 1, 100, 1, green)
drawline (triangle.x1, triangle.y1, triangle.x2, triangle.y2, black)
drawline (triangle.x2, triangle.y2, triangle.x3, triangle.y3, black)
drawline (triangle.x3, triangle.y3, triangle.x1, triangle.y1, black)
%put "Ball: ", x, " ", y
end drawball
proc findtriang
var mx, my, button : int
Mouse.Where (mx, my, button )
if button ~ = 0 then
newball (mx * scale, my * scale )
end if
triangle.x1 := mx
triangle.y1 := my
triangle.x2 := mx + 40
triangle.y2 := my
triangle.x3 := mx
triangle.y3 := my + 40
end findtriang
var frameWait : int := 0
var frames : int := 0
var ang : real
loop
frames + = 1
for ball : 1 .. upper (x )
findtriang
Vx (ball ) := newvel (Vx (ball ), accX (ball ))
Vy (ball ) := newvel (Vy (ball ), accG )
speedbox (ball )
ang := colide (ball )
if ang ~ = 0 then
deflect (ang, Vx (ball ), Vy (ball ))
end if
move (ball )
end for
cls
drawball
put frames
View.Update
frameWait := Time.ElapsedCPU - lastFrame
if frameWait < minWait then
delay (minWait - frameWait )
end if
lastFrame := Time.ElapsedCPU
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
|
|