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

0 Members and 3 Guests are viewing this topic.

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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 block0→Y.X Position of the block44→XRepeat 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  DispGraphEnd
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( argumentsIf (pxl-Test(X/256,Y/256))  .CODEEnd
Now here's some code that you can use as an example of acceleration and the x256 mode.

Code: [Select]
.Y Position of the block0→Y.Y Acceleration of the block0→B.X Position of the block0→XRepeat 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  DispGraphEnd
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 Position0→X.Y Position0→Y.X Acceleration0→A.Y Acceleration0→BRepeat 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

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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!

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.
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.
If I'm wrong, please correct me!
Unfinished Projects:
 Elmgon 14% Basic Movement Demo Homescreen Game Pack 80% Basic Latest Release Cube Droid Saves the Galaxy 65% Axe Demo Detonate 70% Axe
Completed Projects:
Exodus | Midnight |Drifter | Axe Snake | Jump! | Factory Theta | Spider | Plot Drop | Papi Jump | Numb3rs | Nibbler | Boost | Duel Tile Map Editor | Homescreen Map Editor | Key Group Check | Oasis

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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

Builderboy

• Physics Guru
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 5673
• Rating: +613/-9
• Would you kindly?
Re: Physics Introduction Axe Tutorial
« Reply #6 on: May 20, 2011, 08:54:02 pm »
This is a wonderful tutorial 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

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.
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.
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>

Builderboy

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

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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

Jonius7

• python! Lua!
• LV10 31337 u53r (Next: 2000)
• Posts: 1918
• Rating: +82/-18
• Still bringing new dimensions to the TI-nspire...
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 pastDJ Omnimaga Music Discographist DJ Omnimaga DiscographyMy Own Music!
My Released Projects (Updated 2015/05/08)
 TI-nspire BASICTI-nspire Hold 'em Health Bar Scissors Paper Rock TI-nspire LuaNumstrat TI-nspire Hold 'em LuaTransport ChooserSecret Project (at v0.08.2 - 2015/05/08) Spoiler For Extra To-Be-Sorted Clutter: Spoiler For Relegated Projects: TI-nspire BASICBattle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)Axe ParserDoodle God (stalled while I go and learn some Axe)

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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

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.
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.
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>

Munchor

• LV13 Extreme Addict (Next: 9001)
• Posts: 6199
• Rating: +295/-121
• Code Recycler
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.

Deep Toaster

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

Minor correction: "Irrealistic" should be "Unrealistic"