5/28/2008

Making a blob in Flash part 2

Now, lets start for real!

And lets start with the base of our blob: The Verlet implementation.
I can't really explain what is verlet, it's simply the best (and easiest) way to simulate real movements in computer. It may look simple, but is very powerful!

And here's the Flash version of it:

  1. function verlet(particle){
  2. with(particle){
  3. if(oldx == undefined or oldy == undefined){
  4. oldx = _x;
  5. oldy = _y;
  6. }
  7. tempx = _x;
  8. tempy = _y;
  9. _x = _x + (_x - oldx);
  10. _y = _y + (_y - oldy);
  11. oldx = tempx;
  12. oldy = tempy;
  13. }
  14. }

It may looks quite simple, but is not! It works this way:

2: It calls the particle and amkes the particle execute the following code
3, 4, 5: It checks whether the two variables (oldx,oldy) exists, if not, create them
8, 9: Stores the current position in two temporary variables.
11, 12: Moves the particle based on the last position, that is, if last x position is 5, and current x position is 10, then calculates (10-5) and apply it
14, 15: Now store the last position (before the last calculation) in the oldx and oldy variables.

See? Simple, hun? Now, lets test it! :D


_root.createEmptyMovieClip("verlet1",_root.getNextHighestDepth());
grav = .3;

verlet1._x = Stage.width/2;
verlet1._y = Stage.height/2;

verlet1.lineStyle(2,0,100);
verlet1.beginFill(0xFF0000,100);
verlet1.moveTo(-15,-15);
verlet1.lineTo(-15,15);
verlet1.lineTo(15,15);
verlet1.lineTo(15,-15);
verlet1.lineTo(-15,-15);
verlet1.endFill();

function onEnterFrame(){
verlet(verlet1);
verlet1._y += _root.grav;
}

function verlet(particle){
with(particle){
if(oldx == undefined or oldy == undefined){
oldx = _x;
oldy = _y;
}

tempx = _x;
tempy = _y;

_x = _x + (_x - oldx);
_y = _y + (_y - oldy);

oldx = tempx;
oldy = tempy;
}
}


Now, what you may see when paste and execute this code on Flash is a red box falling on the stage. Nothing more, but it may be more complex if implemented a constraint script.
This, and more, at the next part ;)

5/27/2008

Making a blob in Flash part 1

I was wandering around triquitips and I saw an thread about how to make a soft body physics in Flash.
It took me some time to make, but I just finished a simple 'soft body' exapmple:

http://www.swfme.com/view/1175742

Well, it's quite simple and basic, but that's the idea.
I'm going to guide you throught all world of Physics, starting with verlet, constraints, and all other maths involved in the making of a blob.

So, stay toned!

5/21/2008

Hello everyone!

Hi, My name is Luiz and I'm a casual Flash game developer, which means that I don't make games for commercial (i.e. not free) intentions.

In this blog I'll log my progress as a gme developer and I'll make also some tutorials.

And as a new blog, it deserves a glorious first post, right?! :D
Nop! As I don't have time now. :(
But 'til tomorrow I'll post something useful....

Stay tunned!