Esempio n. 1
0
        private cMonster getclosestMonsterColliding(IEnumerable <cMonster> possibleColliders, cBullet bul, Vector2f pos_by, float time)
        {
            // int index = -1;
            double   prevDist = Double.MaxValue;
            double   newDist  = 0.0;
            cMonster returner = null;

            foreach (var mon in possibleColliders)
            {
                if (mon.IsKilled)
                {
                    continue;
                }

                // order by distance to find the closest
                if (cSatCollision.checkAndResolve(bul, mon, time, false))
                {
                    newDist = AppMath.Vec2DistanceSqrt(mon.Bounds.center, pos_by);

                    if (newDist < prevDist)
                    {
                        prevDist = newDist;
                        returner = mon;
                    }
                }
            }

            return(returner);
        }
Esempio n. 2
0
        public void InitLevelEntites(cMapData level)
        {
            // this.monsters.Clear();
            // this.allEntities.RemoveAll((cGameObject g) => g is cMonster );

            TmxMap map = level.GetTmxMap();
            TmxList <TmxObject> entityList = map.ObjectGroups["Entities"].Objects;

            foreach (var tmxEntity in entityList)
            {
                cMonster monster = new cMonster(this.refScene, new Vector2f((float)tmxEntity.X, (float)tmxEntity.Y));
                this.AddMonster(monster);
            }
        }
Esempio n. 3
0
        public void checkBulletVsEntityCollisions(float step_time)
        {
            // List<cMonster> collisionMonsters = new List<cMonster>();
            var bullets = this.allEntities.OfType <cBullet>();

            foreach (var bullet in bullets)
            {
                Vector2f intersection = new Vector2f(0.0f, 0.0f);

                var collisionMonsters = this.getEntitiesNearby(bullet.Position).OfType <cMonster>(); //treeMonsters.GetEntitiesAtPos(bullets[b].Position);


                cMonster monster = getclosestMonsterColliding(collisionMonsters, bullet, bullet.Position, step_time);

                if (monster != null)
                {
                    cCollision.resolveMonsterVsBullet(monster, bullet, intersection);
                }
            }

            // TODO Player Vs Bullet
        }
Esempio n. 4
0
 public void AddMonster(cMonster m)
 {
     this.AddEntity(m);
 }