ForumsProgramming ForumA Games Special Features Programming Code (AS3)

5 7448
HouseHero
offline
HouseHero
5 posts
Nomad

I really wondered How I can do it or That using AS3. Now I learnt at least some of it. I tried to create a game like "Learn to Fly" I at least created 30 - 40% of game. But I encountered with some problems. I did not understand the Special Speed Meters, fuel system, ramp height and length effect, And if altitude. These are the major problems. Help me

  • 5 Replies
mightybob
offline
mightybob
360 posts
Peasant

Almost everything in code for a game is either an if, or a function.

Think, if MovieClip.y returns as a number, we should be able to use it as such, right?

So to figure out your altitude, you might do...

var altitude:Number;

altitude = player.y;

stage.addEventListener(Event.ENTER_FRAME, frameLoop);

function frameLoop(event:Event):void
{
altitude = (player.y); //then you might do *2 or /2 if the number is too big or too small.
}

And for fuel you might do...

var fuel:Number = 100;
var fuelDecrease:Number = 5;
if (put your key code or something here)
{
fuel -= fuelDecrease;
}

hope this helps

weirdlike
offline
weirdlike
1,299 posts
Prince

@HouseHero the questions you are asking are too broad, work with one at a time until you solve the function then move on to the next

THIS LINK will get you started with angles and direction

PART 2 goes more in depth on the power added to shot and hitTest

once you understand how these basic things work you will be putting together games in no time.

HouseHero
offline
HouseHero
5 posts
Nomad

I know how to add and remove child. But how can I support multiple instances like I add a Child I want to make it shoot to other symbols. Can Anyone help me in AS3

weirdlike
offline
weirdlike
1,299 posts
Prince

//speed of bullet
var bulletSpeed:Number = = 10;

//distance to hero
var bulletX:Number = enemy.x - hero.x;
var bulletY:Number = enemy.y - hero.y;

//radian
var radians:Number = Math.atan2(bulletY, bulletX);

//angle 180 might need to be changed depending on the direction of the bullet MC
var angle:Number = radians * 180 / Math.PI;

//rotate bullet to angle

//new pos to hero
var newBulletX:Number = Math.cos(radians);
var newBulletY:Number = Math.sin(radians);

//move bullet * bullet speed
bullet.x -= newBulletX * bulletSpeed;
bullet.y -= newBulletY * bulletSpeed;

I just typed this and did not test, sample on request

weirdlike
offline
weirdlike
1,299 posts
Prince

oop forgot the bullet rotation...

//rotate bullet to angle
bullet.rotation = angle;

once you have figured out 1 enemy with bullet fire you can then implement this technique HERE

Showing 1-5 of 5