/// <summary>
        /// Update this instance.  Called once per frame.
        /// </summary>
        public void Update()
        {
            if (!this.IsActiveOnGrid())
            {
                return;
            }

            var myself = this;

            if (this.Genome.DNA.Execute(ref myself) == 0)
            {
                // If no action taken, kill ent
                this.TakeDamage(this.HealthValue);
            }
            else
            {
                this.TakeDamage(StaticController.GlobalEnviornmentDamagePerTurn);
            }

            if (!StaticController.GlobalForceFlat)
            {
                float healthPercent =
                    GameObjectGrid.GetHealthInRegion(GameObjectGrid.WorldToGridPosition(this.transform.position), StaticController.GlobalHeightBlendDistance) /
                    (float)StaticController.GlobalMaxInt;

                float yScale = healthPercent * StaticController.GlobalMaxHeight;

                this.transform.localScale =
                    new Vector3(
                        this.transform.localScale.x,
                        yScale,
                        this.transform.localScale.z);
            }
        }
Example #2
0
 public Bolt(int scale, GameObject wielder, GameObject target, float damage, GameObjectGrid grid) : base("spr_Bolt", scale, wielder, target, damage, 6)
 {
     //Grid is needed for wall collision
     this.grid = grid;
     Reset();
     cooldown = 0;
 }
Example #3
0
        private bool TryAttack(GeneticGridDirection direction)
        {
            GridPosition myPosition     = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition victimPosition = myPosition.GetPositionInDirection(direction.Value);

            if (!GameObjectGrid.PositionIsAlive(victimPosition))
            {
                return(false);
            }

            GameObject         victim        = GameObjectGrid.GetObjectAt(victimPosition);
            EntBehaviorManager victimManager = victim.GetComponent <EntBehaviorManager>();

            int damage = (this.AttackStrength.Value * this.Health.Value) / InitialHealth;

            victimManager.TakeDamage(damage);

            // Will succeed if we killed the victim
            if (this.TryMove(direction))
            {
                this.TryAddHealth(victimManager.GrowFoodStrength.Value);
            }

            if (this.AttackStrength.Value < StaticController.GlobalMaxInt)
            {
                ++this.AttackStrength.Value;
            }

            if (this.GrowFoodStrength.Value > 1)
            {
                --this.GrowFoodStrength.Value;
            }

            return(true);
        }
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>A string that represents the current object.</returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return(string.Format(
                "[Ent: TeamName={0} {1}]",
                this.TeamName,
                GameObjectGrid.WorldToGridPosition(this.transform.position)));
 }
    /// <summary>
    /// Collision checker for the Penguin
    /// </summary>
    public void CheckCollision()
    {
        //Take the grid to check for all tiles that are solid or doors, and player list for collision with players
        GameObjectGrid field   = GameWorld.Find("TileField") as GameObjectGrid;
        GameObjectList players = GameWorld.Find("playerLIST") as GameObjectList;

        Rectangle tileBoundingBox = new Rectangle((int)this.BoundingBox.X, (int)(this.BoundingBox.Y + 0.75 * Height), this.Width, (int)(this.Height / 4));

        //First check if monster collides with player
        foreach (Character player in players.Children)
        {
            if (this.BoundingBox.Intersects(player.BoundingBox) && !playersHit.Contains(player))
            {
                AttackHit(player);
            }
        }

        //Then check if monster collides with solid tile
        foreach (Tile tile in field.Objects)
        {
            if (tile.IsSolid && tileBoundingBox.Intersects(tile.BoundingBox))
            {
                movementVector = new Vector2(0, 0);
                Position       = previousPos;
                idleCounter    = 3;
                // TargetRandomObject (currently removed but might add back later, but as a local method?
            }
        }
    }
    /// <summary>
    /// Update each GameObject in the GameObjectGrid
    /// </summary>
    /// <param name="gameTime">The object used for reacting to timechanges</param>
    public override void Update(GameTime gameTime)
    {
        foreach (GameObject obj in gameObjects)
        {
            if (obj is GameObjectGrid)
            {
                GameObjectGrid gameObjectGrid = obj as GameObjectGrid;
                foreach (GameObject gameObject in gameObjectGrid.Objects)
                {
                    if (gameObject != null)
                    {
                        gameObject.Update(gameTime);
                        if (gameObject is ExitTile)
                        {
                            ExitTile exitTile = gameObject as ExitTile;
                            if (exitTile.isOnTile)
                            {
                                isOnExit = true;
                            }
                        }
                    }
                }
            }
            else
            {
                obj.Update(gameTime);
            }
        }

        exitText.Position    = new Vector2((GameEnvironment.Screen.X - 300) / 2, 0);
        noteText.Position    = new Vector2((GameEnvironment.Screen.X - 300) / 2, 30);
        roomCounter.Position = new Vector2(GameEnvironment.Screen.X - 60, 10);
    }
Example #7
0
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
            rowDeletionOffsetVector = new Vector3Int(WallsTilemap.cellBounds.xMin, WallsTilemap.cellBounds.yMax - rowDeletionOffset, 0);
            rowCreationOffsetVector = new Vector3Int(WallsTilemap.cellBounds.xMin, WallsTilemap.cellBounds.yMin - rowCreationOffset, 0);

            tileMapsToClear = new Tilemap[]
            {
                WallsTilemap,
                UpBlockersTilemap,
                DownBlockersTilemap,
                DotsTilemap,
                HorizontalPortalsTilemap,
                GhostSlowersTilemap
            };

            int numRows = WallsTilemap.cellBounds.yMax - WallsTilemap.cellBounds.yMin;
            int numCols = WallsTilemap.cellBounds.xMax - WallsTilemap.cellBounds.xMin;

            ObjectGrid = new GameObjectGrid(numRows, numCols);
            ObjectGrid.AddGameObject(2, 1, GameObject.Find("power_pill_tl"));
            ObjectGrid.AddGameObject(2, 19, GameObject.Find("power_pill_tr"));
            ObjectGrid.AddGameObject(18, 1, GameObject.Find("power_pill_bl"));
            ObjectGrid.AddGameObject(18, 19, GameObject.Find("power_pill_br"));
        }
    }
Example #8
0
 private bool TryMove(GeneticGridDirection direction)
 {
     return(GameObjectGrid.TryMoveObject(
                this.TeamName,
                TeamManager.GetTeamColor(this.TeamName),
                GameObjectGrid.WorldToGridPosition(this.transform.position),
                direction.Value));
 }
 private byte TryMove(byte direction)
 {
     return(GameObjectGrid.TryMoveObject(
                this.TeamName,
                TeamManager.GetTeamColor(this.TeamName),
                GameObjectGrid.WorldToGridPosition(this.transform.position),
                direction));
 }
 // This is the base attack method of the weapon,, which will be also defined as an ability
 public virtual void Attack(GameObjectList monsterList, GameObjectGrid field)
 {
     monsterObjectList = monsterList;
     fieldList         = field;
     BasicAttack.Use();
     idAnimation = idBaseAA;
     AnimationAttackCheck();
 }
 public override void AttackHit(Monster monster, GameObjectGrid field)
 {
     fieldGrid = field;
     if (!MonsterHit.Contains(monster) && monster.Attributes.HP > 0 && MonsterHit.Count == 0)
     {
         monster.TakeDamage(DamageAA);
         MonsterAdd(monster, Owner.Mirror);
     }
 }
Example #12
0
    //Method that opens all the affected objects
    public void ActivateCorrObject(string action)
    {
        //Checks which objects has the same objectnumber as this handlenumber and opens or closes the corresponding objects.
        //give "open" to open the corresponding object. Give "close" to close the corresponding object.

        GameObjectGrid tileField = GameWorld.Find("TileField") as GameObjectGrid;
        GameObjectList objects   = GameWorld.Find("objectLIST") as GameObjectList;

        foreach (var openableObject in tileField.Objects)
        {
            if (openableObject is OpenableObject)
            {
                if (this.ObjectNumberConnected == 99)
                {
                    ((OpenableObject)openableObject).Open();
                    continue;
                }
                if (((OpenableObject)openableObject).Objectnumber == handlenumber)
                {
                    if (action == "open")
                    {
                        ((OpenableObject)openableObject).Open();
                    }

                    if (action == "close")
                    {
                        ((OpenableObject)openableObject).Close();
                    }
                }
            }
        }

        foreach (var openableObject in objects.Children)
        {
            if (openableObject is OpenableObject)
            {
                if (this.ObjectNumberConnected == 99)
                {
                    ((OpenableObject)openableObject).Open();
                    continue;
                }
                if (((OpenableObject)openableObject).Objectnumber == handlenumber)
                {
                    if (action == "open")
                    {
                        ((OpenableObject)openableObject).Open();
                    }

                    if (action == "close")
                    {
                        ((OpenableObject)openableObject).Close();
                    }
                }
            }
        }
    }
Example #13
0
        protected void StopMoving()
        {
            GameObjectGrid tileField = GameWorld.Find("tileField") as GameObjectGrid;

            Velocity = Vector2.Normalize(Velocity);
            Vector2 oldBlock = new Vector2(GetCurrentBlock().X, GetCurrentBlock().Y) - Velocity;

            Position = oldBlock * new Vector2(tileField.CellWidth, tileField.CellHeight);
            Velocity = Vector2.Zero;
        }
 /// <summary>
 /// Takes the damage.
 /// </summary>
 /// <param name="amount">Amount.</param>
 public void TakeDamage(byte amount)
 {
     if (amount >= this.Health)
     {
         GameObjectGrid.KillObject(this.gameObject);
     }
     else
     {
         this.Health = (byte)(this.Health - amount);
     }
 }
    /// <summary>
    /// Method that defines what happens when a monster gets hit
    /// </summary>
    /// <param name="monster">The affected monster</param>
    /// <param name="field">The tileField of the level</param>
    public virtual void AttackHit(Monster monster, GameObjectGrid field)
    {
        fieldGrid = field;

        //Only affects the monster if it has not been affected by the ability already
        if (!MonsterHit.Contains(monster) && monster.Attributes.HP > 0)
        {
            monster.TakeDamage(DamageAA);
            MonsterAdd(monster, Owner.Mirror);
        }
    }
 // Uses the main ability
 public virtual void UseMainAbility(GameObjectList monsterList, GameObjectGrid field)
 {
     if (!mainAbility.IsOnCooldown)
     {
         mainAbility.Use();
         idAnimation       = idMainAbility;
         monsterObjectList = monsterList;
         fieldList         = field;
         AnimationMainCheck();
     }
 }
        private byte TryReproduce(byte direction)
        {
            GridPosition myPosition    = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition childPosition = myPosition.GetPositionInDirection(direction);

            return(GameObjectGrid.TryReviveObjectAt(
                       this.TeamName,
                       TeamManager.GetTeamColor(this.TeamName),
                       childPosition,
                       false));
        }
Example #18
0
        private GeneticBool DirectionIsOccupied(GeneticGridDirection direction)
        {
            GridPosition currentPosition = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition testPosition    = currentPosition.GetPositionInDirection(direction.Value);

            if (GameObjectGrid.PositionIsAlive(testPosition))
            {
                return(GeneticBool.True);
            }

            return(GeneticBool.False);
        }
Example #19
0
        /// <summary>
        /// Tries the create and place new ent.
        /// </summary>
        /// <returns><c>true</c>, if create and place new ent was tryed, <c>false</c> otherwise.</returns>
        /// <param name="template">Template.</param>
        /// <param name="position">Position.</param>
        /// <param name="teamName">Team name.</param>
        /// <param name="forcePlace">If set to <c>true</c> force place.</param>
        public static bool TryCreateAndPlaceNewEnt(
            Color color,
            GridPosition position,
            string teamName,
            bool forcePlace)
        {
            if (!GameObjectGrid.TryReviveObjectAt(teamName, color, position, forcePlace))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Tries the create and place new ent.
        /// </summary>
        /// <returns><c>true</c>, if create and place new ent was tryed, <c>false</c> otherwise.</returns>
        /// <param name="template">Template.</param>
        /// <param name="position">Position.</param>
        /// <param name="teamName">Team name.</param>
        /// <param name="forcePlace">If set to <c>true</c> force place.</param>
        public static byte TryCreateAndPlaceNewEnt(
            Color color,
            GridPosition position,
            string teamName,
            bool forcePlace)
        {
            if (GameObjectGrid.TryReviveObjectAt(teamName, color, position, forcePlace) == 0)
            {
                return(0);
            }

            return(1);
        }
Example #21
0
        public SpriteGameObject FindSharkAtPosition(Point p)
        {
            GameObjectGrid tileField     = GameWorld.Find("tileField") as GameObjectGrid;
            Vector2        finalPosition = new Vector2(p.X * tileField.CellWidth, p.Y * tileField.CellHeight);

            foreach (SpriteGameObject s in sharks)
            {
                if (s.Position == finalPosition)
                {
                    return(s);
                }
            }
            return(null);
        }
        private byte DirectionIsOccupied(byte direction)
        {
            GridPosition currentPosition = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition testPosition    = currentPosition.GetPositionInDirection(direction);

            if (GameObjectGrid.PositionIsAlive(testPosition))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #23
0
    /// <summary>
    /// Checks whether a character collides with a tile
    /// </summary>
    /// <returns>whether the position the character is going is valid</returns>
    private bool SolidCollisionChecker()
    {
        GameObjectGrid Field = GameWorld.Find("TileField") as GameObjectGrid;
        // Define a quarter bounding box (the feet plus part of the legs) for isometric collision
        Rectangle quarterBoundingBox = new Rectangle((int)this.BoundingBox.X, (int)(this.BoundingBox.Y + 0.75 * Height), this.Width, (int)(this.Height / 4));

        foreach (Tile tile in Field.Objects)
        {
            if (tile.IsSolid && quarterBoundingBox.Intersects(tile.BoundingBox))
            {
                return(false);
            }
        }
        return(true);
    }
    public void openUnlockedDoor(Door openDoor)
    {
        GameObjectGrid tileField = GameWorld.Find("TileField") as GameObjectGrid;

        foreach (var door in tileField.Objects)
        {
            if (door is Door)
            {
                if (((Door)door).Objectnumber == openDoor.Objectnumber && openDoor.DoorOpen)
                {
                    ((Door)door).DoorOpen = true;
                }
            }
        }
    }
Example #25
0
        public Statsscreenbox(GameObjectGrid itemGrid2, int layer = 0, string id = "", float cameraSensitivity = 0) : base(layer, id)
        {
            itemGrid2.CellHeight = Tile.TileHeight;
            itemGrid2.CellWidth  = Tile.TileWidth;


            for (int x = 0; x < itemGrid2.Columns; x++)
            {
                for (int y = 0; y < itemGrid2.Rows; y++)
                {
                    ItemGrid2.Add(new ItemSlot(), x, y);
                }
            }
            Add(itemGrid2);
        }
Example #26
0
        public Point GetCurrentBlock()
        {
            GameObjectGrid tileField = GameWorld.Find("tileField") as GameObjectGrid;
            Point          p         = new Point((int)Math.Floor(Position.X / tileField.CellWidth), (int)Math.Floor(Position.Y / tileField.CellHeight));

            if (Velocity.X > 0)
            {
                p.X++;
            }
            if (Velocity.Y > 0)
            {
                p.Y++;
            }
            return(p);
        }
Example #27
0
        public GameObjectGridState()
        {
            GOGrid = new GameObjectGrid(5, 5, 0);
            Add(GOGrid);
            GOGrid.CellHeight = 50;
            GOGrid.CellWidth  = 50;
            for (int i = 0; i < GOGrid.Rows; i++)
            {
                for (int x = 0; x < GOGrid.Columns; x++)
                {
                    GOGrid.Add(new SpriteGameObject("spr_player"), i, x);
                }
            }

            DH = new DrawingHelper();
        }
Example #28
0
    /// <summary>
    /// Checker that checks whether a character is on ice
    /// </summary>
    public bool IsOnIceChecker()
    {
        GameObjectGrid Field = GameWorld.Find("TileField") as GameObjectGrid;
        // Bounding box for only the feet
        Rectangle feetBoundingBox = new Rectangle((int)(this.BoundingBox.X + 0.33 * Width),
                                                  (int)(this.BoundingBox.Y + 0.9 * Height), (int)(this.Width / 3), (Height / 10));

        foreach (Tile tile in Field.Objects)
        {
            if (tile.Type == TileType.Ice && tile.BoundingBox.Intersects(feetBoundingBox))
            {
                return(true);
            }
        }
        blockinput = false;
        return(false);
    }
        void FixedUpdate()
        {
            bool forceEarlyRefresh =
                GameObjectGrid.EveryoneIsDead() ||
                GameObjectGrid.GridIsMonoChromatic();

            if (frameCounter >= this.FramesPerIteration || forceEarlyRefresh)
            {
                lock (CommonHelperMethods.GlobalStateLock)
                {
                    // Everyone wins
                    GenePoolManager.RefreshTeamDNA();
                }

                this.frameCounter = 0;
            }
        }
Example #30
0
    /// <summary>
    /// Draws the GameObjects of the list
    /// </summary>
    /// <param name="gameTime">The object used for reacting to timechanges</param>
    /// <param name="spriteBatch">The SpriteBatch</param>
    public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
    {
        foreach (GameObject gameObject in gameObjects)
        {
            if (gameObject is Object3D)
            {
                Object3D gameObject3D = gameObject as Object3D;
                if (gameObject3D.Model != null)
                {
                    gameObject3D.DrawCamera(player);
                    gameObject3D.Draw(gameTime, spriteBatch);
                }
            }

            else if (gameObject is GameObjectGrid)
            {
                GameObjectGrid gameObjectGrid = gameObject as GameObjectGrid;
                foreach (GameObject obj in gameObjectGrid.Objects)
                {
                    if (obj is Object3D)
                    {
                        Object3D gameObject3D = obj as Object3D;
                        if (gameObject3D.Model != null)
                        {
                            gameObject3D.DrawCamera(player);
                            gameObject3D.Draw(gameTime, spriteBatch);
                        }
                    }
                }
            }
            else
            {
                gameObject.Draw(gameTime, spriteBatch);
            }
        }

        if (isOnExit && !NoteInVicinity)
        {
            exitText.Draw(gameTime, spriteBatch);
            isOnExit = false;
        }
        else if (NoteInVicinity)
        {
            noteText.Draw(gameTime, spriteBatch);
        }
    }
    private void DrawEndless(int part,GameTime gameTime, SpriteBatch spriteBatch)
    {
        level = new Level();
        level.player = new Player(new Vector3(200, 200f, 200));

        GameObjectGrid grid = new GameObjectGrid(20,20,"grid");

        for (int i = 0; i < grid.Rows; i++)
        {
            grid.Add(new WallTile("01"), 0, i);
            grid.Add(new WallTile("01"), 2, i);
            grid.Add(new PathTile("01"), 1, i);
        }

        for (int x = 0; x < grid.Objects.GetLength(0); x++)
        {
            for (int y = 0; y < grid.Objects.GetLength(1); y++)
            {
                if (grid.Objects[x, y] != null)
                {
                    grid.Objects[x, y].Position -= new Vector3(0, 0, GameObjectGrid.CellWidth * part / 60);
                    if (grid.Objects[x, y] is WallTile)
                    {
                        grid.Objects[x, y].Position += new Vector3(0, 200, 0);
                    }
                }
            }
        }

        level.Add(grid);

        level.Parent = this;

        foreach (GameObject obj in level.Objects)
        {
            obj.Parent = level;
        }
    }