Forums

ForumsProgramming Forum

A Games Special Features Programming Code (AS3)

Posted Mar 25, '14 at 2:05pm

HouseHero

HouseHero

5 posts

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

 

Posted Mar 25, '14 at 2:47pm

mightybob

mightybob

353 posts

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

 

Posted Mar 25, '14 at 3:05pm

weirdlike

weirdlike

624 posts

Knight

@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.

 

Posted Apr 18, '14 at 11:07am

HouseHero

HouseHero

5 posts

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

 

Posted Apr 18, '14 at 12:34pm

weirdlike

weirdlike

624 posts

Knight

//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

 

Posted Apr 18, '14 at 12:53pm

weirdlike

weirdlike

624 posts

Knight

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

 
Reply to A Games Special Features Programming Code (AS3)

You must be logged in to post a reply!