Esempio n. 1
0
 public override void OnCollide(GameObject g)
 {
     if (g != parent)
     {
         Scene.RemoveObject(this);
     }
 }
Esempio n. 2
0
        //check if there is a collision between two gameGrid objects
        public bool isCollision(GameObject o1,GameObject o2)
        {
            if (checkBoundingBoxes(o1, o2))
                //if (checkPixelCollision(o1.getBoundingRectangle(), o1.getTextureData(), o2.getBoundingRectangle(), o2.getTextureData()))
                    return true;

            return false;
        }
Esempio n. 3
0
        public Bullet(Vector2 position, float rotation, GameObject parent)
            : base(position, new Vector2(10, 10), Assets.shot)
        {
            this.parent = parent;
            Rotation = rotation;

            Velocity = RotationVector * SPEED;
        }
Esempio n. 4
0
        //calc distance to target object from current object
        public double getDistanceTo(GameObject obj)
        {
            float a = obj.getPosition().X - this.position.X;
            float b = obj.getPosition().Y - this.position.Y;
            double distance = Math.Sqrt(a * a + b * b);

            return distance / 2;
        }
Esempio n. 5
0
        public BullitObject(Texture2D texture, int rows, int columns, int x, int y,GameObject source)
            : base(texture, rows, columns, x, y)
        {
            //defualt constructor
            lifeSpan = 50;
            speedFactor = 7;
            sourceObj = source;

            //sets direction of bullit
            direction = ((Player)source).getDirection();
        }
Esempio n. 6
0
        //do boundingbox test
        public bool checkBoundingBoxes(GameObject obj1,GameObject obj2)
        {
            //get bounding boxes
            Rectangle temp1 = obj1.getBoundingRectangle();
            Rectangle temp2 = obj2.getBoundingRectangle();

            //check collision
            if (temp1.Intersects(temp2))
                return true;
            else
                return false;
        }
Esempio n. 7
0
        //checks if object is dead
        public void checkHealth(GameObject obj)
        {
            //check if health is finished
            if (healthLeft <= 0)
            {
                this.setMarkedForDestruction(true);
                healthLeft = 0;

                //get points for destroying an enemy/player object
                if (obj is BombObject)
                {
                    BombObject bombObj = (BombObject)obj;
                    if (bombObj.source is Player)
                    {
                        if (bombObj.source.Equals(this))
                            GameMap.tempscores.Add(this.playerID + " committed suicide.");
                        else
                        {
                            ((Player)(bombObj).source).score += 15;
                            GameMap.tempscores.Add(((Player)bombObj.source).playerID + ": +15");//(killed an enemy with a bomb!)
                            GameMap.tempscores.Add(this.playerID + " was blown up.");
                        }
                    }
                }
                else if(obj is BullitObject)
                {
                    if (((BullitObject)obj).getSource()is Player)
                    {
                        Player temp = (Player)((BullitObject)obj).getSource();
                        temp.score += 10;
                        GameMap.tempscores.Add(temp.playerID + ": +10");//(killed an enemy with bulltis!)
                        GameMap.tempscores.Add(this.playerID + " was shot.");
                    }
                }
            }
        }
Esempio n. 8
0
 //for firing bullets
 public void fireBullet(GameObject source,float dir)
 {
     ((Player)source).cooldownTimer = 50;
     bulletObj = null;
     if (source is EnemyObject)
     {
         //calculate direction bullet should take realtive to source
         int xpos = (int)((source.getPosition().X) + Math.Sin(MathHelper.ToRadians(dir) *48) +10);
         int ypos = (int)((source.getPosition().Y) + Math.Cos(MathHelper.ToRadians(dir) *48) +20);
         bulletObj = new BullitObject(bulletTexture, 1, 1, xpos, ypos, source);
         objects.Add(bulletObj);
     }
     else if (source is Player)
     {
         //calculate direction bullet should take realtive to source
         int xpos = (int)((source.getPosition().X) + Math.Sin(MathHelper.ToRadians(dir) * 32) + 10);
         int ypos = (int)((source.getPosition().Y) + Math.Cos(MathHelper.ToRadians(dir) * 32) + 20);
         bulletObj = new BullitObject(bulletTexture, 1, 1, xpos, ypos, source);
         objects.Add(bulletObj);
     }
 }
Esempio n. 9
0
        //randomly select a different ground texture for each new game started
        private void loadGridTiles()
        {
            Texture2D gridTile;
            int rand = randomNumber.Next(1, 7);
            if (rand == 1)
                gridTile = gridTiles[0];
            else if (rand == 2)
                gridTile = gridTiles[1];
            else if (rand == 3)
                gridTile = gridTiles[2];
            else if (rand == 4)
                gridTile = gridTiles[3];
            else if (rand == 5)
                gridTile = gridTiles[4];
            else
                gridTile = gridTiles[5];

            gameGrid = new GameObject[gridWidth, gridHeight];
            for (int i = 0; i < gridWidth; i++)
            {
                for (int j = 0; j < gridHeight; j++)
                {
                    gameGrid[i, j] = new GameObject(gridTile, 1, 1, gridTile.Width * i, gridTile.Height * j);
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Автоматизированное добавление юнита
 /// </summary>
 /// <param name="obj">Вставляемый юнит, координата должна быть прописана в нем!!!</param>
 public static void AddUnit(GameObject obj)
 {
     Vector2 Pos = obj.Position;
     int X = (int)(Pos.X / 10 /Map.CellWidth);
     int Y = (int)(Pos.Y / 10/Map.CellHeight);
     Zmap[X, Y].sprites.Add(obj);
 }
 public virtual void OnCollide(GameObject g)
 {
 }
Esempio n. 12
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     Storage st = new Storage();
     st.Load(Content);
     level.Load(Content);
     camera = new Camera(this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight);
     GameObject T = new GameObject(this);
     T.Angle = 0f;
     T.Position = new Vector2(100, 100);
     T.Name = "Pedestrian";
     T.Scale = 1.0f;
     T.Load();
     Map.AddUnit(T);
     // TODO: use this.Content to load your game content here
 }