Exemple #1
0
        public bool check_map_col(int pot_x, int pot_y, int width, int height)
        {
            TileLayer back_layer = game_state.tile_engine.getCurrentMap().getLayer(LayerType.BACKGROUND);
            //Convert from world coords to tile coords

            //Bottom Left
            int tile_x = (pot_x + 5) / game_state.tile_engine.getTileSize();
            int tile_y = (pot_y + height) / game_state.tile_engine.getTileSize();

            if (tile_x < 0 || tile_x >= back_layer.getWidth())
            {
                return(true);
            }

            if (tile_y < 0 || tile_y >= back_layer.getHeight())
            {
                return(true);
            }


            Tile t = back_layer.getTile(tile_x, tile_y);

            if (t.hasCollision() == true)
            {
                return(true);
            }

            //Bottom Right
            tile_x = (pot_x + width - 10) / game_state.tile_engine.getTileSize();
            tile_y = (pot_y + height) / game_state.tile_engine.getTileSize();

            t = back_layer.getTile(tile_x, tile_y);
            if (t.hasCollision() == true)
            {
                return(true);
            }

            return(false);
        }
        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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }