void fire(Enemy monster)
        {
            int       player_x  = game_state.local_player.getX();
            int       player_y  = game_state.local_player.getY();
            int       monster_x = monster.getX();
            int       monster_y = monster.getY();
            int       fire_x    = 0;
            int       fire_y    = 0;
            int       min       = 0;
            int       max       = 0;
            PlayerDir dir       = PlayerDir.UP;
            Random    random    = new Random();
            bool      fire      = false;

            if (player_x < monster_x + monster.getWidth() && player_x > monster_x - monster.getWidth())
            {
                fire   = true;
                min    = monster.getX();
                max    = monster.getX() + monster.getWidth();
                fire_x = random.Next(min, max);
                if (monster_y - player_y >= 0)
                {
                    dir    = PlayerDir.UP;
                    fire_y = monster.getY() + 5;
                }
                else
                {
                    dir    = PlayerDir.DOWN;
                    fire_y = monster.getY() + monster.getHeight();
                }
            }
            else if (player_y < monster_y + monster.getHeight() && player_y > monster_y - monster.getHeight())
            {
                fire   = true;
                min    = monster.getY();
                max    = monster.getY() + monster.getHeight();
                fire_y = random.Next(min, max);
                if (monster_x - player_x >= 0)
                {
                    dir    = PlayerDir.LEFT;
                    fire_x = monster.getX() - 5;
                }
                else
                {
                    dir    = PlayerDir.RIGHT;
                    fire_x = monster.getX() + monster.getWidth();
                }
            }
            if (fire)
            {
                game_state.bullet_engine.fire(fire_x, fire_y, dir, bulletOwner.ENEMY, bulletType.SMALL);
                fire = false;
            }
            else
            {
                this.advance(monster);
            }
            //Place holder till bullet system works
        }
        void advance(Enemy monster) // go toward player
        {
            PathFind pf          = new PathFind(game_state);
            int      mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
            int      pl_tile_x   = (game_state.local_player.getX() + (game_state.local_player.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      pl_tile_y   = (game_state.local_player.getY() + (game_state.local_player.getHeight())) / game_state.tile_engine.getTileSize();

            monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, pl_tile_y));
        }
        void advance(Enemy monster)
        {
            PathFind pf          = new PathFind(game_state);
            int      mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
            int      pl_tile_x   = (game_state.local_player.getX() + (game_state.local_player.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      pl_tile_y   = (game_state.local_player.getY() + (game_state.local_player.getHeight())) / game_state.tile_engine.getTileSize();

            // pl_tile_y += 1;//get the enemies to head toward the bottom of the player so that they follow you on the bridge
            monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, pl_tile_y));
        }
        void idle(Enemy monster)
        {
            //THIS IS FOR DEBUG PURPOSES
            //PathFind pf = new PathFind(game_state);
            //int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            //int mons_tiel_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
            //monster.setPath(pf.FindPath(mons_tile_x, mons_tiel_y, 1, 1));

            PathFind pf           = new PathFind(game_state);
            int      mons_tile_x  = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y  = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            Random   r            = new Random();
            int      mons_tile_xr = mons_tile_x + r.Next(-10, 10);
            int      mons_tile_yr = mons_tile_y + r.Next(-10, 10);

            if (mons_tile_yr < 0)
            {
                mons_tile_yr = 0;
            }
            if (mons_tile_xr < 0)
            {
                mons_tile_xr = 0;
            }
            monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));

            /*
             * //Random number
             * System.Random generator = new System.Random();
             * int dir = generator.Next(4);
             * switch ((PlayerDir)dir)
             * {
             *  case PlayerDir.DOWN:
             *      monster.setY(monster.getY() + monster.getSpeed());
             *      monster.setDirection(PlayerDir.DOWN);
             *      break;
             *  case PlayerDir.LEFT:
             *      monster.setX(monster.getX() - monster.getSpeed());
             *      monster.setDirection(PlayerDir.LEFT);
             *      break;
             *  case PlayerDir.RIGHT:
             *      monster.setX(monster.getX() + monster.getSpeed());
             *      monster.setDirection(PlayerDir.RIGHT);
             *      break;
             *  case PlayerDir.UP:
             *      monster.setY(monster.getY() - monster.getSpeed());
             *      monster.setDirection(PlayerDir.UP);
             *      break;
             * }
             * */
        }
        void move_towards_target(Enemy monster)
        {
            if (monster.getTarget() == null)
            {
                return;
            }
            int dist_x = monster.getTarget().loc_x - (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int dist_y = monster.getTarget().loc_y - (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();

            if (dist_x == 0 && dist_y == 0)
            {
                monster.nextTarget();
                return;
            }

            if (Math.Abs(dist_x) > Math.Abs(dist_y))
            {
                //Advance in the X direction
                if (dist_x > 0)
                {
                    monster.setX(monster.getX() + monster.getSpeed());
                    monster.setDirection(PlayerDir.RIGHT);
                }
                else
                {
                    monster.setX(monster.getX() - monster.getSpeed());
                    monster.setDirection(PlayerDir.LEFT);
                }
            }
            else
            {
                //Advance in the Y direction
                if (dist_y > 0)
                {
                    monster.setY(monster.getY() + monster.getSpeed());
                    monster.setDirection(PlayerDir.DOWN);
                }
                else
                {
                    monster.setY(monster.getY() - monster.getSpeed());
                    monster.setDirection(PlayerDir.UP);
                }
            }
            if (monster.getLastDirection() != monster.getDirection())
            {
                monster.getSprite().StartAnimating((int)monster.getDirection() * 3, ((int)monster.getDirection() * 3) + 2);
            }
        }
        void idle(Enemy monster) // dont do anything
        {
            PathFind pf           = new PathFind(game_state);
            int      mons_tile_x  = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y  = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            Random   r            = new Random();
            int      mons_tile_xr = mons_tile_x + r.Next(-10, 10);
            int      mons_tile_yr = mons_tile_y + r.Next(-10, 10);

            if (mons_tile_yr < 0)
            {
                mons_tile_yr = 0;
            }
            if (mons_tile_xr < 0)
            {
                mons_tile_xr = 0;
            }
            monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
        }
        void align(Enemy monster)
        {
            PathFind pf          = new PathFind(game_state);
            int      dist_x      = game_state.local_player.getX() - monster.getX();
            int      dist_y      = game_state.local_player.getY() - monster.getY();
            int      mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            int      pl_tile_x   = game_state.local_player.getX() / game_state.tile_engine.getTileSize();
            int      pl_tile_y   = game_state.local_player.getY() / game_state.tile_engine.getTileSize();


            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                //Advance in the X direction toward the player
                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, mons_tile_y));
            }
            else
            {
                //Advance in the Y direction toward the player
                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_x, pl_tile_y - 1));
            }
        }
 void advance(Enemy monster)
 {
     PathFind pf = new PathFind(game_state);
     int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
     int mons_tile_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
     int pl_tile_x = (game_state.local_player.getX()+(game_state.local_player.getWidth()/2))/game_state.tile_engine.getTileSize();
     int pl_tile_y = (game_state.local_player.getY()+(game_state.local_player.getHeight()))/game_state.tile_engine.getTileSize();
        // pl_tile_y += 1;//get the enemies to head toward the bottom of the player so that they follow you on the bridge
     monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, pl_tile_y));
 }
Example #9
0
        public void LoadLevel(int level_num)
        {
            game_state.obj_mang.Clear();
            resetTimer();
            game_state.tile_engine.loadLevel(level_num);//needs to be changed to level_0
            game_state.obj_mang.load(game_state.tile_engine.getCurrentMap().getLayer(LayerType.OBJECTS));
            //game_state.monster_engine.AddMonster(new Enemy(500, 240, 48, 54, enemyType.GRUNT));
            //game_state.monster_engine.AddMonster(new Enemy(300, 400, 48, 54, enemyType.GRUNT));
            for (int i = 0; i < game_state.monster_engine.GetMonsters().Count(); ++i)
            {
                Enemy  new_enemy      = game_state.monster_engine.GetMonsters().ElementAt(i);
                Sprite enemy_sprite   = new Sprite();
                int    new_enemy_type = (int)new_enemy.getType();

                enemy_sprite.Load(monster_texture[new_enemy_type], new_enemy.getWidth(), new_enemy.getHeight(), 200);
                new_enemy.setSprite(enemy_sprite);
                //game_state.monster_engine.AddMonster(new_enemy);
            }

            /*
             * game_state.monster_engine = new MonsterEngine(game_state);
             * game_state.coll_engine = new CollisionEngine(game_state);
             * game_state.fx_engine = new EffectsEngine(game_state);
             * game_state.obj_mang = new ObjectManager(game_state);
             */
        }
        //Functions to calculate actions
        void flee(Enemy monster)
        {
            PathFind pf           = new PathFind(game_state);
            int      dist_x       = game_state.local_player.getX() - monster.getX();
            int      dist_y       = game_state.local_player.getY() - monster.getY();
            int      mons_tile_x  = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int      mons_tile_y  = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            int      pl_tile_x    = game_state.local_player.getX() / game_state.tile_engine.getTileSize();
            int      pl_tile_y    = game_state.local_player.getY() / game_state.tile_engine.getTileSize();
            Random   r            = new Random();
            int      mons_tile_xr = mons_tile_x;
            int      mons_tile_yr = mons_tile_y;

            //int pl_tile_yr = pl_tile_y + r.Next(-5, 5);
            //int pl_tile_xr = pl_tile_x + r.Next(-5, 5);
            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                //Flee in the Y direction from the player
                if (dist_y <= 0)
                {
                    mons_tile_yr += r.Next(-5, -10);
                    mons_tile_xr += r.Next(-10, 10);
                    if (mons_tile_yr < 0)
                    {
                        mons_tile_yr = 0;
                    }
                    if (mons_tile_xr < 0)
                    {
                        mons_tile_xr = 0;
                    }
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                else
                {
                    mons_tile_yr += r.Next(5, 10);
                    mons_tile_xr += r.Next(-10, 10);
                    if (mons_tile_yr < 0)
                    {
                        mons_tile_yr = 0;
                    }
                    if (mons_tile_xr < 0)
                    {
                        mons_tile_xr = 0;
                    }
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
            }
            else
            {
                //Flee in the x direction from the player
                if (dist_x <= 0)
                {
                    mons_tile_yr += r.Next(-10, 10);
                    mons_tile_xr += r.Next(5, 10);
                    if (mons_tile_yr < 0)
                    {
                        mons_tile_yr = 0;
                    }
                    if (mons_tile_xr < 0)
                    {
                        mons_tile_xr = 0;
                    }
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                else
                {
                    mons_tile_yr += r.Next(-10, 10);
                    mons_tile_xr += r.Next(5, 10);
                    if (mons_tile_yr < 0)
                    {
                        mons_tile_yr = 0;
                    }
                    if (mons_tile_xr < 0)
                    {
                        mons_tile_xr = 0;
                    }
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
            }

            //monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
        }
        void align(Enemy monster)
        {
            PathFind pf = new PathFind(game_state);
            int dist_x = game_state.local_player.getX() - monster.getX();
            int dist_y = game_state.local_player.getY() - monster.getY();
            int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int mons_tile_y = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            int pl_tile_x = game_state.local_player.getX() / game_state.tile_engine.getTileSize();
            int pl_tile_y = game_state.local_player.getY() / game_state.tile_engine.getTileSize();

            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                //Advance in the X direction toward the player

                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, mons_tile_y));
            }
            else
            {
                //Advance in the Y direction toward the player

                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_x, pl_tile_y-1));
            }
        }
 void fire(Enemy monster)
 {
     int player_x = game_state.local_player.getX();
     int player_y = game_state.local_player.getY();
     int monster_x = monster.getX();
     int monster_y = monster.getY();
     int fire_x = 0;
     int fire_y = 0;
     int min = 0;
     int max = 0;
     PlayerDir dir = PlayerDir.UP;
     Random random = new Random();
     bool fire = false;
     if (player_x < monster_x + monster.getWidth() && player_x > monster_x - monster.getWidth())
     {
         fire = true;
         min = monster.getX();
         max = monster.getX()+monster.getWidth();
         fire_x = random.Next(min,max);
         if (monster_y - player_y >= 0)
         {
             dir = PlayerDir.UP;
             fire_y = monster.getY() + 5;
         }
         else
         {
             dir = PlayerDir.DOWN;
             fire_y = monster.getY() + monster.getHeight();
         }
     }
     else if (player_y < monster_y + monster.getHeight() && player_y > monster_y - monster.getHeight())
     {
         fire = true;
         min = monster.getY();
         max = monster.getY() + monster.getHeight();
         fire_y = random.Next(min, max);
         if (monster_x - player_x >= 0)
         {
             dir = PlayerDir.LEFT;
             fire_x = monster.getX() - 5;
         }
         else
         {
             dir = PlayerDir.RIGHT;
             fire_x = monster.getX() + monster.getWidth();
         }
     }
     if (fire)
     {
         game_state.bullet_engine.fire(fire_x, fire_y, dir, bulletOwner.ENEMY, bulletType.SMALL);
         fire = false;
     }
     else
     {
         this.advance(monster);
     }
      //Place holder till bullet system works
 }
        public void Update(int elapsed_time) // detect if explosion needs to be drawn, determine what the monster needs to do, handle dead monsters
        {
            for (int i = 0; i < monsters.Count(); ++i)
            {
                Enemy monster      = monsters.ElementAt(i);
                bool  mons_removed = false;

                if (monster.getHealth() <= 0)
                {
                    game_state.monster_engine.Remove(monster);
                    mons_removed = true;
                    game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX() + (monster.getWidth() / 2), monster.getY() + (monster.getHeight() / 2));
                    game_state.fx_engine.RequestSound(soundType.ENEMY_DIE);
                }
                if (mons_removed == false)
                {
                    if (IsVisible(monster))
                    {
                        move_towards_target(monster);

                        if (monster.next_think_time >= 2000) //TIME DELAY
                        {
                            actionDecision action = think(monster);
                            act(monster, action);
                            monster.next_think_time = 0;
                        }
                        else
                        {
                            monster.next_think_time += elapsed_time;
                        }
                    }
                }
            }
        }
 // dont do anything
 void idle(Enemy monster)
 {
     PathFind pf = new PathFind(game_state);
     int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
     int mons_tile_y = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
     Random r = new Random();
     int mons_tile_xr = mons_tile_x + r.Next(-10, 10);
     int mons_tile_yr = mons_tile_y + r.Next(-10, 10);
     if (mons_tile_yr < 0)
         mons_tile_yr = 0;
     if (mons_tile_xr < 0)
         mons_tile_xr = 0;
     monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
 }
        //Functions to calculate actions
        void flee(Enemy monster)
        {
            PathFind pf = new PathFind(game_state);
            int dist_x = game_state.local_player.getX() - monster.getX();
            int dist_y = game_state.local_player.getY() - monster.getY();
            int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int mons_tile_y = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            int pl_tile_x = game_state.local_player.getX() / game_state.tile_engine.getTileSize();
            int pl_tile_y = game_state.local_player.getY() / game_state.tile_engine.getTileSize();
            Random r = new Random();
            int mons_tile_xr = mons_tile_x;
            int mons_tile_yr = mons_tile_y;
            //int pl_tile_yr = pl_tile_y + r.Next(-5, 5);
            //int pl_tile_xr = pl_tile_x + r.Next(-5, 5);
            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                //Flee in the Y direction from the player
                if (dist_y <= 0)
                {
                    mons_tile_yr += r.Next(-10, -5);
                    mons_tile_xr += r.Next(-10, 10);
                    if (mons_tile_yr < 0)
                        mons_tile_yr = 0;
                    if (mons_tile_xr < 0)
                        mons_tile_xr = 0;
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                else
                {
                    mons_tile_yr += r.Next(5, 10);
                    mons_tile_xr += r.Next(-10, 10);
                    if (mons_tile_yr < 0)
                        mons_tile_yr = 0;
                    if (mons_tile_xr < 0)
                        mons_tile_xr = 0;
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
            }
            else
            {
                //Flee in the x direction from the player
                if (dist_x <= 0)
                {
                    mons_tile_yr += r.Next(-10, 10);
                    mons_tile_xr += r.Next(5, 10);
                    if (mons_tile_yr < 0)
                        mons_tile_yr = 0;
                    if (mons_tile_xr < 0)
                        mons_tile_xr = 0;
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                else
                {
                    mons_tile_yr += r.Next(-10, 10);
                    mons_tile_xr += r.Next(5, 10);
                    if (mons_tile_yr < 0)
                        mons_tile_yr = 0;
                    if (mons_tile_xr < 0)
                        mons_tile_xr = 0;
                    monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
                }
                monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
            }

            //monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public void LoadContent(ContentManager Content)
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            Texture2D textureb = Content.Load <Texture2D>("background_cropped"); // background
            Texture2D texturef = Content.Load <Texture2D>("foreground_cropped"); // foreground
            Texture2D textureo = Content.Load <Texture2D>("objects1");           // objects

            tiles = new List <Texture2D>();                                      // tiles
            tiles.Add(textureb);
            tiles.Add(texturef);
            tiles.Add(textureo); // add bg, fg, obj's to draw
            game_state.tile_engine = new TileEngine(32, tiles);

            //Character Sprite
            character_sprite[(int)weaponType.NONE].Load(Content, "player_no", 32, 36, 200);
            character_sprite[(int)weaponType.SWORD].Load(Content, "player_sword", 32, 36, 200);
            character_sprite[(int)weaponType.LASER].Load(Content, "player_gun", 32, 36, 200);

            monster_texture[(int)enemyType.GRUNT] = Content.Load <Texture2D>("grunt");

            monster_texture[(int)enemyType.BEETLE]    = Content.Load <Texture2D>("beetles");
            monster_texture[(int)enemyType.BERSERKER] = Content.Load <Texture2D>("berserker");
            monster_texture[(int)enemyType.TROOPER]   = Content.Load <Texture2D>("trooper");

            LoadLevel(0);
            bullet_sprite.Load(Content, "bullet", 9, 9, 0);
            sword_sprite.Load(Content, "player_sword_attack", 32, 36, 0);


            for (int i = 0; i < game_state.monster_engine.GetMonsters().Count(); ++i) // draw new monsters randomly
            {
                Enemy  new_enemy      = game_state.monster_engine.GetMonsters().ElementAt(i);
                Sprite enemy_sprite   = new Sprite();
                int    new_enemy_type = (int)new_enemy.getType();

                enemy_sprite.Load(monster_texture[new_enemy_type], new_enemy.getWidth(), new_enemy.getHeight(), 200);
                new_enemy.setSprite(enemy_sprite);
            }

            game_state.bullet_engine = new BulletEngine(game_state);


            uparrow         = Content.Load <Texture2D>("arrowup");
            downarrow       = Content.Load <Texture2D>("arrowdown");
            leftarrow       = Content.Load <Texture2D>("arrowleft");
            rightarrow      = Content.Load <Texture2D>("arrowright");      // components for "keypad" HUD
            fire_button     = Content.Load <Texture2D>("fire");            // "fire" button (attacks enemies when pushed)
            item_background = Content.Load <Texture2D>("item_background"); // user taps this to bring up inventory

            game_state.fx_engine.LoadSound(Content, "shoot", soundType.SHOOT);

            game_state.fx_engine.LoadSound(Content, "enemy_hit", soundType.ENEMY_HURT);
            game_state.fx_engine.LoadSound(Content, "enemy_die", soundType.ENEMY_DIE);
            game_state.fx_engine.LoadSound(Content, "player_hurt", soundType.PLAYER_HURT);
            game_state.fx_engine.LoadSound(Content, "player_sword_s", soundType.SWORD);
            game_state.fx_engine.LoadSound(Content, "item_pickup", soundType.ITEM_PICKUP);
            game_state.fx_engine.LoadExplosion(Content, "expl", explosionType.SMALL);
            //SoundEffect game_music = Content.Load<SoundEffect>("01AttackPanda1");
            Song game_music = Content.Load <Song>("01AttackPanda1");

            MediaPlayer.Play(game_music);
            MediaPlayer.IsRepeating = true;

            //********************************LOADING GRAPHIC SPRITES********************************//
            backpack             = Content.Load <Texture2D>("backpack");       // loading backpack
            healthbar_empty      = Content.Load <Texture2D>("healthbar");      // load health bar
            healthbar_full       = Content.Load <Texture2D>("healthbar_full"); // load health bar
            health_bar_rec       = new Rectangle((int)healthpos.X, (int)healthpos.Y, health_bar_width, 30);
            health_bar_empty_rec = new Rectangle((int)healthpos.X, (int)healthpos.Y, health_bar_width, 30);
            //**************************************************************************************//


            //********************MISCELLANEOUS*****************************************************//
            displayFont = Content.Load <SpriteFont>("StatsFont");   //load a font from a formatted file
            //displayFont = Content.Load<SpriteFont>("Courier New");
            itemfont    = Content.Load <SpriteFont>("ItemFont");    // ^^
            expiredfont = Content.Load <SpriteFont>("TimeExpired"); // ^^
            //***************************************************************************************//

            backpackmenu.loadContent(Content);
            gameOver.loadContent(Content);
            timex.loadContent(Content);
            //load content for each respective menu
        }
        void idle(Enemy monster)
        {
            //THIS IS FOR DEBUG PURPOSES
            //PathFind pf = new PathFind(game_state);
            //int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            //int mons_tiel_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
            //monster.setPath(pf.FindPath(mons_tile_x, mons_tiel_y, 1, 1));

            PathFind pf = new PathFind(game_state);
            int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
            int mons_tile_y = (monster.getY() + (monster.getHeight() / 2)) / game_state.tile_engine.getTileSize();
            Random r = new Random();
            int mons_tile_xr = mons_tile_x + r.Next(-10, 10);
            int mons_tile_yr = mons_tile_y + r.Next(-10, 10);
            if (mons_tile_yr < 0)
                mons_tile_yr = 0;
            if (mons_tile_xr < 0)
                mons_tile_xr = 0;
            monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, mons_tile_xr, mons_tile_yr));

            /*
            //Random number
            System.Random generator = new System.Random();
            int dir = generator.Next(4);
            switch ((PlayerDir)dir)
            {
                case PlayerDir.DOWN:
                    monster.setY(monster.getY() + monster.getSpeed());
                    monster.setDirection(PlayerDir.DOWN);
                    break;
                case PlayerDir.LEFT:
                    monster.setX(monster.getX() - monster.getSpeed());
                    monster.setDirection(PlayerDir.LEFT);
                    break;
                case PlayerDir.RIGHT:
                    monster.setX(monster.getX() + monster.getSpeed());
                    monster.setDirection(PlayerDir.RIGHT);
                    break;
                case PlayerDir.UP:
                    monster.setY(monster.getY() - monster.getSpeed());
                    monster.setDirection(PlayerDir.UP);
                    break;
            }
             * */
        }
Example #18
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public void LoadContent(ContentManager Content)
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            Texture2D textureb = Content.Load <Texture2D>("background_cropped");
            Texture2D texturef = Content.Load <Texture2D>("foreground_cropped");
            Texture2D textureo = Content.Load <Texture2D>("objects1");

            tiles = new List <Texture2D>();
            tiles.Add(textureb);
            tiles.Add(texturef);
            tiles.Add(textureo);
            game_state.tile_engine = new TileEngine(32, tiles);

            //back_layer = tileEngine.getLayer(LayerType.BACKGROUND);
            //Character Sprite
            character_sprite[(int)weaponType.NONE].Load(Content, "player_no", 32, 36, 200);
            character_sprite[(int)weaponType.SWORD].Load(Content, "player_sword", 32, 36, 200);
            character_sprite[(int)weaponType.LASER].Load(Content, "player_gun", 32, 36, 200);
            //character_sprite.loc.X = 400;
            //character_sprite.loc.Y = 240;

            monster_texture[(int)enemyType.GRUNT] = Content.Load <Texture2D>("grunt");

            monster_texture[(int)enemyType.BEETLE]    = Content.Load <Texture2D>("beetles");
            monster_texture[(int)enemyType.BERSERKER] = Content.Load <Texture2D>("berserker");
            monster_texture[(int)enemyType.TROOPER]   = Content.Load <Texture2D>("trooper");
            //monster_sprites[(int)enemyType.GRUNT].Load(monster_texture[(int)enemyType.GRUNT], 32, 48);
            //monster_sprites[(int)enemyType.GRUNT].StartAnimating((int)PlayerDir.UP * 3, ((int)PlayerDir.UP * 3) + 2);
            LoadLevel(0);
            bullet_sprite.Load(Content, "bullet", 9, 9, 0);
            sword_sprite.Load(Content, "player_sword_attack", 32, 36, 0);


            //game_state.monster_engine.AddMonster(new Enemy(500, 240, 48, 54, enemyType.GRUNT));
            //game_state.monster_engine.AddMonster(new Enemy(300, 400, 48, 54, enemyType.GRUNT));
            for (int i = 0; i < game_state.monster_engine.GetMonsters().Count(); ++i)
            {
                Enemy  new_enemy      = game_state.monster_engine.GetMonsters().ElementAt(i);
                Sprite enemy_sprite   = new Sprite();
                int    new_enemy_type = (int)new_enemy.getType();

                enemy_sprite.Load(monster_texture[new_enemy_type], new_enemy.getWidth(), new_enemy.getHeight(), 200);
                new_enemy.setSprite(enemy_sprite);
                //game_state.monster_engine.AddMonster(new_enemy);
            }

            game_state.bullet_engine = new BulletEngine(game_state);
            //character_sprite.StartAnimating(6, 8);
            // TODO: use this.Content to load your game content here

            uparrow         = Content.Load <Texture2D>("arrowup");
            downarrow       = Content.Load <Texture2D>("arrowdown");
            leftarrow       = Content.Load <Texture2D>("arrowleft");
            rightarrow      = Content.Load <Texture2D>("arrowright"); // components for "keypad" HUD
            fire_button     = Content.Load <Texture2D>("fire");
            item_background = Content.Load <Texture2D>("item_background");

            game_state.fx_engine.LoadSound(Content, "shoot", soundType.SHOOT);
            game_state.fx_engine.LoadSound(Content, "hurt", soundType.HURT);
            game_state.fx_engine.LoadSound(Content, "sword_swing", soundType.SWORD);
            game_state.fx_engine.LoadExplosion(Content, "expl", explosionType.SMALL);
            //SoundEffect game_music = Content.Load<SoundEffect>("01AttackPanda1");
            Song game_music = Content.Load <Song>("01AttackPanda1");

            MediaPlayer.Play(game_music);
            //game_music.Play();

            //********************************LOADING GRAPHIC SPRITES********************************//
            backpack             = Content.Load <Texture2D>("backpack");       // loading backpack
            healthbar_empty      = Content.Load <Texture2D>("healthbar");      // load health bar
            healthbar_full       = Content.Load <Texture2D>("healthbar_full"); // load health bar
            health_bar_rec       = new Rectangle((int)healthpos.X, (int)healthpos.Y, health_bar_width, 30);
            health_bar_empty_rec = new Rectangle((int)healthpos.X, (int)healthpos.Y, health_bar_width, 30);
            //**************************************************************************************//


            //********************MISCELLANEOUS*****************************************************//
            displayFont = Content.Load <SpriteFont>("StatsFont");   //load a font from a formatted file
            //displayFont = Content.Load<SpriteFont>("Courier New");
            itemfont    = Content.Load <SpriteFont>("ItemFont");    // ^^
            expiredfont = Content.Load <SpriteFont>("TimeExpired"); // ^^
            //***************************************************************************************//

            backpackmenu.loadContent(Content);
            gameOver.loadContent(Content);
            timex.loadContent(Content);
        }
Example #19
0
        public void Update()
        {
            for (int i = 0; i < marked_objects.Count(); ++i) // for every object that has been "marked", or changed/modified via gameplay, check to see if there is collisions
            {
                ColToken obj = marked_objects.ElementAt(i);
                int      loc_x = 0, loc_y = 0, width = 0, height = 0;
                switch (obj.GetLocalType())
                {
                case ColType.PLAYER:
                    Player temp_pl = (Player)obj.GetParent();
                    loc_x  = temp_pl.getX();
                    loc_y  = temp_pl.getY();
                    width  = temp_pl.getWidth();
                    height = temp_pl.getHeight();
                    break;

                case ColType.MONSTER:
                    Enemy temp_em = (Enemy)obj.GetParent();
                    loc_x  = temp_em.getX();
                    loc_y  = temp_em.getY();
                    width  = temp_em.getWidth();
                    height = temp_em.getHeight();
                    break;

                case ColType.BULLET:
                    Bullet temp_bu = (Bullet)obj.GetParent();
                    loc_x  = temp_bu.x;
                    loc_y  = temp_bu.y;
                    width  = temp_bu.width;
                    height = temp_bu.height;
                    break;
                }

                if (check_map_col(loc_x, loc_y, width, height))
                {
                    obj.Collision(new ColToken(ColType.MAP, this, unique_id++, null));
                }


                for (int j = 0; j < all_objects.Count(); ++j) // check to see if any object is involved in a collision
                {
                    ColToken other_obj = all_objects.ElementAt(j);
                    if (obj.getID() == other_obj.getID())
                    {
                        continue;
                    }
                    int other_loc_x = 0, other_loc_y = 0, other_width = 0, other_height = 0;
                    switch (other_obj.GetLocalType())
                    {
                    case ColType.PLAYER:
                        Player temp_pl = (Player)other_obj.GetParent();
                        other_loc_x  = temp_pl.getX();
                        other_loc_y  = temp_pl.getY();
                        other_width  = temp_pl.getWidth();
                        other_height = temp_pl.getHeight();
                        break;

                    case ColType.MONSTER:
                        Enemy temp_em = (Enemy)other_obj.GetParent();
                        other_loc_x  = temp_em.getX();
                        other_loc_y  = temp_em.getY();
                        other_width  = temp_em.getWidth();
                        other_height = temp_em.getHeight();
                        break;

                    case ColType.BULLET:
                        Bullet temp_bu = (Bullet)other_obj.GetParent();
                        other_loc_x  = temp_bu.x;
                        other_loc_y  = temp_bu.y;
                        other_width  = temp_bu.width;
                        other_height = temp_bu.height;
                        break;
                    }


                    if (check_col(loc_x, loc_y, other_loc_x, other_loc_y, width, height, other_width, other_height))
                    {
                        obj.Collision(other_obj);
                    }
                }
                obj.updated_this_frame = false;
            }
            marked_objects.Clear(); // handled all of the modified objects
        }
        void move_towards_target(Enemy monster)
        {
            if (monster.getTarget() == null)
            {
                return;
            }
            int dist_x = monster.getTarget().loc_x - (monster.getX()+(monster.getWidth()/2))/game_state.tile_engine.getTileSize();
            int dist_y = monster.getTarget().loc_y - (monster.getY()+(monster.getHeight())) / game_state.tile_engine.getTileSize();
            if (dist_x == 0 && dist_y == 0)
            {
                monster.nextTarget();
                return;
            }

            if (Math.Abs(dist_x) > Math.Abs(dist_y))
            {
                //Advance in the X direction
                if (dist_x > 0)
                {
                    monster.setX(monster.getX() + monster.getSpeed());
                    monster.setDirection(PlayerDir.RIGHT);
                }
                else
                {
                    monster.setX(monster.getX() - monster.getSpeed());
                    monster.setDirection(PlayerDir.LEFT);
                }
            }
            else
            {
                //Advance in the Y direction
                if (dist_y > 0)
                {
                    monster.setY(monster.getY() + monster.getSpeed());
                    monster.setDirection(PlayerDir.DOWN);

                }
                else
                {
                    monster.setY(monster.getY() - monster.getSpeed());
                    monster.setDirection(PlayerDir.UP);

                }
            }
            if (monster.getLastDirection() != monster.getDirection())
            {
                monster.getSprite().StartAnimating((int)monster.getDirection() * 3, ((int)monster.getDirection() * 3) + 2);
            }
        }
        public void Update(int elapsed_time)
        {
            for (int i = 0; i < monsters.Count(); ++i)
            {
                Enemy monster      = monsters.ElementAt(i);
                bool  mons_removed = false;

                /*
                 * if (monster.col_tok.HasCollisions())//&& monster.col_tok.GetHitType() == ColType.BULLET)
                 * {
                 *
                 *  List<ColToken> cols = monster.col_tok.GetCollisions();
                 *  for (int j = 0; j < cols.Count(); ++j)
                 *  {
                 *      if (cols.ElementAt(j).GetLocalType() == ColType.BULLET )
                 *      {
                 *          //MAGIC NUMBER
                 *          Bullet bull = (Bullet)cols.ElementAt(j).GetParent();
                 *          int damage = 0;
                 *          switch (bull.type)
                 *          {
                 *              case bulletType.SMALL:
                 *                  damage = 5;
                 *                  break;
                 *              case bulletType.SWORD:
                 *                  damage = 10;
                 *                  break;
                 *
                 *          }
                 *          monster.setHealth(monster.getHealth() - (game_state.local_player.getAttackBonus()+damage));
                 *          //dmg_sound.Play();
                 *          if (monster.getHealth() <= 0)
                 *          {
                 *              game_state.monster_engine.Remove(monster);
                 *              mons_removed = true;
                 *              game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX()+(monster.getWidth()/2), monster.getY()+(monster.getHeight()/2));
                 *          }
                 *          game_state.fx_engine.RequestSound(soundType.HURT);
                 *      }
                 *      else if (cols.ElementAt(j).GetLocalType() == ColType.MAP)
                 *      {
                 *          //monster.revertX();
                 *          //monster.revertY();
                 *      }
                 *  }
                 *
                 *  monster.col_tok.ResetCollisions();
                 * }
                 * */
                if (monster.getHealth() <= 0)
                {
                    game_state.monster_engine.Remove(monster);
                    mons_removed = true;
                    game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX() + (monster.getWidth() / 2), monster.getY() + (monster.getHeight() / 2));
                }
                if (mons_removed == false)
                {
                    if (IsVisible(monster))
                    {
                        move_towards_target(monster);

                        if (monster.next_think_time >= 2000) //TIME DELAY
                        {
                            actionDecision action = think(monster);
                            act(monster, action);
                            monster.next_think_time = 0;
                        }
                        else
                        {
                            monster.next_think_time += elapsed_time;
                        }
                    }
                }
            }
        }
Example #22
0
        public void Update()
        {
            for (int i = 0; i < marked_objects.Count(); ++i)
            {
                ColToken obj = marked_objects.ElementAt(i);
                int      loc_x = 0, loc_y = 0, width = 0, height = 0;
                switch (obj.GetLocalType())
                {
                case ColType.PLAYER:
                    Player temp_pl = (Player)obj.GetParent();
                    loc_x  = temp_pl.getX();
                    loc_y  = temp_pl.getY();
                    width  = temp_pl.getWidth();
                    height = temp_pl.getHeight();
                    break;

                case ColType.MONSTER:
                    Enemy temp_em = (Enemy)obj.GetParent();
                    loc_x  = temp_em.getX();
                    loc_y  = temp_em.getY();
                    width  = temp_em.getWidth();
                    height = temp_em.getHeight();
                    break;

                case ColType.BULLET:
                    Bullet temp_bu = (Bullet)obj.GetParent();
                    loc_x  = temp_bu.x;
                    loc_y  = temp_bu.y;
                    width  = temp_bu.width;
                    height = temp_bu.height;
                    break;
                }

                if (check_map_col(loc_x, loc_y, width, height))
                {
                    // obj.Collision(new Collision(ColType.MAP, 0)); // REVERTS ITSELF SOME TIMES SO IT SAYS IT'S MARKED
                    obj.Collision(new ColToken(ColType.MAP, this, unique_id++, null));
                }


                for (int j = 0; j < all_objects.Count(); ++j)
                {
                    ColToken other_obj = all_objects.ElementAt(j);
                    if (obj.getID() == other_obj.getID())
                    {
                        continue;
                    }
                    int other_loc_x = 0, other_loc_y = 0, other_width = 0, other_height = 0;
                    switch (other_obj.GetLocalType())
                    {
                    case ColType.PLAYER:
                        Player temp_pl = (Player)other_obj.GetParent();
                        other_loc_x  = temp_pl.getX();
                        other_loc_y  = temp_pl.getY();
                        other_width  = temp_pl.getWidth();
                        other_height = temp_pl.getHeight();
                        break;

                    case ColType.MONSTER:
                        Enemy temp_em = (Enemy)other_obj.GetParent();
                        other_loc_x  = temp_em.getX();
                        other_loc_y  = temp_em.getY();
                        other_width  = temp_em.getWidth();
                        other_height = temp_em.getHeight();
                        break;

                    case ColType.BULLET:
                        Bullet temp_bu = (Bullet)other_obj.GetParent();
                        other_loc_x  = temp_bu.x;
                        other_loc_y  = temp_bu.y;
                        other_width  = temp_bu.width;
                        other_height = temp_bu.height;
                        break;
                    }

                    //Check col

                    /*
                     * if (obj.GetLocalType() == ColType.BULLET && other_obj.GetLocalType() == ColType.MONSTER)
                     * {
                     *  //HELP
                     *  continue;
                     * }
                     * */
                    if (check_col(loc_x, loc_y, other_loc_x, other_loc_y, width, height, other_width, other_height))
                    {
                        // obj.Collision(new Collision(other_obj.GetLocalType(), other_obj.getID()));
                        // other_obj.Collision(new Collision(obj.GetLocalType(), obj.getID()));
                        obj.Collision(other_obj);
                    }
                }
                obj.updated_this_frame = false;
            }
            marked_objects.Clear();
        }
        public void LoadLevel(int level_num) // which level should we load?
        {
            game_state.obj_mang.Clear();
            resetTimer(); // restart the level timer for each new level
            game_state.tile_engine.loadLevel(level_num);
            game_state.obj_mang.load(game_state.tile_engine.getCurrentMap().getLayer(LayerType.OBJECTS));

            for (int i = 0; i < game_state.monster_engine.GetMonsters().Count(); ++i) // put the enemies on the map
            {
                Enemy  new_enemy      = game_state.monster_engine.GetMonsters().ElementAt(i);
                Sprite enemy_sprite   = new Sprite();
                int    new_enemy_type = (int)new_enemy.getType();

                enemy_sprite.Load(monster_texture[new_enemy_type], new_enemy.getWidth(), new_enemy.getHeight(), 200);
                new_enemy.setSprite(enemy_sprite);
            }
        }
 // go toward player
 void advance(Enemy monster)
 {
     PathFind pf = new PathFind(game_state);
     int mons_tile_x = (monster.getX() + (monster.getWidth() / 2)) / game_state.tile_engine.getTileSize();
     int mons_tile_y = (monster.getY() + (monster.getHeight())) / game_state.tile_engine.getTileSize();
     int pl_tile_x = (game_state.local_player.getX()+(game_state.local_player.getWidth()/2))/game_state.tile_engine.getTileSize();
     int pl_tile_y = (game_state.local_player.getY()+(game_state.local_player.getHeight()))/game_state.tile_engine.getTileSize();
     monster.setPath(pf.FindPath(mons_tile_x, mons_tile_y, pl_tile_x, pl_tile_y));
 }