public void Init() { stopwatch.Start(); lastTime = stopwatch.ElapsedMilliseconds; string tankTexture = "../Images/tankGreen.png"; string gunTexture = "../Images/barrelGreen.png"; tankSprite.Load(tankTexture); tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // sprite is facing the wrong way... fix that here // tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // sets an offset for the base, so it rotates around the centre tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f); turretSprite.Load(gunTexture); // turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // set the turret offset from the tank base turretSprite.SetPosition(0, turretSprite.Width / 2.0f); // set up the scene object hierarchy - parent the turret to the base, // then the base to the tank sceneObject turretObject.AddChild(turretSprite); tankObject.AddChild(tankSprite); tankObject.AddChild(turretObject); // having an empty object for the tank parent means we can set the // position/rotation of the tank without // affecting the offset of the base sprite tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f); }
public void Init() { stopwatch.Start(); lastTime = stopwatch.ElapsedMilliseconds; //tank tankSprite.Load("tankBlue_outline.png"); tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f); //turrent turretSprite.Load("barrelBlue.png"); turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); turretSprite.SetPosition(0, turretSprite.Width / 2.0f); //bullet bulletSprite.Load("barrelBlue.png"); bulletSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); bulletSprite.SetPosition(0, bulletSprite.Width / 2.0f); turretObject.AddChild(turretSprite); tankObject.AddChild(tankSprite); tankObject.AddChild(turretObject); bulletObject.AddChild(bulletSprite); }
public void Init() { stopwatch.Start(); lastTime = stopwatch.ElapsedMilliseconds; // ---- SPRITE CREATION ---- // Tank sprite tankSprite.Load("tankBlue_outline.png"); // Loads tank image into tank sprite tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the tank tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f); // Sets an offset for the base, so it rotates around the centre // Turret sprite turretSprite.Load("barrelBlue.png"); // Loads turret image into turret sprite turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the turret turretSprite.SetPosition(0, turretSprite.Width / 2.0f); // Set the turret offset from the tank base // Bullet sprite bulletSprite.Load("bulletBlue.png"); // Loads bullet image into bullet sprite bulletSprite.SetRotate(90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the bullet bulletSprite.SetPosition(50, -6); // Sets an offset for the bullet // Smoke sprite smokeSprite.Load("smokeOrange0.png"); // Loads smoke image into smoke sprite smokeSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the smoke smokeSprite.SetPosition(-smokeSprite.Width / 2.0f, smokeSprite.Height / 2.0f); // Sets an offset for the smoke // Tree sprite treeSprite.Load("treeLarge.png"); // Loads tree image into tree sprite treeSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the tree treeSprite.SetPosition(-treeSprite.Width / 2.0f, treeSprite.Height / 2.0f); // Sets an offset for the tree // Oil sprite oilSprite.Load("oil.png"); // Loads oil image into oil sprite oilSprite.SetRotate(-90 * (float)(Math.PI / 180.0f)); // Sets the rotation of the tree oilSprite.SetPosition(-oilSprite.Width / 2.0f, oilSprite.Height / 2.0f); // Sets an offset for the oil // ---- SCENE HIERARCHY ---- oilObject.AddChild(oilSprite); // Attach oil sprite to the oil object treeObject.AddChild(treeSprite); // Attach tree sprite to the tree object smokeObject.AddChild(smokeSprite); // Attach smoke sprite to the smoke object bulletObject.AddChild(bulletSprite); // Attach bullet sprite to the bullet object turretObject.AddChild(turretSprite); // Attach turret sprite to the turret object tankObject.AddChild(tankSprite); // Attach tank sprite to the tank object tankObject.AddChild(turretObject); // Attach the turret to the tank as a child // ---- OBJECT POSITIONING ---- tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f); // Position tank in the middle of the screen bulletObject.SetPosition(-100, -100); // Position bullet outside the screen smokeObject.SetPosition(-100, -100); // Position smoke outside the screen treeObject.SetPosition(GetRandomValue(54, 216), GetRandomValue(49, 431)); // Position tree in a random spot oilObject.SetPosition(GetRandomValue(400, 590), GetRandomValue(50, 430)); // Position oil barrel in a random spot }
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(); }