예제 #1
0
        private bool hitTestPlayerVitals(Player pl)
        {
            Vector2 vitalsPos = pl.Position;
            vitalsPos.X += (pl.HitBox.X - pl.VitalsBox.X) / 2;
            vitalsPos.Y += (pl.HitBox.Y - pl.VitalsBox.Y) / 2;

            if (horizontal_pos > vitalsPos.X + pl.VitalsBox.X || horizontal_pos + width < vitalsPos.X || vertical_pos > vitalsPos.Y + pl.VitalsBox.Y || vertical_pos + height < vitalsPos.Y)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
예제 #2
0
        private void loadLevelThread()
        {
            #if XBOX
            Thread.CurrentThread.SetProcessorAffinity(Game1.loadThread);
            #endif

            Monitor.Enter(levelEntities);
            grabbed = true;

            if (Entity.globalEntityList != null)
            {
                Entity.globalEntityList.Clear();
                Entity.globalEntityList.TrimExcess();
            }

            tagLineA = "LEVEL " + (Game1.CurrentLevel + 1);
            tagLineB = Game1.levelNames[Game1.CurrentLevel];

            switch (Game1.CurrentLevel)
            {
                case 0:
                    parallax1 = null;
                    parallax2 = "cityParallax2";
                    parallax3 = "cityParallax3";
                    levelSong = "songs/song0";
                    break;
                case 1:
                    levelSong = "songs/song1";
                    parallax1 = null;
                    parallax2 = "cityParallax2";
                    parallax3 = "cityParallax3";
                    break;
                case 2:
                    levelSong = "songs/song2";
                    parallax1 = "sewerParallax3";
                    parallax2 = "sewerParallax2";
                    parallax3 = "sewerParallax1";
                    break;
                case 3:
                    levelSong = "songs/song3";
                    parallax1 = "factoryParallax1";
                    parallax2 = "factoryParallax2";
                    parallax3 = "factoryParallax3";
                    break;
                case 4:
                    levelSong = "songs/song4";
                    parallax1 = "factoryParallax1";
                    parallax2 = "factoryParallax2";
                    parallax3 = "sewerParallax1";
                    break;
                default:
                    break;
            }

            levelMap = contentManager.Load<Map>(levelName);

            foreach (ObjectLayer layer in levelMap.ObjectLayers)
            {
                foreach (MapObject obj in layer.MapObjects)
                {
                    Entity en = null;

                    switch (obj.Name)
                    {
                        case "player":
                            if (checkPointTouched == false)
                            {
                                en = new Player(obj.Bounds.X, obj.Bounds.Y);
                                checkPointTime = 0.0f;
                                levelRecordTime = 0;
                            }
                            else
                            {
                                en = new Player(respawnPosition.X, respawnPosition.Y);
                                levelRecordTime = checkPointTime;
                            }
                            levelEntities.Add(en);
                            levelCamera.setNewFocus(ref en);
                            break;
                        case "wm_pos":
                            levelEntities.Add(new WallMagnet(obj.Bounds.X, obj.Bounds.Y, Entity.Polarity.Positive));
                            break;
                        case "wm_neg":
                            levelEntities.Add(new WallMagnet(obj.Bounds.X, obj.Bounds.Y, Entity.Polarity.Negative));
                            break;
                        case "walker_pos":
                            levelEntities.Add(new Enemy(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "walker_neg":
                            levelEntities.Add(new Enemy(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "jumper_pos":
                            levelEntities.Add(new JumpingEnemy(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "factory_conveyer_left":
                            levelEntities.Add(new ConveyerBelt(obj.Bounds.X, obj.Bounds.Y, ConveyerBelt.ConveyerSpot.Left));
                            break;
                        case "factory_conveyer_mid":
                            levelEntities.Add(new ConveyerBelt(obj.Bounds.X, obj.Bounds.Y, ConveyerBelt.ConveyerSpot.Mid));
                            break;
                        case "factory_conveyer_right":
                            levelEntities.Add(new ConveyerBelt(obj.Bounds.X, obj.Bounds.Y, ConveyerBelt.ConveyerSpot.Right));
                            break;
                        case "spikes_up":
                            levelEntities.Add(new Spikes(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "angrySaw":
                            levelEntities.Add(new AngrySaw(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "lava":
                            levelEntities.Add(new Lava(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "lavaDumper":
                            if (obj.Properties.ContainsKey("interval"))
                            {
                                levelEntities.Add(new LavaDumper(obj.Bounds.X, obj.Bounds.Y, (double)(obj.Properties["interval"].AsSingle)));
                            }
                            else
                            {
                                levelEntities.Add(new LavaDumper(obj.Bounds.X, obj.Bounds.Y));
                            }
                            break;
                        case "endLevelFlag":
                            levelEntities.Add(new EndLevelFlag(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "lolrus":
                            levelEntities.Add(new Lolrus(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "wallEntity":
                            levelEntities.Add(new climbWall(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "shieldDudeRight":
                            levelEntities.Add(new ShieldDude(obj.Bounds.X, obj.Bounds.Y, true));
                            break;
                        case "shieldDudeLeft":
                            levelEntities.Add(new ShieldDude(obj.Bounds.X, obj.Bounds.Y, false));
                            break;
                        case "heartItem":
                            levelEntities.Add(new HealthItem(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "boss":
                            levelEntities.Add(new Boss(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "flagDoor":
                            if (obj.Properties["color"].Value == "blue")
                            {
                                levelEntities.Add(new FlagDoor(obj.Bounds.X, obj.Bounds.Y, FlagColor.Blue));
                            }
                            else if (obj.Properties["color"].Value == "green")
                            {
                                levelEntities.Add(new FlagDoor(obj.Bounds.X, obj.Bounds.Y, FlagColor.Green));
                            }
                            else if (obj.Properties["color"].Value == "red")
                            {
                                levelEntities.Add(new FlagDoor(obj.Bounds.X, obj.Bounds.Y, FlagColor.Red));
                            }
                            else if (obj.Properties["color"].Value == "yellow")
                            {
                                levelEntities.Add(new FlagDoor(obj.Bounds.X, obj.Bounds.Y, FlagColor.Yellow));
                            }
                            else if (obj.Properties["color"].Value == "purple")
                            {
                                levelEntities.Add(new FlagDoor(obj.Bounds.X, obj.Bounds.Y, FlagColor.Purple));
                            }
                            break;
                        case "flagLock":
                            if (obj.Properties["color"].Value == "blue")
                            {
                                levelEntities.Add(new FlagLock(obj.Bounds.X, obj.Bounds.Y, FlagColor.Blue));
                            }
                            else if (obj.Properties["color"].Value == "green")
                            {
                                levelEntities.Add(new FlagLock(obj.Bounds.X, obj.Bounds.Y, FlagColor.Green));
                            }
                            else if (obj.Properties["color"].Value == "red")
                            {
                                levelEntities.Add(new FlagLock(obj.Bounds.X, obj.Bounds.Y, FlagColor.Red));
                            }
                            else if (obj.Properties["color"].Value == "yellow")
                            {
                                levelEntities.Add(new FlagLock(obj.Bounds.X, obj.Bounds.Y, FlagColor.Yellow));
                            }
                            else if (obj.Properties["color"].Value == "purple")
                            {
                                levelEntities.Add(new FlagLock(obj.Bounds.X, obj.Bounds.Y, FlagColor.Purple));
                            }
                            break;
                        case "flagKey":
                            if (obj.Properties["color"].Value == "blue")
                            {
                                levelEntities.Add(new FlagKey(obj.Bounds.X, obj.Bounds.Y, FlagColor.Blue));
                            }
                            else if (obj.Properties["color"].Value == "green")
                            {
                                levelEntities.Add(new FlagKey(obj.Bounds.X, obj.Bounds.Y, FlagColor.Green));
                            }
                            else if (obj.Properties["color"].Value == "red")
                            {
                                levelEntities.Add(new FlagKey(obj.Bounds.X, obj.Bounds.Y, FlagColor.Red));
                            }
                            else if (obj.Properties["color"].Value == "yellow")
                            {
                                levelEntities.Add(new FlagKey(obj.Bounds.X, obj.Bounds.Y, FlagColor.Yellow));
                            }
                            else if (obj.Properties["color"].Value == "purple")
                            {
                                levelEntities.Add(new FlagKey(obj.Bounds.X, obj.Bounds.Y, FlagColor.Purple));
                            }
                            break;
                        case "tutorialSign":
                            if (obj.Properties["message"].Value == "message1")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)1));
                            }
                            else if (obj.Properties["message"].Value == "message2")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)2));
                            }
                            else if (obj.Properties["message"].Value == "message3")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)3));
                            }
                            else if (obj.Properties["message"].Value == "message4")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)4));
                            }
                            else if (obj.Properties["message"].Value == "message5")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)5));
                            }
                            else if (obj.Properties["message"].Value == "message6")
                            {
                                levelEntities.Add(new TutorialSign(obj.Bounds.X, obj.Bounds.Y, (TutorialSign.SignMessage)6));
                            }
                            break;
                        case "bossShield":
                            levelEntities.Add(new bossShield(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "walkMarker":
                            levelEntities.Add(new WalkMarker(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "goomba":
                            levelEntities.Add(new Goomba(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        case "flagCloseSwitch":
                            if (obj.Properties["color"].Value == "blue")
                            {
                                levelEntities.Add(new FlagCloseSwitch(obj.Bounds.X, obj.Bounds.Y, FlagColor.Blue));
                            }
                            else if (obj.Properties["color"].Value == "yellow")
                            {
                                levelEntities.Add(new FlagCloseSwitch(obj.Bounds.X, obj.Bounds.Y, FlagColor.Yellow));
                            }
                            else if (obj.Properties["color"].Value == "red")
                            {
                                levelEntities.Add(new FlagCloseSwitch(obj.Bounds.X, obj.Bounds.Y, FlagColor.Red));
                            }
                            else if (obj.Properties["color"].Value == "purple")
                            {
                                levelEntities.Add(new FlagCloseSwitch(obj.Bounds.X, obj.Bounds.Y, FlagColor.Purple));
                            }
                            else if (obj.Properties["color"].Value == "green")
                            {
                                levelEntities.Add(new FlagCloseSwitch(obj.Bounds.X, obj.Bounds.Y, FlagColor.Green));
                            }
                            break;
                        case "easterEgg":
                            levelEntities.Add(new EasterEgg(obj.Bounds.X, obj.Bounds.Y));
                            break;
                        default:
                            break;
                    }
                }
            }

            Thread.Sleep(1500);

            Monitor.Exit(levelEntities);
        }