Author Topic: Physics Introduction Axe Tutorial  (Read 14114 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Physics Introduction Axe Tutorial
« 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

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

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:



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:



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:



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.
« Last Edit: May 20, 2011, 04:22:29 pm by Scout »

Ashbad

  • Guest
Re: Physics Introduction Axe Tutorial
« Reply #1 on: May 20, 2011, 04:13:05 pm »
Awesome job!  This will be very helpful for people new to learning 8.8-based physics :)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #2 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 :)

Ashbad

  • Guest
Re: Physics Introduction Axe Tutorial
« Reply #3 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

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #4 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. :)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #5 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 :)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #6 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

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #7 on: May 20, 2011, 08:57:12 pm »
hmm, maybe a Physics Axiom could be developed?

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #8 on: May 20, 2011, 09:54:07 pm »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #9 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 :)

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Physics Introduction Axe Tutorial
« Reply #10 on: May 21, 2011, 12:13:01 am »
Wow this is great! I'll be hoping to use something like this in my game
« Last Edit: May 21, 2011, 12:13:19 am by jhgenius01 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #11 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

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #12 on: May 21, 2011, 09:57:18 am »
Depends, what's it about?

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Physics Introduction Axe Tutorial
« Reply #13 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Physics Introduction Axe Tutorial
« Reply #14 on: May 21, 2011, 11:53:29 am »
Another great tutorial for people to start experimenting :D

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