예제 #1
0
        private Vector2 CalculateActualCoordiantes(Block block)
        {
            int positionX = GridUtil.TransformPositionRelative(block.Bounds.CenterX, 0, gridSize);
            int positionY = GridUtil.TransformPositionRelative(block.Bounds.CenterY, 0, gridSize);

            return(new Vector2(positionX, positionY));
        }
예제 #2
0
        public void HandleCollisions(float updatePeriod)
        {
            player.ResolveCollision();

            foreach (Obstacle obstacle in obstacles.ToList())
            {
                obstacle.ResolveCollision();
            }

            foreach (Enemy enemy in enemies.ToList())
            {
                enemy.ResolveCollision();
            }

            foreach (Bomb bomb in bombs.ToList())
            {
                bomb.ResolveCollision();

                if (bomb.State == BombState.EXPLODE)
                {
                    timeDelta += updatePeriod;
                    if (timeDelta > 0.3f)
                    {
                        bombs.Remove(bomb);
                        int x = GridUtil.TransformPositionRelative(bomb.Bounds.CenterX, 0, modelView.gridSize);
                        int y = GridUtil.TransformPositionRelative(bomb.Bounds.CenterY, 0, modelView.gridSize);
                        bomb.Bounds.RemoveReferencedObject(modelView.Grid[x, y]);
                        timeDelta = 0;
                    }
                }
            }
        }
예제 #3
0
        private void HandleEnemyBombCollision(object sender, EventArgs args)
        {
            Enemy enemy = (Enemy)sender;

            if (enemy != null)
            {
                foreach (Bomb bomb in bombs)
                {
                    if (bomb.State == BombState.EXPLODE)
                    {
                        enemies.Remove((Enemy)enemy);
                        int x = GridUtil.TransformPositionRelative(enemy.Bounds.CenterX, 0, modelView.gridSize);
                        int y = GridUtil.TransformPositionRelative(enemy.Bounds.CenterY, 0, modelView.gridSize);
                        enemy.Bounds.RemoveReferencedObject(modelView.Grid[x, y]);
                        onEnemyDestroy?.Invoke(this, null);
                    }
                }
            }
        }
예제 #4
0
        private void HandleObstacleBombCollision(object sender, EventArgs args)
        {
            GameObject block = (GameObject)sender;

            foreach (Obstacle obstacle in obstacles.ToArray())
            {
                if (obstacle.Bounds.Equals(block.Bounds))
                {
                    foreach (Bomb bomb in bombs)
                    {
                        if (bomb.State == BombState.EXPLODE)
                        {
                            obstacles.Remove(obstacle);
                            int x = GridUtil.TransformPositionRelative(obstacle.Bounds.CenterX, 0, modelView.gridSize);
                            int y = GridUtil.TransformPositionRelative(obstacle.Bounds.CenterY, 0, modelView.gridSize);
                            obstacle.Bounds.RemoveReferencedObject(modelView.Grid[x, y]);
                        }
                    }
                }
            }
        }
예제 #5
0
 public void ExecuteAllElements(float updatePeriod)
 {
     player.Execute(updatePeriod);
     foreach (Enemy enemy in enemies)
     {
         enemy.Execute(updatePeriod);
     }
     foreach (Obstacle obstacle in obstacles)
     {
         obstacle.Execute(updatePeriod);
     }
     foreach (Bomb bomb in bombs)
     {
         bomb.Execute(updatePeriod);
     }
     if (!enemies.Any())
     {
         portal.setVisible();
         int x = GridUtil.TransformPositionRelative(portal.Bounds.CenterX, 0, modelView.gridSize);
         int y = GridUtil.TransformPositionRelative(portal.Bounds.CenterY, 0, modelView.gridSize);
         portal.Bounds.SetReferencedBlockVisible(modelView.Grid[x, y]);
     }
 }