Forum Topic: Sample Code

(430 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

PhantomGames

Reply To Post Reply & Quote

Posted at: 1/7/03 08:01 PM

PhantomGames NEUTRAL LEVEL 07

Sign-Up: 10/31/02

Posts: 13

Game Programming is VERY mathematical if you haven't fugured that out yet. Check this out, this is the movement program for my enemies in "Space Gunner":

hp = 2;
spd = 17;
pow = 5;
typ = 4;
life = true;

//get random x y values
var j = random(4) + 1;
switch (j) {
case 1 :
//left edge
x = 0;
y = random(601);
break;
case 2 :
//right edge
x = 800;
y = random(601);
break;
case 3 :
//top edge
y = 0;
x = random(801);
break;
case 4 :
//bottom edge
y = 600;
x = random(801);
break;
default :
x = 0;
y = 0;
break;
}

this._x = x;
this._y = y;
//find the angle from point to (400,300)
r = Math.atan2(x-400,y-300);
a = (180/Math.PI)*r + 90;
this._rotation = a;
//find the x y increment
xi = -Math.sin(r);
yi = -Math.cos(r);

count = 0;
function special () {
//agility
count += 1;
agility = Math.sin(count/2) * spd;
ar = Math.atan2(x-400, y-300) + (Math.PI/2);
axi = -Math.sin(ar);
ayi = -Math.cos(ar);
x += agility * axi;
y += agility * ayi;
}

function incr() {
// find the angle from point to (400,300)
r = Math.atan2(x-400, y-300);
a = (180/Math.PI)*r;
this._rotation = -a + 180;
// find the x y increment
xi = -Math.sin(r);
yi = -Math.cos(r);

if (hp<=0) {
this.gotoandplay("exp");
}

d = Math.sqrt((y-300) * (y-300)+(x-400) * (x-400)) - (this._height/2);
if (d <= 50) {
//if (this.hitTest(_root.boundary)) {
_root.hp -= pow;
this.gotoandplay("exp")
}

x += (xi*(spd*10))/18;
y += (yi*(spd*10))/18;

special();

this._x = x;
this._y = y;
}


None

omega10mg

Reply To Post Reply & Quote

Posted at: 1/9/03 04:24 PM

omega10mg NEUTRAL LEVEL 11

Sign-Up: 01/17/02

Posts: 164

wow.. great.. u seem to understand this kinda good.. i'm trying to learn.. but there's two thing that bugs me and i just cant find a good way for it..
number one.. is how to creat a good working damage meter?
and second.. how to make something explode or die without having to jump to another frame like 50 frame away...where i put the explotion animation..
is there a way to swap the symbols when u click something even if they are moving..

like if i make a ball and movies it around as a buttom.. i animat the movment... and when i click it want another movie symbol to replace it how?


None

MetaphorcE

Reply To Post Reply & Quote

Posted at: 1/10/03 09:10 AM

MetaphorcE NEUTRAL LEVEL 29

Sign-Up: 01/28/02

Posts: 2,036

look at my post about sphere equations and see if you can help me out... circle maths is where i got lost in high school... no not pi sin, cos, etc. but circle equtions... like I knew quadratic equations fine... (anyone care? nup, didn't think so)


None

JudgeDredd

Reply To Post Reply & Quote

Posted at: 1/11/03 08:13 AM

JudgeDredd EVIL LEVEL 37

Sign-Up: 08/18/01

Posts: 3,428

At 1/9/03 04:24 PM, omega10mg wrote:
like if i make a ball and movies it around as a buttom.. i animat the movment... and when i click it want another movie symbol to replace it how?

the main timeline is where you make an animated movie. When you want sprite swapping or buttons then you make movieclip objects. Buttons have code directly on the button, but other movieclips can be "double clicked" so as to enter each movieclips personal timeline (which also starts frame 1, frame 2, etc) and you can also layer movieclips (movieclips inside buttons, movieclips inside other movieclips, buttons inside movieclips).

Make a ball, then "convert to symbol -> movieclip", doubleclick the ball object to enter the balls new timeline and put a STOP(); action on the first frame. Frame 2 onwards can be some new design or animation (can be many frames long) and at the end put another STOP(); action. Finally go back to the main timeline (by doubleclicking on the stage) and "convert to symbol -> button" the new ball object. This will make a movieclip within a button. Now put PRESS or RELEASE code on the button itself (right click the button to bring up menu -> ACTIONS) and tell the ball to GOTOANDPLAY(2).. to animate the ball or explosion.

NOW, everything i've said is easy except for 1 thing. Calling movieclips within buttons is very advanced coding (but not impossible). So instead, make a ball, "convert to symbol -> button" first, then convert this button to a movieclip second. This way you have a button inside a movieclip - WHICH IS 10x EASIER TO CODE! ..and remember to name the movieclip!! ;O)_*


All times are Eastern Standard Time (GMT -5) | Current Time: 12:40 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!