Esempio n. 1
0
        //private SpriteBatch spriteBatch;
        public Scene(SpriteBatch spriteBatch, ContentManager content, Vector2 screenSize, Game1 game)
        {
            entities        = new List <Entity>();
            entitiesID      = new Dictionary <int, Entity>();
            deadEntities    = new List <Entity>();
            players         = new List <Player>();
            localPlayers    = new List <Player>();
            enemies         = new List <BaseEnemy>();
            worldObjects    = new List <WorldObject>();
            cargos          = new List <Cargo>();
            activeAbilities = new List <ActiveAbility>();
            camera          = new Camera(spriteBatch, screenSize, cargos, players, enemies, worldObjects, activeAbilities);
            this.game       = game;
            networkThread   = game.networkThread;
            //SoundCollection.Instance.LoadSounds(content);
            //textureCollection = new TextureCollection(content);
            //TextureCollection.Instance.loadTextures(content);
            collisionCheck = new CollisionCheck(cargos, players, enemies, worldObjects, activeAbilities);

            worldObjectHandling = new WorldObjectHandling(this, worldObjects);
            tilemap             = new Tilemap(1, content);

            //enemyAI = new EnemyAI(tilemap, enemies, cargo);
            enemyAI      = new EnemyAI(worldObjects, enemies, cargos);
            this.content = content;
        }
Esempio n. 2
0
 public override void Collide(Entity entity, EntityCategory entityCategory)
 {
     if (isExploded)
     {
         return;
     }
     Explosion();
     foreach (Entity entity1 in scene.entities)
     {
         if (entity1 == this)
         {
             continue;
         }
         if (CollisionCheck.CheckCollision(new RotRectangle(hitbox.RotationRad, hitbox.Center, new Vector2(120, 120)), entity1.Hitbox))
         {
             if (entity1.GetType() == typeof(Player) || entity1.GetType() == typeof(Cargo))
             {
                 entity1.TakeDamage(1);
             }
             else
             {
                 entity1.TakeDamage(damage);
             }
         }
     }
 }
Esempio n. 3
0
        private void Search(Vector2 position, float pathWidth, Vector2 target, List <Vector2> path)
        {
            if (path.Count > 5)
            {
                return;
            }

            Vector2 direction = target - position;
            float   angle     = Geometry.DegToRad(1);

            while (true)
            {
                float distance         = 0;
                int   collisionCount   = 0;
                float shortestDistance = 0;// int.MaxValue;
                foreach (WorldObject worldObject in worldObjects)
                {
                    if (CollisionCheck.CheckCollision(position, direction, pathWidth, worldObject.Hitbox))
                    {
                        distance = Vector2.Distance(position, worldObject.Hitbox.Center);
                        if (collisionCount == 0)
                        {
                            shortestDistance = distance;
                        }

                        if (distance < shortestDistance)
                        {
                            shortestDistance = distance;
                        }
                        collisionCount++;
                    }
                }
                if (collisionCount > 0)
                {
                    direction.Normalize();
                    direction *= shortestDistance;
                    direction  = Geometry.Rotate(direction, angle);
                    angle     *= -1.2f;
                    if (angle > Math.PI)
                    {
                        return;
                    }
                }
                else
                {
                    position += direction;
                    path.Add(position);
                    if (Vector2.Distance(position, target) < 10)
                    {
                        return;
                    }
                    Search(position, pathWidth, target, path);
                    return;
                }
            }
        }
Esempio n. 4
0
 private bool CheckCollisions(RotRectangle hitbox)
 {
     //if (worldObjects.Count == 0) return false;
     foreach (RotRectangle playerSpawnPosition in spawnPositons)
     {
         if (CollisionCheck.CheckCollision(hitbox, playerSpawnPosition))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
 private bool CheckCollisions(WorldObject worldObject1, List <WorldObject> worldObjects)
 {
     if (worldObjects.Count == 0)
     {
         return(false);
     }
     foreach (WorldObject worldObject in worldObjects)
     {
         if (worldObject.Equals(worldObject1))
         {
             continue;
         }
         if (CollisionCheck.CheckCollision(worldObject1.Hitbox, worldObject.Hitbox))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
 public void Reset()
 {
     entities        = new List <Entity>();
     entitiesID      = new Dictionary <int, Entity>();
     deadEntities    = new List <Entity>();
     players         = new List <Player>();
     enemies         = new List <BaseEnemy>();
     worldObjects    = new List <WorldObject>();
     cargos          = new List <Cargo>();
     activeAbilities = new List <ActiveAbility>();
     collisionCheck  = new CollisionCheck(cargos, players, enemies, worldObjects, activeAbilities);
     camera.Reset(cargos, players, enemies, worldObjects, activeAbilities);
     if (!StateMachine.Instance.networkGame || networkThread.isMainClient)
     {
         worldObjectHandling = new WorldObjectHandling(this, worldObjects);
     }
     tilemap = new Tilemap(1, content);
     //enemyAI = new EnemyAI(tilemap, enemies, cargo);
     enemyAI = new EnemyAI(worldObjects, enemies, cargos);
 }