Example #1
0
        public override void Update(GameObj gameObj)
        {
            position = new Vector2(gameObj.GetPosition().X, gameObj.GetPosition().Y);
            if (isAttacking)
            {
                if (attackType == Pickup_Melee.AttackType.STAB)
                {
                    origin.X   = dimensions.X / 2;
                    swingAngle = angle;
                    if (stabDistance < MAXSTAB)
                    {
                        stabDistance += swingRate;
                    }
                    else
                    {
                        isAttacking = false;
                    }
                }
                else if (attackType == Pickup_Melee.AttackType.SWING)
                {
                    origin.X = 0;

                    if (rotation < MAXROTATION)
                    {
                        rotation += swingRate / 100;
                        if (swingingRight)
                        {
                            swingAngle = angle + rotation - (MAXROTATION / 2);
                        }
                        else if (!swingingRight)
                        {
                            swingAngle = angle - rotation + (MAXROTATION / 2);
                        }
                    }
                    else
                    {
                        angle       = 0.0f;
                        isAttacking = false;
                    }
                }
            }
            else
            {
                if (stabDistance > 0 && attackType == Pickup_Melee.AttackType.STAB)
                {
                    stabDistance -= swingRate;
                }
                else
                {
                    stabDistance = 0f;
                }
            }

            if (attackType == Pickup_Melee.AttackType.STAB)
            {
                position.X += (float)Math.Cos(angle) * stabDistance;
                position.Y += (float)Math.Sin(angle) * stabDistance;
            }
        }
Example #2
0
        public void AddObject(GameObj newObject)
        {
            int xPos = (int)Math.Round(newObject.GetPosition().X / tileMap.GetTileSize());
            int yPos = (int)Math.Round(newObject.GetPosition().Y / tileMap.GetTileSize());

            if (occupiedPlaces[xPos, yPos] == 0)
            {
                sceneObjects.Add(newObject);
                occupiedPlaces[xPos, yPos] = 1;
            }
            else
            {
                int checkWidth  = 1;
                int checkHeight = 1;
                while (occupiedPlaces[xPos, yPos] != 0)
                {
                    checkWidth  += 2;
                    checkHeight += 2;
                    if (xPos >= 1)
                    {
                        xPos--;
                    }
                    if (yPos >= 1)
                    {
                        yPos--;
                    }
                    for (int i = 0; i < checkWidth; i++)
                    {
                        for (int j = 0; j < checkHeight; j++)
                        {
                            if (occupiedPlaces[xPos + i, yPos + j] == 0)
                            {
                                xPos = xPos + i;
                                yPos = yPos + j;
                                break;
                            }
                        }
                        if (occupiedPlaces[xPos, yPos] == 0)
                        {
                            break;
                        }
                    }
                }
                newObject.SetXPosition(xPos * tileMap.GetTileSize());
                newObject.SetYPosition(yPos * tileMap.GetTileSize());
                sceneObjects.Add(newObject);
                occupiedPlaces[xPos, yPos] = 1;
            }
        }
Example #3
0
 public void RemoveObject(GameObj obj)
 {
     if (sceneObjects.Contains(obj))
     {
         occupiedPlaces[(int)(obj.GetPosition().X / tileMap.GetTileSize()), (int)(obj.GetPosition().Y / tileMap.GetTileSize())] = 0;
         sceneObjects.Remove(obj);
     }
 }
Example #4
0
 public override void Update(GameObj gameObj)
 {
     position = gameObj.GetPosition();
     for (int i = 0; i < bullets.Count; i++)
     {
         bullets[i].Update();
         if (bullets[i].canBeDestroyed)
         {
             bullets.Remove(bullets[i]);
         }
     }
     fireCount++;
 }
Example #5
0
 public virtual void Update(GameObj gameObj)
 {
     bounds = new Rectangle((int)gameObj.GetPosition().X, (int)gameObj.GetPosition().Y, (int)gameObj.GetDimensions().X, (int)gameObj.GetDimensions().Y);
 }