How to setup bullet factory/bullet switch for the same player object?
Hi guys,
I'm currently making my own shoot'em up game where the player can switch between two player types which will fire their own bullet type in this case, squares and circles. I've setup the player switch function via pressing "space" button (switching between the two player types) and the default bullet type is "squares" and I'm not sure to approach the coding with changing the bullet type to "circles".
I've written 2 classes for the bullet and player setup:Player Class: Creates instance of bullet on screen and enables the switch player type function
Bullet Class: Enables bullet properies and bullet types
Player Class:
function onKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == 32) //// pressing/holding "space bar" to function
{
{
this.gotoAndStop(3); ///changing to other player type via frame 3
}
}
private function onKeyUp(event:KeyboardEvent):void //// letting go of "space bar" returns to default player type - frame 1
{
if (event.keyCode == 32)
{
this.gotoAndStop(1);
}
private function shootBullet():void
{
//Create bullet instance and add it to the stage
var bullet:Bullet = new Bullet(bullet_Vx, bullet_Vy, bullet_StartX, bullet_StartY, "square");
parent.addChild(bullet);
}
public function Bullet(vx:Number, vy:Number, startX:Number, startY:Number, bulletType:String)
{
//Assign velocity and start position using values
//supplied to the parameters
this._vx = vx;
this._vy = vy;
this.x = startX;
this.y = startY;
//Find bullet type
switch (bulletType) /// Declaring the bullet types
{
case "square" :
gotoAndStop(SQUARE);
break;
case "circle" :
gotoAndStop(CIRCLE);
break;
}
Thanks
Jonesy
