Sunday, April 25, 2010

Space Triangle

Well I got really bored today, and thought I could give back a bit to the community. The end result is a ship (triangle) that floats across a stage. The user controls the ship using keyboard arrow keys. The animation is frame independent. That means I explore a bit about frame time calculations, which in code translate into a variable declaration and three lines of code.

To cut the chase short, here's what you can do with 1 line on top of a hundred in pure Actionscript 3 programming.

Check the source code here.

This triangle is a repeated theme in my experimental work, and has been so since I was back in High School. You can imagine that the math involved is really simple arithmetic. That's the elegance that I appreciate for an introduction.

I will not break the habit of not writing code in this blog, and instead I'll explain the core concepts behind this basic program. For a technical undertaking, the code is extremely self explanatory and is very brief.

The game, as I said before, is simply a little triangle that's controllable using the arrow keys. It slides across the screen.

The states I keep watching are the position and rotation of the triangle (which I get for free after creating a sprite). I also create three variables to keep an eye on velocity on the x-axis (sideways), velocity on y-axis (vertically), and rotation.

Three event listeners are in action, two to watch key strokes (and save them into three additional state variables), and one to be called on each frame (the whole simulation driver).

Beyond that, it's a matter of figuring out how to update velocity and rotational velocity based on the keystrokes, then how to update position and rotation based on the velocity variables. There's a piece of trigonometry on conversion from traingle angle into an acceleration vector.

One more piece is left missing, which is the link between the velocity variables, and the positional ones. This piece is the delta time between frames. To keep the motion frame-independent (as in, the same across all computers regardless of processing power), I calculate the time in milliseconds it takes from each frame to the next one. Although it's quite an extrapolation in terms of numerical precision, it does it's job, and the motion is basically frame independent.

Monday, April 19, 2010


While the other posts have been about the development of arithma, this post is about the development of arithma.

The latest and most prevalent fact about me is simply that I am freelancing as a developer and more so as a solution provider. It has been about 6 months of ups and downs... an emotional, and stressful roller-coaster. A lot of people enjoy these, and a lot of people end up with a yellow face and with lots of goo on the ground (when it comes to roller coasters, am personally more on the goo-side).

Yet in real life, the gut is strong, and to answer the question in my head: "So how was life for you, punk?"... I'd simply have to say: "It was such a ride! Again."... I prefer this answer to "Well it was really safe, I felt comfortable". Hardly "yay".

For a more objective comparison between being employed, and starting up, here's a [hardly exhaustive] list of some things I'd like you to know:
  • Don't expect to become rich right away
  • Don't expect to make more financially than by being employed right away
  • Don't expect to work less than when being employed
  • Expect a lot more to learn than just being pigeon holed into your tasks while employed
  • Expect a lot more freedom in what you're able to work on and explore
  • Expect a lot more satisfaction and attachment to the products you are working on
  • Expect a lot more tense relation with your work
  • Expect a lot more ability to work on the techniques you deliver your own work, and ability to set your schedule experimentally, and being able to actually achieve an improvement (rather than being dictated to a scrawl in updates to higher management and overhead)
  • Expect to have a whole more lot of fun
This is simply a fun game, but not for the faint of heart.
I encourage everyone able to start up, to do so... There's a lot more to life than sitting behind a desk and waiting for a paycheck.