Game play controls...
Hey all!
I'm creating a real basic Flash shooter game where objects/enemies are flying by at the top of the screen and a soldier is at the bottom of the screen trying to shoot them down. I've got some code from a sample game but I need to change one thing.
The first line of code (onMouseDown...), I would like to change it to when the spacebar is pushed it will shoot the bullet (interceptor), not on the mouse press. I've tried a few different things with "if" statements and "keypress" stuff but no luck. Here is that part of the code:
-----------------------
onMouseDown = function () {
this.attachMovie('interceptor', 'interceptor'+totalobjects, this.getNextHighestDepth());
eval('interceptor'+totalobjects)._x = soldier._x;
eval('interceptor'+totalobjects)._y = soldier._y-20;
eval('interceptor'+totalobjects).xvel = 13*(_xmouse-soldier._x)/(Math.abs(_xmouse-soldier._x)+Math.abs(_ymouse-soldier._y));
eval('interceptor'+totalobjects).yvel = 13*(_ymouse-soldier._y)/(Math.abs(_xmouse-soldier._x)+Math.abs(_ymouse-soldier._y));
eval('interceptor'+totalobjects).onEnterFrame = function() {
this._x += this.xvel;
this._y += this.yvel;
enemyCollision(this._name);
if (this._x<0 || this._x>Stage.width || this._y<0 || this._y>Stage.height) {
removeMovieClip(this);
}
};
totalobjects++;
};
-----------------------
I'm sure I'm making this harder than it has to be. Any ideas?