drumn4life0789
03-10-2008, 08:52 AM
Hello everyone. I am trying to create a little ball game right now in flash. I am kind of new to flash but have been looking at it for a while now that I am starting to understand the actionscript and things now.
Basically I am making a ball game where the ball has gravity on it. you move it with the arrow keys and such, it has gravity and all that. The point of the game is to get from point A to point B.
Well the main problem I have right now in my code is that when i move my ball which i have named hero_mc in my code it is also moving my walls which I am going to set up a hittest function later.
here is my code
//---------------------------------------VARIABLES-----------------------------------\\
var power:Number = 0.65;
var xspeed:Number = 0;
var yspeed:Number = 0;
var friction:Number = .99;
var gravity:Number = 0.2;
var thrust:Number = .75;
//---------------------------------------VARIABLES-----------------------------------\\
//---------------------------------------FUNCTIONS-----------------------------------\\
function movement () {
if (Key.isDown(Key.LEFT)) {
xspeed-=power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed+=power;
}
if (Key.isDown(Key.UP)) {
yspeed-=power*thrust;
}
if (Key.isDown(Key.DOWN)) {
yspeed+=power*thrust;
}
xspeed *= friction;
yspeed += gravity;
_x += xspeed;
_y += yspeed;
}
//---------------------------------------FUNCTIONS-----------------------------------\\
hero_mc.onEnterFrame = function () {
movement();
}
I dont see why the hero on enterframe code is not only working for the hero. why is it moving my walls as well.
And I have all this placed in the first frame of the file. I like to keep all my actionscript in the maintimeline of the movie and not in alternate movie clip timelines. So any help would be most appreciated.
Basically I am making a ball game where the ball has gravity on it. you move it with the arrow keys and such, it has gravity and all that. The point of the game is to get from point A to point B.
Well the main problem I have right now in my code is that when i move my ball which i have named hero_mc in my code it is also moving my walls which I am going to set up a hittest function later.
here is my code
//---------------------------------------VARIABLES-----------------------------------\\
var power:Number = 0.65;
var xspeed:Number = 0;
var yspeed:Number = 0;
var friction:Number = .99;
var gravity:Number = 0.2;
var thrust:Number = .75;
//---------------------------------------VARIABLES-----------------------------------\\
//---------------------------------------FUNCTIONS-----------------------------------\\
function movement () {
if (Key.isDown(Key.LEFT)) {
xspeed-=power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed+=power;
}
if (Key.isDown(Key.UP)) {
yspeed-=power*thrust;
}
if (Key.isDown(Key.DOWN)) {
yspeed+=power*thrust;
}
xspeed *= friction;
yspeed += gravity;
_x += xspeed;
_y += yspeed;
}
//---------------------------------------FUNCTIONS-----------------------------------\\
hero_mc.onEnterFrame = function () {
movement();
}
I dont see why the hero on enterframe code is not only working for the hero. why is it moving my walls as well.
And I have all this placed in the first frame of the file. I like to keep all my actionscript in the maintimeline of the movie and not in alternate movie clip timelines. So any help would be most appreciated.