PDA

View Full Version : I need help with coding for a game I'm making



Smeegel
November 17th, 2005, 05:44 PM
I'm creating a game with two ships that fly around trying to shoot one another. It is two player with one ship using One ship uses the arrow keys to fly, that one works. The other, which uses the "A", "W", "S", and "D" does not work.

Here is the code for the ship that uses the arrow keys:

ship2.onEnterFrame = function() {
Key.isDown(Key.UP) ? (this.speed = +7.5) : Key.isDown(Key.DOWN) ? (this.speed = -3.75) : null;
Key.isDown(Key.LEFT) ? this._rotation -= 12.5 : Key.isDown(Key.RIGHT) ? this._rotation += 12.5 : null;
this._x<=0 ? this._x=1100 : this._x>=1100 ? this._x=0 : null;
this._y<=0 ? this._y=800 : this._y>=800 ? this._y=0 : null;
this.speed *= .94, this.roto=this._rotation*(Math.PI/180);
this._x += Math.sin(this.roto)*this.speed;
this._y -= Math.cos(this.roto)*this.speed;
updateAfterEvent();
};

This is the code for the A,S,W,D ship:

ship1.onEnterFrame = function() {
Key.isDown(Key.119) ? (this.speed = +12.5) : Key.isDown(Key.115) ? (this.speed = -6.25) : null;
Key.isDown(Key.97) ? this._rotation -= 7.5 : Key.isDown(Key.100) ? this._rotation += 7.5 : null;
this._x<=0 ? this._x=1100 : this._x>=1100 ? this._x=0 : null;
this._y<=0 ? this._y=800 : this._y>=800 ? this._y=0 : null;
this.speed *= .94, this.roto=this._rotation*(Math.PI/180);
this._x += Math.sin(this.roto)*this.speed;
this._y -= Math.cos(this.roto)*this.speed;
updateAfterEvent();
};

I believe the numbers are the correct ascii numbers, but I am unsure. Any help you could offer will be greatly appreciated.

Thank you!

colombianking
November 17th, 2005, 09:46 PM
first you should put actionscript in the code form also
i dont know if those key numbers are good
i check them with nathans checker thing that he made
http://www.kirupa.com/forum/attachment.php?attachmentid=29630

nathan99
November 17th, 2005, 10:44 PM
:te:

nathan99
November 17th, 2005, 10:54 PM
ship1.onEnterFrame = function() {
Key.isDown(87) ? (this.speed=+7.5) : Key.isDown(83) ? (this.speed=-3.75) : null;
Key.isDown(65) ? this._rotation -= 12.5 : Key.isDown(68) ? this._rotation += 12.5 : null;
this._x<=0 ? this._x=1100 : this._x>=1100 ? this._x=0 : null;
this._y<=0 ? this._y=800 : this._y>=800 ? this._y=0 : null;
this.speed *= .94, this.roto=this._rotation*(Math.PI/180);
this._x += Math.sin(this.roto)*this.speed;
this._y -= Math.cos(this.roto)*this.speed;
updateAfterEvent();
};

rhamej
November 17th, 2005, 10:57 PM
first you should put actionscript in the code form also
i dont know if those key numbers are good
i check them with nathans checker thing that he made
http://www.kirupa.com/forum/attachment.php?attachmentid=29630
Whoa, thats cool nathan. How did I ever miss that thread. Great job! :thumb: