Example #1
0
        public void AddTriggerFromMapData(AddTriggerType triggertype, Color c, int x, int y, AbstractMarioPower p)
        {
            double px = x * Block.BLOCK_WIDTH;
            double py = y * Block.BLOCK_HEIGHT;

            if (triggertype == AddTriggerType.PLAYER_SPAWN_POSITION || triggertype == AddTriggerType.PLAYER_INITIAL_SPAWN_POSITION)
            {
                PlayerSpawnZone zone = new PlayerSpawnZone(new Vec2i(x, y));
                AddTrigger(zone, x, y);

                if (triggertype == AddTriggerType.PLAYER_INITIAL_SPAWN_POSITION)
                {
                    (HUD as StandardGameHUD).Reset();
                    player = zone.SpawnPlayer();
                }
                else
                {
                    player = zone.SpawnPlayer(p);
                }
            }
            else if (triggertype == AddTriggerType.DEATH_ZONE)
            {
                AddTrigger(new DeathZone(new Vec2i(x, y)), x, y);
            }
            else if (triggertype == AddTriggerType.LEVEL_WRAP)
            {
                AddTrigger(new LevelWrapZone(new Vec2i(x, y), c.B), x, y);
            }
            else if (triggertype == AddTriggerType.BRIDGE_DESTROY)
            {
                AddTrigger(new BridgeDestroyZone(new Vec2i(x, y)), x, y);
            }
            else if (triggertype == AddTriggerType.BEANSTALK_SPAWN)
            {
                AddTrigger(new BeanStalkSpawnZone(new Vec2i(x, y)), x, y);
            }
            else if (triggertype == AddTriggerType.TELEPORT_ENTRY)
            {
                AddTrigger(new TeleportEntryZone(new Vec2i(x, y), c.R), x, y);
            }
            else if (triggertype == AddTriggerType.TELEPORT_EXIT)
            {
                AddTrigger(new TeleportExitZone(new Vec2i(x, y), c.R), x, y);
            }
            else if (triggertype == AddTriggerType.TEXTURE_CHANGE)
            {
                AddTrigger(new TextureChangeZone(new Vec2i(x, y), c.G), x, y);
            }
            else if (triggertype == AddTriggerType.SPAWN_LOGO)
            {
                AddTrigger(new SpawnLogoZone(new Vec2i(x, y)), x, y);
            }
            else if (triggertype == AddTriggerType.SWITCH_ZOOM)
            {
                AddTrigger(new SwitchZoomZone(new Vec2i(x, y)), x, y);
            }
            else if (triggertype == AddTriggerType.PLAYER_GROW)
            {
                AddTrigger(new GrowPlayerZone(new Vec2i(x, y)), x, y);
            }
        }
Example #2
0
        public void LoadMapFromResources(AbstractMarioPower p)
        {
            ImageMapParser parser = new ImageMapParser(new OpenRasterImage(ResourceAccessor.GetMap(mapWorld, mapLevel)));

            setSize(parser.GetWidth(), parser.GetHeight());

            for (int x = 0; x < parser.GetWidth(); x++)
            {
                for (int y = 0; y < parser.GetHeight(); y++)
                {
                    int imgX = x;
                    int imgY = parser.GetHeight() - (1 + y);

                    Color col_b = parser.map.GetColor(ImageMapParser.LAYER_BLOCKS, imgX, imgY);
                    Color col_e = parser.map.GetColor(ImageMapParser.LAYER_ENTITIES, imgX, imgY);
                    Color col_t = parser.map.GetColor(ImageMapParser.LAYER_TRIGGER, imgX, imgY);
                    Color col_p = parser.map.GetColor(ImageMapParser.LAYER_PIPEZONES, imgX, imgY);
                    Color col_v = parser.map.GetColor(ImageMapParser.LAYER_PLAYERVISION, imgX, imgY);

                    Block               block = parser.GetBlock(imgX, imgY);
                    EntityTypeWrapper   set   = parser.GetEntity(imgX, imgY);
                    AddTriggerType      att   = parser.GetTrigger(imgX, imgY);
                    PipeZoneTypeWrapper pzt   = parser.GetPipeZone(imgX, imgY);

                    if (block == null)
                    {
                        throw new NotSupportedException(String.Format("Could not parse Block-Color in Map: {0} ({1}|{2})", col_b, x, y));
                    }
                    else
                    {
                        AddBlock(block, x, y);
                    }

                    if (set == null)
                    {
                    }    // No Entity
                    else if (!set.IsSet())
                    {
                        throw new NotSupportedException(String.Format("Could not parse SpawnEntity-Color in Map: {0} ({1}|{2})", col_e, x, y));
                    }
                    else
                    {
                        SpawnEntityFromMapData(set, col_e, x, y);
                    }

                    if (att == AddTriggerType.UNKNOWN_TRIGGER)
                    {
                        throw new NotSupportedException(String.Format("Could not parse Trigger-Color in Map: {0} ({1}|{2})", col_t, x, y));
                    }
                    else if (att != AddTriggerType.NO_TRIGGER)
                    {
                        AddTriggerFromMapData(att, col_t, x, y, p);
                    }

                    if (pzt == null)
                    {
                    }    // No Zone
                    else if (!pzt.IsSet())
                    {
                        throw new NotSupportedException(String.Format("Could not parse PipeZone-Color in Map: {0} ({1}|{2})", col_p, x, y));
                    }
                    else
                    {
                        AddPipeZoneFromMapData(pzt, x, y);
                    }
                }
            }

            offset.AddVisionBoxes(parser.GetVisionZones());

            //#############
            //AFTER MAP GEN
            //#############

            offset.Calculate(player.GetPosition(), viewPortWidth, viewPortHeight, mapRealWidth, mapRealHeight, false, false);
            foreach (DynamicEntity e in dynamicEntityList)
            {
                e.OnAfterMapGen();
            }

            foreach (Trigger t in triggerList)
            {
                t.OnAfterMapGen();
            }
        }