PDA

View Full Version : A small Flash game/toy: Building demolition


genericuser
03-06-2007, 01:08 PM
I found a tutorial for a small gravity engine in Flash, tinkered a bit with it(added horizontal motion), and made this small toy/pointless game.

Enjoy!

Building Demolition (http://www.swfupload.com/view/125256.htm)

Please post ideas and comments.

Jokker
03-06-2007, 06:01 PM
Actually it's not all that bad. The movement is a bit clunky, but it's not like you spent hours on optimizing, so it works.

What would have been better, would have been disabling gravity once the bomb exploded, and maybe adding mouse control.

Overall, it's above average, and pretty good provided you added horizontal motion yourself.

How much time did you spend on it?

Rob223
03-06-2007, 09:01 PM
M...m...m... Mouse control.

What did I just say?

genericuser
03-07-2007, 07:32 AM
Actually it's not all that bad. The movement is a bit clunky, but it's not like you spent hours on optimizing, so it works.

What would have been better, would have been disabling gravity once the bomb exploded, and maybe adding mouse control.

Overall, it's above average, and pretty good provided you added horizontal motion yourself.

How much time did you spend on it?
One hour, mostly tinkering with different options and buildings.

Jokker
03-07-2007, 08:01 AM
Well, it's pretty good for just one hour. Like I said, disable the gravity for exploding bombs, mouse control, bouncing off walls and it'd be a neat game to waste 2 minutes on.


EDIT: Mind sharing the tutorial? I got an hour to waste as well. =D

Dj Demetrius
03-07-2007, 02:09 PM
I want to learn how to make games too..:p

mister.x
03-07-2007, 02:14 PM
I didnt like it :confused: why is it so good ???

genericuser
03-07-2007, 08:37 PM
Well, it's pretty good for just one hour. Like I said, disable the gravity for exploding bombs, mouse control, bouncing off walls and it'd be a neat game to waste 2 minutes on.


EDIT: Mind sharing the tutorial? I got an hour to waste as well. =D

Sure! Make an MC of a ball and a platform.
Call the platform's instance "floor".
Apply this code to the ball MC:

onClipEvent(load){
velocity = 0
gravity = 2
friction = 0.01
}
onClipEvent(enterFrame){
velocity += gravity
velocity -= friction*velocity
_y += velocity
if(_y>_root.floor._y){
_y = _root.floor._y
velocity *= -0.9
}
}

(Make sure you place the ball over the platform
because it is the platform which makes it bounce) (http://www.flashkit.com/tutorials/Math-Physics/Simple_G-GinjaNin-1093/index.php)

I'll post my version later. Have to fix some code.

Stupid question: By mouse control, do you mean being able to place the bomb before dropping it?

genericuser
03-08-2007, 07:07 AM
The code for my gravity engine:
//My (maybe not-so)simple gravity engine, now capable of horizontal motion

//Made by "genericuser", based on the gravity engine from GinjaNinja

onClipEvent(load){ //set variables
velocity = 0 //intially, the bomb doesn't go up or down
gravity = 2 //set gravity here
friction = 0.01 //vertical friction
horizontalfriction = 0.03 //horizontal friction??? stops the bomb gradually
horizontalvelocity = 3.5 //starting speed of the bomb
}
onClipEvent(enterFrame){
velocity += gravity //GinjaNinjas code
velocity -= friction*velocity
if (horizontalvelocity > 0.1){ //small hack needed to fix a problem
horizontalvelocity -= horizontalfriction //slow down the bomb
}
_y += velocity
_x += horizontalvelocity //the ACTUAL horizontal movement
if(_y>_root.floor._y){ //if the bomb hits the floor, bounce
_y = _root.floor._y
velocity *= -0.9
}
}

BTW, I fixed the problem with bouncing explosions. When I add the other suggestions from Jokker, i'll upload it.

Jokker
03-08-2007, 08:30 AM
By mouse control, I mean that you do this:

When mouse_x and mouse_y (forget the variable names, but meh =\) are in the ball and a mouse button is pressed, gravity and everything disables, and the ball moves with the mouse. During that time, you calculate x_speed and y_speed using x_speed= x_ball - x_ball_last_frame, and when you let go of the mouse button, the speed remains in the program, and the ball continues to go, like inertia.

PS. make it bounce off the walls so you can actually see if it's going well.


Oh, and I'll try to optimize the original program and add my own stuff into it...once I get a Flash Player installed and ready to test... =\

SataMaxx
03-08-2007, 03:04 PM
Well in fact just adding instantaneous speed to positions to get the new coordinates gets you to wrong results, and you'll see it if you want to use *real* formulas and values for gravity, or make objects interact with each other (such as a gravitational system with more than two objects, or objects connected by springs).
To really simulate physics, you need to get the real differential equations that define the movement, and calculate the next step value for each variable (speed, acceleration, damping....) with some kind of algorythm. Simply calculating the following step by adding values will lead you to results totally different that what expected. One of the calculation method for solving numerically the differential equations is called the Runge-Kutta algorythm, and to my own expereince it's quite accurate and powerful.
If you want some examples for using it (such as movement under gravity and damping, or spring movement, or whatever...), I'll be glad to post some links and generic code.

Jokker
03-08-2007, 06:16 PM
That'd be great if you could. Though well...my main problem is...well...I don't really understand the basics of C++ or other languages. Not as in syntax or stuff. But how to SET UP the COMPILER. I can't make Bloodshev C++ even run a bit of Hello World code, because I don't know what type of file to create..

So yeah...

PS. What...do you write Flash in? Macromedia (I think it's Adobe now, but meh) Flash ...something. I can't recall the name...

Dj Demetrius
03-08-2007, 06:31 PM
I didn't understand much of that code there, but you guys really got some talent. Keep that up and you'll (probably) be great game developers some day, creating Cortex Command 2, and a new better Toribash!

SataMaxx
03-08-2007, 07:13 PM
If you don't know how to code I presume it's a bit useless to post complicated programming stuffs here. But I can already give you one very good link : http://www.myphysicslab.com/
On this site are some very basic-physic toys in java, the explanation of the physics behind them, and some explanations on how to program them, but not full, you'll have to figure out some things by yourself...
@jokker : we could meet sometime on irc or whatever so that I help you configuring dev-c++

Now if someone (really) knows how to program, and wants some help with physics I can help with code or explanations....

VinceA
03-10-2007, 11:55 PM
PS. What...do you write Flash in? Macromedia (I think it's Adobe now, but meh) Flash ...something. I can't recall the name...

Well you can write your action script 3 code in Flex. Works very nice! The new AS3 is faster than AS2 but still struggles with bitmaps. Not ideal for a fullscreen scroller..

For more on that: http://www.cove.org/ape/

fusion1224
04-11-2007, 10:07 AM
To really simulate physics, you need to get the real differential equations that define the movement, and calculate the next step value for each variable (speed, acceleration, damping....) with some kind of algorythm.

To calculate physics properly you need to introduce a timestep, which allows the path of a physically simulated object to be calculated over time.
I use Verlet integration for calculating physics simulations. There are many flash physics demos out there that use Verlet, for example the Ape physics engine mentioned in the last post.

This is a great paper on Verlet which goes into detail without getting too complicated:
http://www.teknikus.dk/tj/gdc2001.htm

OkumTheLostNinja
07-22-2007, 10:40 PM
What would have been better, would have been disabling gravity once the bomb exploded

i agree i dont like when those part of the buildings fly up