Esempio n. 1
0
 public static void check(Entity ent, Player player)
 {
     if (ent.position.X + ent.texture.Width / 2  < player.position.X - player.imageDimension().X / 2 ||
         ent.position.Y + ent.texture.Height / 2 < player.position.Y - player.imageDimension().Y / 2 ||
         ent.position.X - ent.texture.Width / 2  > player.position.X + player.imageDimension().X / 2 ||
         ent.position.Y - ent.texture.Height / 2 > player.position.Y + player.imageDimension().Y / 2)
     {
         // No Collision
     }
     else
     {
         ent.doCollision(player);
         player.doCollision(ent);
     }
 }
Esempio n. 2
0
 public void checkPlayerCollisions(Player e)
 {
     foreach (Bullet b in bullets)
     {
         if ((b.shotBy is Entity))
         {
             if (b.position.X > e.position.X - e.imageDimension().X / 2 &&
                 b.position.X < e.position.X + e.imageDimension().X / 2 &&
                 b.position.Y > e.position.Y - e.imageDimension().Y / 2 &&
                 b.position.Y < e.position.Y + e.imageDimension().Y / 2)
             {
                 if (!e.shielding)
                     e.health -= 1;
                 b.alive = false;
             }
         }
     }
 }
Esempio n. 3
0
        public bool teleportCheck2(Player p, Vector2 result)
        {
            int xmin = (int)(result.X + 1 - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(result.X - 1 + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(result.Y + 1 - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(result.Y - 1 + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(result.X) / tileWidth;
            int y = (int)(result.Y) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                return false;
                //p.velocity.Y = 0;
            }

            if (m_tiles[x, ymax] != null)
            {
                return false;
                //p.jump = false;
            }
            else
            {
                //p.jump = true;
            }

            if (m_tiles[xmin, y] != null)
            {
                return false;
            }
            if (m_tiles[xmax, y] != null)
            {
                return false;
            }
            return true;
        }
Esempio n. 4
0
        public Vector2 teleportCheck(Player p, Vector2 displaced)
        {
            Vector2 result = p.position + displaced;
            int xmin = (int)(result.X - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(result.X + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(result.Y - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(result.Y + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(result.X) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                result.Y = ymax * tileWidth + p.imageDimension().Y / 2;
                //p.velocity.Y = 0;
            }

            if (m_tiles[x, ymax] != null)
            {
                result.Y = ymax * tileWidth - p.imageDimension().Y / 2;
                //p.jump = false;
            }
            else
            {
                //p.jump = true;
            }

            int y = (int)(result.Y) / tileWidth;

            if (m_tiles[xmin, y] != null)
            {
                result.X = (xmax) * tileWidth + p.imageDimension().X / 2;
            }
            if (m_tiles[xmax, y] != null)
            {
                result.X = xmax * tileWidth - p.imageDimension().X / 2;
            }
            if (teleportCheck2(p, result))
            {
                return result;
            }
            else
            {
                p.health = 0;
                return result;
            }
        }
Esempio n. 5
0
        public void checkPlayerCollisionRev(Player p)
        {
            int xmin = (int)(p.position.X - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(p.position.X + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(p.position.Y - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(p.position.Y + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(p.position.X) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                p.position.Y = ymax * tileWidth + p.imageDimension().Y / 2;
                p.jump = false;
                p.velocity.Y = 0;
                if (m_tiles[x, ymin].getType() == 1)
                {
                    p.health = 0;
                }
            }

            if (m_tiles[x, ymax] != null)
            {
                p.position.Y = ymax * tileWidth - p.imageDimension().Y / 2;
                p.velocity.Y = 0;
                if (m_tiles[x, ymax].getType() == 1)
                {
                    p.health = 0;
                }
            }
            else
            {
                p.jump = true;
            }

            int y = (int)(p.position.Y) / tileWidth;

            if (m_tiles[xmin, y] != null)
            {
                p.position.X = (xmax) * tileWidth + p.imageDimension().X / 2;
                if (m_tiles[xmin, y].getType() == 1)
                {
                    p.health = 0;
                }
            }
            if (m_tiles[xmax, y] != null)
            {
                p.position.X = xmax * tileWidth - p.imageDimension().X / 2;
                if (m_tiles[xmax, y].getType() == 1)
                {
                    p.health = 0;
                }
            }
        }
Esempio n. 6
0
 public override void doCollision(Player player)
 {
 }
Esempio n. 7
0
 public abstract void doCollision(Player player);
Esempio n. 8
0
        protected override void LoadContent()
        {
            gameFont = Game.Content.Load<SpriteFont>(@"logtext");
            background = Game.Content.Load<Texture2D>(@"backgrounds/chipbg");

            level = Game.Content.Load<Texture2D>(@"maps/HugeLevel");

            tileTextures = new Dictionary<Color, Texture2D[]>();
            tileTextures.Add(Color.Black, new Texture2D[]{
               Game.Content.Load<Texture2D>(@"images/tile1"),
               Game.Content.Load<Texture2D>(@"images/tile2"),
               Game.Content.Load<Texture2D>(@"images/tile3"),
            });
            tileTextures.Add(Color.Red, new Texture2D[]{
                Game.Content.Load<Texture2D>(@"images/spike1"),
                Game.Content.Load<Texture2D>(@"images/spike2"),
                Game.Content.Load<Texture2D>(@"images/spike3"),
            });

            entities = new Dictionary<Color, Entity>();
            entities.Add(new Color(0, 100, 100), new InfoPad(Vector2.One, PlayerPower.LOW_GRAV));                   // 0
            entities.Add(new Color(5, 100, 100), new InfoPad(Vector2.One, PlayerPower.MASSIVE_GRAV));               // 5
            entities.Add(new Color(10, 100, 100), new InfoPad(Vector2.One, PlayerPower.GRAVITY_NORMAL));            // 10
            entities.Add(new Color(15, 100, 100), new InfoPad(Vector2.One, PlayerPower.GRAVITY_OFF));               // 15
            entities.Add(new Color(20, 100, 100), new InfoPad(Vector2.One, PlayerPower.REV_GRAVITY));               // 20
            entities.Add(new Color(25, 100, 100), new InfoPad(Vector2.One, PlayerPower.WEAK_JUMP));                 // 25
            entities.Add(new Color(30, 100, 100), new InfoPad(Vector2.One, PlayerPower.SUPER_JUMP));                // 30
            entities.Add(new Color(35, 100, 100), new InfoPad(Vector2.One, PlayerPower.NORMAL_JUMP));               // 35
            entities.Add(new Color(40, 100, 100), new InfoPad(Vector2.One, PlayerPower.MOVEMENT_FAST));             // 40
            entities.Add(new Color(45, 100, 100), new InfoPad(Vector2.One, PlayerPower.MOVEMENT_SLOW));             // 45
            entities.Add(new Color(50, 100, 100), new InfoPad(Vector2.One, PlayerPower.MOVEMENT_NORMAL));           // 50
            entities.Add(new Color(55, 100, 100), new InfoPad(Vector2.One, PlayerPower.BULLET1));                   // 55
            entities.Add(new Color(60, 100, 100), new InfoPad(Vector2.One, PlayerPower.BULLET2));                   // 60
            entities.Add(new Color(65, 100, 100), new InfoPad(Vector2.One, PlayerPower.BULLET_SPREAD));             // 65
            entities.Add(new Color(70, 100, 100), new InfoPad(Vector2.One, PlayerPower.BULLET_DIAGONAL));           // 70
            entities.Add(new Color(75, 100, 100), new InfoPad(Vector2.One, PlayerPower.BULLET_TRIPLE));             // 75
            entities.Add(new Color(80, 100, 100), new InfoPad(Vector2.One, PlayerPower.STRONG_BULLETS));            // 80
            entities.Add(new Color(85, 100, 100), new InfoPad(Vector2.One, PlayerPower.FREEZE_ENEMIES));            // 85
            entities.Add(new Color(90, 100, 100), new InfoPad(Vector2.One, PlayerPower.BURN_ENEMIES));              // 90
            entities.Add(new Color(95, 100, 100), new InfoPad(Vector2.One, PlayerPower.THROW_ENEMY));               // 95
            entities.Add(new Color(100, 100, 100), new InfoPad(Vector2.One, PlayerPower.SUPERLAZER));               // 100
            entities.Add(new Color(105, 100, 100), new InfoPad(Vector2.One, PlayerPower.TELEPORT));                 // 105
            entities.Add(new Color(110, 100, 100), new InfoPad(Vector2.One, PlayerPower.LAZER));                    // 110
            entities.Add(new Color(115, 100, 100), new InfoPad(Vector2.One, PlayerPower.DECREASE_ENEMY_SPEED));     // 115
            entities.Add(new Color(120, 100, 100), new InfoPad(Vector2.One, PlayerPower.GET_ENEMY_ID));             // 120
            entities.Add(new Color(125, 100, 100), new InfoPad(Vector2.One, PlayerPower.KILL_ID));                  // 125
            entities.Add(new Color(130, 100, 100), new InfoPad(Vector2.One, PlayerPower.ROOT_PRIV));                // 130
            entities.Add(new Color(135, 100, 100), new InfoPad(Vector2.One, PlayerPower.OVERCLOCK4));               // 135
            entities.Add(new Color(140, 100, 100), new InfoPad(Vector2.One, PlayerPower.OVERCLOCK2));               // 140
            entities.Add(new Color(145, 100, 100), new InfoPad(Vector2.One, PlayerPower.CLOCK1));                   // 145
            entities.Add(new Color(150, 100, 100), new InfoPad(Vector2.One, PlayerPower.UNDERCLOCK2));              // 150
            entities.Add(new Color(155, 100, 100), new InfoPad(Vector2.One, PlayerPower.UNDERCLOCK4));              // 155
            entities.Add(new Color(160, 100, 100), new InfoPad(Vector2.One, PlayerPower.RESET));                    // 160

            entities.Add(new Color(50, 255, 255), new GuardEnemy(Vector2.One));     // 50
            entities.Add(new Color(60, 255, 255), new SpawnerEnemy(Vector2.One));   // 60
            entities.Add(new Color(70, 255, 255), new FlyingEnemy(Vector2.One));    // 70
            gameMap = new Map(Game, level, tileTextures, entities);

            enemies = gameMap.makeTileMap();

            player = new Player(gameMap.getPlayerSpawn());
            player.LoadContent(Game);

              /*  enemies = new List<Entity>();

            enemies.Add(new GuardEnemy(gameMap.getPlayerSpawn() + new Vector2(600, 0)));
            enemies.Add(new SpawnerEnemy(gameMap.getPlayerSpawn() + new Vector2(-300, 0)));
            enemies.Add(new InfoPad(gameMap.getPlayerSpawn() + new Vector2(150, 0), PlayerPower.GRAVITY_OFF));*/

            bullets = new Bullets();
            bullets.LoadContent(Game);
        }