Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Munchor on May 20, 2011, 11:31:21 am

Title: Physics Introduction Axe Tutorial
Post by: Munchor on May 20, 2011, 11:31:21 am
One of the things that I could never understand in Axe was acceleration/velocity and physics. And although everybody kept saying Builderboy's tutorials were the best for the job, I thought they were too advanced for me when I read them. When I read Axe Physics tutorials I was confused. Of course the tutorials were great, but just not for a true beginner.

All of my games were always non-realistic, without acceleration and using simple code and lots of dirty hacks. The other I finally understood acceleration and physics, and decided to write this very simple tutorial for the job.

Also, you may note most of the code in this tutorial is not optimized so you can understand it better.

Let's start with displaying an image and gravity:

Code: [Select]
.Y Position of the block
0→Y
.X Position of the block
44→X

Repeat getKey(15)
  ClrDraw

  .Draw a line at the bottom
  Line(0,63,95,63)

  .Draw our main image, a square of width=8
  Rect(X,Y,8,8

  !If (pxl-Test(X+3,Y+8))
    Y+1→Y
  End

  DispGraph
End

(http://img.removedfromgame.com/imgs/PhysicsTutorialImage2.gif) Irrealistic Gravity

This code draws a square and it will fall down vertically (gravity) until it hits the line. However, this code is not realistic. If you're surprised, don't worry, it's easy to get.

When an object falls down from, let's say, the top of a building, it will fall down vertically and it's speed will increase. So, the highest speed reached is higher if you throw it from a higher building. Newton calls this speed 'gravitational acceleration'.

So how to make this realistic? We will need a variable for the acceleration and a variable for the Y position of the sprite, so we don't change the Y position of the sprite directly, but add to its speed.

Now the next code uses the Fixed Point or as I prefer the x256 mode. We multiply the X and Y positions of stuff by 256 to get more precision. So if in the code I write X+1→X I'm adding 1/256 of a pixel to X. If you ever had the need to move a sprite/block to the right but not so fast as X+1→X then you can use the x256 mode. It's very important in Axe Physics.

To display sprites we write lines such as Pt-On(X/256,Y/256,PTR. So when we display them, we divide their positions by 256 to fit on the graphscreen. Functions like pxl-Test also require us to divide variables by 256 (if we're using the x256 mode).

Here's how it works to check if a pixel is black:

Code: [Select]
.X And Y Positions as pxl-Test( arguments
If (pxl-Test(X/256,Y/256))
  .CODE
End

Now here's some code that you can use as an example of acceleration and the x256 mode.

Code: [Select]
.Y Position of the block
0→Y
.Y Acceleration of the block
0→B
.X Position of the block
0→X

Repeat getKey(15)
  ClrDraw

  .Draw a line at the bottom
  Line(0,63,95,63)

  .Draw our main image, a square of width=8
  Rect(X/256,Y/256,8,8)

  .If nothing beneath block, make block go down
  !If (pxl-Test(X/256+3,Y/256+8))
    B+4→B
  End

  .If something beneath block, make block stop
  If (pxl-Test(X/256+3,Y/256+8))
    0→B
  End

  Y+B→Y

  DispGraph
End

(http://img.removedfromgame.com/imgs/PhysicsTutorialImage1.gif) More realistic gravity

As you can see, the speed of the block in this code gets higher and higher. However, if it hits the line, it immediately stops.

Now there's a very important concept you need to understand. Vectors and Components of Vectors. A movement can be represented by a vector, here is an example:

(http://img.removedfromgame.com/imgs/BallVector.png)

The ball is moving right because there's a force in the direction where it is going.

Now let's imagine a ball being thrown in the air:

(http://img.removedfromgame.com/imgs/vector1.png)

The ball is not moving to a single direction, but both up and right. The vector has a force, but it can be split in two forces, the X force and Y force. The Y force is the vertical component of the force and the X component is the horizontal component of the force.

So, the last image could be actually represented this way:

(http://img.removedfromgame.com/imgs/vector2.png)

When we add Fx to Fy we have the F force in the previous image.

In Axe, to make acceleration work like in real lifes, we have 4 variables:

Code: [Select]
.X Position
0→X
.Y Position
0→Y
.X Acceleration
0→A
.Y Acceleration
0→B
Repeat getKey(15)
  ClrDraw
 
  .CODE
 
  .Sum acceleration to the positions of the sprites
  X+A→X
  Y+B→Y 
 
  .MORE CODE
 
End

This will make sprites moving much more realistic.

Yet again, note this tutorial is just to let you more comfortable with some concepts and acceleration and Physics in Axe. I recommend you to move on to more advanced tutorials such as Builderboy's and others which can be found in axe.omnimaga.org.

Thanks
I'd like to thank Builderboy for inspiring me to learn Physics by making awesome games.

Thanks squidgetx for a tutorial you wrote on Omnimaga.

Thanks all Omnimaga members for support!

Attached is a PDF version of this tutorial.
Title: Re: Physics Introduction Axe Tutorial
Post by: Ashbad on May 20, 2011, 04:13:05 pm
Awesome job!  This will be very helpful for people new to learning 8.8-based physics :)
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 20, 2011, 06:35:34 pm
Awesome job!  This will be very helpful for people new to learning 8.8-based physics :)

Thanks a lot Ashbad, I actually just used some of the code I posted myself, funny thing :)
Title: Re: Physics Introduction Axe Tutorial
Post by: Ashbad on May 20, 2011, 06:45:24 pm
it's actually pretty good code :) good luck in the contest, it seems as if you're on a good running! :D
Title: Re: Physics Introduction Axe Tutorial
Post by: ztrumpet on May 20, 2011, 06:49:49 pm
This is a very nice tutorial for the basics of physics in games.  Very well done, Scout.  I'm sure that this thread will be pointed tofor inexperienced people to learn from. :)
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 20, 2011, 08:18:59 pm
This is a very nice tutorial for the basics of physics in games.  Very well done, Scout.  I'm sure that this thread will be pointed tofor inexperienced people to learn from. :)

Yeah I really hope so as it was also added to the Tutorials List. Thanks :)
Title: Re: Physics Introduction Axe Tutorial
Post by: Builderboy on May 20, 2011, 08:54:02 pm
This is a wonderful tutorial :D Just one tiny little thing, in the second program you have 4 variables, for position XY, and acceleration AB.  However, AB is not actually acceleration, AB is your velocity.  AB is being applied to XY, which makes AB velocity.  The number that is being applied to AB (in this case its 4 i think) would be your acceleration.  Just suggesting that be changed, or else people might become a little confused as to what acceleration and velocity are :)

Besides that very small quirk though, a very well made tutorial, and one that seems like it could help a lot of people new to Axe :D
Title: Re: Physics Introduction Axe Tutorial
Post by: yunhua98 on May 20, 2011, 08:57:12 pm
hmm, maybe a Physics Axiom could be developed?
Title: Re: Physics Introduction Axe Tutorial
Post by: Builderboy on May 20, 2011, 09:54:07 pm
http://ourl.ca/4665

 8)
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 20, 2011, 10:00:16 pm
Thanks a lot for the feedback Builderboy and thanks for the acceleration/velocity difference explanation. I shall change it :)
Title: Re: Physics Introduction Axe Tutorial
Post by: Jonius7 on May 21, 2011, 12:13:01 am
Wow this is great! I'll be hoping to use something like this in my game
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 21, 2011, 09:27:02 am
Wow this is great! I'll be hoping to use something like this in my game

Thanks a lot for the support too :)

I wrote a new tutorial, not sure if should be like Part II of this one or a completely new tutorial by the way :P
Title: Re: Physics Introduction Axe Tutorial
Post by: yunhua98 on May 21, 2011, 09:57:18 am
Depends, what's it about?
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 21, 2011, 10:53:17 am
Well, people who read this have learnt the basics and gravity. In the other tutorial I wrote, they learn movements, so they can move objects.
Title: Re: Physics Introduction Axe Tutorial
Post by: Deep Toaster on May 21, 2011, 11:53:29 am
Another great tutorial for people to start experimenting :D

Minor correction: "Irrealistic" should be "Unrealistic" ;D
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 23, 2011, 08:54:22 am
Another great tutorial for people to start experimenting :D

Minor correction: "Irrealistic" should be "Unrealistic" ;D

XD Thanks my English still has a flaw or two :P
Title: Re: Physics Introduction Axe Tutorial
Post by: DJ Omnimaga on May 25, 2011, 04:28:02 am
Nice job Scout!
Title: Re: Physics Introduction Axe Tutorial
Post by: Munchor on May 27, 2011, 05:22:29 pm
Nice job Scout!

Thanks a lot DJ :D