PDA

View Full Version : Making a Classic Asteroids Game


abeisgreat
05-05-2007, 09:50 PM
I am trying to make a classic astreoids game. But i am having problems with the driving engine. Most people should know the game I mean. Its the one with the little ship that spins around and shoots astroids. Well If anyone can give me the code or direct me to a tutorial or something. That would be great. Thanks!

arkhan
05-06-2007, 10:44 AM
find a car tutorial, then get rid of the friction part...voilá

abeisgreat
05-06-2007, 06:08 PM
i tryed that, I couldnt find a good tut

Jared
05-06-2007, 06:41 PM
Why do people think they can tutorial everything >_>

abeisgreat
05-06-2007, 08:20 PM
I dont know. But really I need help!

truimagz
05-06-2007, 11:25 PM
I shouldnt do this because this is simple stuff and you should learn to make these things yourself not just use code you dont know how it works but here.

first I would reccomend exporting your ship in 360 degrees, this way when you turn you get a nice light effect, thi si saying your ship is maybie a 3d model, you dont want the light always on the nose regardless of the way your facing, you wan the light always north, or south or whatever.


// this will place your ship as you turn on the right frame, since were not using _rotation, this way we use the actual frame of the ship facing its direction, because of the light situation I was saying


_root.attachMovie("ship","ship",100);
_root.attachMovie("spaceWorld","spaceWorld",10);

function getFrame (shipAngle){
shipAngle %= 360;
shipAngle += shipAngle<0 ? 360 : 0
return Math.floor(ship._totalframes*shipAngle/360)
}

var angle = ship._rotation
var speed:Number = ///whatever you want speed to be
var v:Number = ////whatever you want the velocity to be
var va:Number = ////whatever you want the velocity angle to be

onEnterFrame = function (){

angle = angle>360 ? 0 : angle<0 ? 360 : angle
ship.gotoAndStop (getFrame(angle));
var rad:Number = angle*Math.PI/180;

spaceWorld._x += speed*Math.cos(rad);
spaceWorld._y -= speed*Math.sin(rad)

if (Key.isDown(Key.SPACE)){ ///acceleration button
speed += v
}else{
speed -= v
}

if (Key.isDown(Key.RIGHT)){
angle -= va+speed
}else if (Key.isDown(Key.Left)){
angle+= va+speed
}
}

then just create a movie clip named ship, put your frames if there 360, if not put 80 or whatever you got.

then create your spaceWorld movie clip

setup linkgae on both.

arkhan
05-07-2007, 05:19 AM
the bad part about making 360 frames, one for each angle, is that you end up with only 360 directions...coz you dont have the 116º15' angle or 127º55'22" angle.. so its most likelly to look a bit choppy.

abeisgreat
05-07-2007, 09:26 AM
Thanks everyone

truimagz
05-07-2007, 12:27 PM
arkhan I dont think it will look choppy at all with 360 frames, geez maybie if it were 80, or even 40, but no one would notice any choppyness with 360 frames, were talking about rotation so small that looking at frame and frame 2 yo would probabl think there the same frame.

no one is going to even be able to tap left and have it go just 1 frame its going to be like press left and it goes 4-5 frames, creating a tween look without using the tween class.

render 360 frames and try it, unless your fps is at like 2 its going to look smooth. I'd even say just render 80 and you'll be fine.

medhopz
05-07-2007, 12:43 PM
truimagz

i would really appriciate if you wrote the ifs the full way (the way that is easier to understand)

if(...) {
}
cause i think i will learn a lot more from the code above that way

truimagz
05-07-2007, 02:09 PM
what if statement you talking about? I wrote them out the normal way, there only one way to write them....

are you talking about the }else if(){

?

medhopz
05-07-2007, 03:09 PM
im talking about this line:
angle = angle>360 ? 0 : angle<0 ? 360 : angle


i think its if statement, not sure
if its not, could you explain to me how it works?

Jared
05-07-2007, 03:38 PM
im talking about this line:


i think its if statement, not sure
if its not, could you explain to me how it works?
I'll explain the first part
angle>360 ? 0
Is saying that if the angle is greater than 360 to set the angle variable to 0
angle<0 ? 360
Is saying that if the angle is less than 0 set the angle variable to 0
If its easier for you

if (angle>360) {
angle = 0;
} else if (angle<0) {
angle = 360;
}

This is saying the same thing as that.

arkhan
05-07-2007, 07:50 PM
I tried it with 360 frames..it doesnt look as good as with rotation..but anyway..the light coming from on side all the time looks bad as well...even worse..its just that, the game gets much bigger with 360 images just to change the light..I really cant waito for papervision3d to come out..
for a lil look at it
www.papervision3d.org

truimagz
05-08-2007, 12:43 AM
yea, you really gotta play with it to get it smooth I made a race car game once and did it this way, I had to play with the frames to get it to work right and run smooth, I always set 30 fps though, I think my car frames were 90 also.

It comes out nice with some TLC.

Matt
05-08-2007, 04:20 AM
If you want to use rotation and still have lighting effects make an overlay with the light.
MC of light->set to overlay
MC of Car->set to normal (duh)

truimagz
05-08-2007, 07:40 AM
well with an asteroid type game id try to avoid alpha's as you should with any game but especially an asteroid game, alphas can really slow down the game, and in asteroids your dealing with possiblility of tons of mc on the screen at once already.

As to file size due to using frames for rotation, I wouldnt worry about it, if you use 1 asteroid you can vectorize it and just use the same one for every single asteroid just use a tint or brightness even contrast to change how they look, so really your only file size will be your ship.

I would assume you could make a great asteroid game under 215k

truimagz
05-12-2007, 01:21 AM
I hope all is going well with your game.

Here are some animated assests you can use for your game, they are ment for a sidescroller but maybie they will come in handy.

http://www.creativededication.com/forum/viewtopic.php?t=22