public Bullet(string name, MathsLibrary.Vector3 pos, float rotation, Game Gam) { //create the bullets sprite object SpriteObject sprite = new SpriteObject(); sprite.Load("..\\Images\\PNG\\Bullets\\bulletBeige_outline.png"); sprite.Name = name + "_Sprite"; sprite.SetPosition(sprite.Height - sprite.Height / 2, -10); sprite.SetRotate(90 * (float)(Math.PI / 180.0f)); //set the sprite object as a child of the bullet AddChild(sprite); //set the bullet position and rotation SetPosition(pos); SetRotate(rotation); Name = name; Game = Gam; ///add and set up the components //add the physics move component AddComponent(new PhysicsBody(this)); //set the move type of the physics move to non uniform (uses acceleration) (GetComponent(typeof(PhysicsBody)) as PhysicsBody).MoveType = PhysicsBody.PhysicsMoveType.NonUniform; //set the x velocity to 500 (GetComponent(typeof(PhysicsBody)) as PhysicsBody).Velocity = new Vector2(500, 0); //set the x acceleration to 10 (GetComponent(typeof(PhysicsBody)) as PhysicsBody).Acceleration = new Vector2(10, 0); //add a destroy timer with a 2 second timer AddComponent(new DestroyTimer(2f, this)); //add a collider set for AABB AddComponent(new Collider(Collider.CollisionType.AABB, this)); //set the bullet to destroy itself when it collides with another collider (GetComponent(typeof(Collider)) as Collider).DestroySelfOnCollision = true; (GetComponent(typeof(Collider)) as Collider).isTrigger = true; MakeSureCollisionComponentsAreLast(); }
public GameObject(string name, MathsLibrary.Vector3 pos, float rotation, string ImageAddress, Game Gam) { //create objects sprite object SpriteObject sprite = new SpriteObject(); sprite.Load(ImageAddress); sprite.Name = name + "_Sprite"; sprite.SetPosition(-sprite.Width / 2.0f, sprite.Height / 2.0f); sprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); //add the sprite object as a child AddChild(sprite); //set object position and rotaion SetPosition(pos); SetRotate(rotation); Name = name; game = Gam; }
//set up tank public Tank(string name, Vector2 pos, float rotation, string Colour, Game Gam) { //Create and set up tanks sprite object SpriteObject sprite = new SpriteObject(); sprite.Load("..\\Images\\PNG\\Tanks\\tank" + Colour + "_outline.png"); sprite.Name = name + "_Sprite"; sprite.SetPosition(-sprite.Width / 2.0f, sprite.Height / 2.0f); sprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); AddChild(sprite); //Create tank turret object tankTurret = new GameObject(); //set up Turrets Sprite object SpriteObject turretSprite = new SpriteObject(); turretSprite.Load("..\\Images\\PNG\\Tanks\\barrel" + Colour + "_outline.png"); turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); turretSprite.SetPosition(0, turretSprite.Width / 2f); turretSprite.Name = "TurretSprite"; //add the turret sprite to the tankturret object tankTurret.AddChild(turretSprite); //add tank turret to the tank as a child AddChild(tankTurret); //set position and rotation of the tank SetPosition(pos); SetRotate(rotation); Name = name; Game = Gam; //add a collider AddComponent(new Collider(Collider.CollisionType.Circle, this)); //add the physics move component AddComponent(new PhysicsBody(this)); MakeSureCollisionComponentsAreLast(); }