Ejemplo n.º 1
0
        public bool IsVisible(Enemy monster)
        {
            //MAGIC NUMBERS. Screen is 800 long by 480
            //We can determine if the monster is visible based on the players position
            int screen_x = Math.Abs(game_state.local_player.getX() - monster.getX());
            int screen_y = Math.Abs(game_state.local_player.getY() - monster.getY());

            if (screen_x > 800 || screen_y > 400)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        public void load(TileLayer _objects_layer)
        {
            objects_layer = _objects_layer;
            for (int w = 0; w < objects_layer.getWidth(); ++w)
            {
                for (int h = 0; h < objects_layer.getHeight(); ++h)
                {
                    Tile t = objects_layer.getTile(w, h);
                    if (t.getTexture() == -1)
                    {
                        continue;
                    }
                    if (obj_hash[t.getTexture()] == objectType.SPAWN)
                    {
                        if (t.getTexture() == PLAYER_SPAWN)
                        {
                            game_state.local_player.setX((w * TileEngine.TILE_SIZE)+(TileEngine.TILE_SIZE/2) - game_state.local_player.getWidth()/2);///2+game_state.local_player.getWidth());
                            game_state.local_player.setY((h * TileEngine.TILE_SIZE) + (TileEngine.TILE_SIZE / 2) - game_state.local_player.getHeight());///2+game_state.local_player.getHeight());
                        }
                        else
                        {

                            int width = 0;
                            int height = 0;
                            enemyType type = enemyType.BEETLE;

                            switch (t.getTexture())
                            {
                                case 78: //Beetle
                                    width = 30;
                                    height = 30;
                                    type = enemyType.BEETLE;
                                    break;
                                case 72: //grunt
                                    width = 32;
                                    height = 36;
                                    type = enemyType.GRUNT;
                                    break;
                                case 73: //Berserker
                                    width = 32;
                                    height = 36;
                                    type = enemyType.BERSERKER;
                                    break;
                                case 77: //Trooper
                                    width = 32;
                                    height = 36;
                                    type = enemyType.TROOPER;
                                    break;
                                default:
                                    continue;

                            }

                            Enemy monster = new Enemy((w * TileEngine.TILE_SIZE)+16-(width/2), (h * TileEngine.TILE_SIZE)+16-(height/2), width, height, type);
                            game_state.monster_engine.AddMonster(monster);
                        }

                        t.setTexture(-1);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void Remove(Enemy monster)
 {
     game_state.coll_engine.remove_object(monster.col_tok);
     monsters.Remove(monster);
 }
Ejemplo n.º 4
0
 public void AddMonster(Enemy monster)
 {
     //Request collision token and push monster to monster list
     monster.col_tok = game_state.coll_engine.register_object(monster, ColType.MONSTER);
     monsters.Add(monster);
 }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        //Two basic functions for the Monster engine
        actionDecision think(Enemy monster)
        {
            float[] ratings = new float[(int)actionDecision.NUM_ACTIONS];
            int dist_x = game_state.local_player.getX() - monster.getX();
            int dist_y = game_state.local_player.getY() - monster.getY();

            int Dp = GetRating(Math.Sqrt(Math.Pow(dist_x, 2) + Math.Pow(dist_y, 2)), 800.0f);
            int Db = 0; //Bullet system not in yet
            int Alg = 0;
            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                Alg = GetRating(Math.Abs(dist_x), 400);
            }
            else
            {
                Alg = GetRating(Math.Abs(dist_y), 240);
            }

            int Hlt = GetRating(monster.getHealth(), monster.getMaxHealth());

            actionDecision retval = actionDecision.FLEE;
            float max_value = 0;

            for (int i = 0; i < (int)actionDecision.NUM_ACTIONS; ++i)
            {
                ratings[i] =
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.DP]*Dp +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.DB]*Db +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.AL]*Alg +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.HL]*Hlt;

                if (ratings[i] > max_value)
                {
                    retval = (actionDecision)i;
                    max_value = ratings[i];
                }
            }

            if (max_value < 5)
            {
                return actionDecision.IDLE;
            }
            return retval;
        }
Ejemplo n.º 7
0
        //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));
        }
Ejemplo n.º 8
0
        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;
            }
             * */
        }
Ejemplo n.º 9
0
 void evade(Enemy monster)
 {
     //Place holder till bullet system works
 }
Ejemplo n.º 10
0
 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
 }
Ejemplo n.º 11
0
        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));
            }
        }
Ejemplo n.º 12
0
 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));
 }
Ejemplo n.º 13
0
        void act(Enemy monster, actionDecision action)
        {
            switch (action)
            {
                case actionDecision.FLEE:
                    flee(monster);
                    break;
                case actionDecision.ALIGN:
                    align(monster);
                    break;
                case actionDecision.ADVANCE:
                    advance(monster);
                    break;
                case actionDecision.EVADE:
                    evade(monster);
                    break;
                case actionDecision.FIRE:
                    fire(monster);
                    break;
                case actionDecision.IDLE:
                    idle(monster);
                    break;

            }
        }
Ejemplo n.º 14
0
 // 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));
 }
Ejemplo n.º 15
0
 // 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));
 }