Пример #1
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);
        }
Пример #2
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;
        }
Пример #3
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);
     }
 }
Пример #4
0
        //remove objects within blast areas
        public void bombExplosion(BombObject bombObj)
        {
            int xcoord = (int)((bombObj.getPosition().X + bombObj.getTexture().Width / 2) / gridDimensions.X - 1);
            int ycoord = (int)(((bombObj.getPosition().Y + bombObj.getTexture().Height / 2) / gridDimensions.Y));

            //mapPathData[ycoord, xcoord] = -1;

            //loop through blast area
            for (int x = xcoord - 1; x < xcoord + 2; x++)
            {
                for (int y = ycoord - 1; y < ycoord + 2; y++)
                {
                    //loop through all the objects
                    for (int t = 0; t < MainGameClass.objects.Count; t++)
                    {
                        GameObject temp = MainGameClass.objects[t];
                        int        temp_x;
                        int        temp_y;

                        //checks if the object being examined is the player object due to the use of sprite sheets
                        if (!(temp is Player) && !(temp is EnemyObject))
                        {
                            temp_x = (int)((temp.getPosition().X + temp.getTexture().Width / 2) / gridDimensions.X);
                            temp_y = (int)((temp.getPosition().Y + temp.getTexture().Height / 2) / gridDimensions.Y);
                        }
                        else
                        {
                            temp_x = (int)(((temp.getPosition().X + (temp.getTexture().Width / temp.numberOfColumns) / 2) / gridDimensions.X));
                            temp_y = (int)((temp.getPosition().Y + (temp.getTexture().Height / temp.numberOfRows) / 2) / gridDimensions.Y);
                        }

                        //if within blast area
                        if (temp_x == x && temp_y == y)
                        {
                            if (!temp.Equals(bombObj) && temp is BombObject)
                            {
                                temp.setMarkedForDestruction(true);
                            }
                            else if (!temp.Equals(bombObj) && temp is EnemyObject)
                            {
                                ((EnemyObject)temp).healthLeft -= 40;
                                ((EnemyObject)temp).checkHealth(bombObj);
                            }
                            else if (!temp.Equals(bombObj) && temp is Player)
                            {
                                ((Player)temp).healthLeft -= 40;
                                ((Player)temp).checkHealth(bombObj);
                            }
                            else if (!temp.Equals(bombObj) && (temp is StationaryObject))
                            {
                                //checks if the block can be destroyed
                                if (((StationaryObject)temp).getState() == StationaryObject.PILLER.CAN_DESTROY)
                                {
                                    destructables.Remove((StationaryObject)temp);
                                    numberOfPointBlocks--;
                                    MainGameClass.objects.Remove(temp);
                                    temp.setMarkedForDestruction(true);

                                    //add points to player
                                    if (bombObj.source is Player)
                                    {
                                        ((Player)bombObj.source).score += 5;
                                        tempscores.Add(((Player)bombObj.source).playerID + ": +5");
                                    }
                                }
                            }
                            else if (!temp.Equals(bombObj))
                            {
                                MainGameClass.objects.Remove(temp);
                                temp.setMarkedForDestruction(true);

                                //add points to source
                                if (bombObj.source is Player)
                                {
                                    ((Player)bombObj.source).score += 5;
                                    tempscores.Add(((Player)bombObj.source).playerID + ": +5");
                                }
                            }
                        }
                    } //end loop through objects
                }     //end loop through rowa
            }         //end loop through columns
            bombObj.animationCanStart = true;   //indicates to bomb object that animation can start
        }