public static void CheckSpiked() { object[] spikes = (spikes_in_contact.ToArray()); Player p = GameEngine.Instance.currentLevel.player; Vector2 ppos = p.Body.Position; float pw = p.width / 2; float ph = p.height / 2; float eps = 0.1f; int i = 0; foreach (object o in spikes) { Spike s = (Spike)(o); Vector2 spos = s.Body.Position; float sw = s.width / 2; float sh = s.height / 2; float diffX = ppos.X - spos.X; float diffY = ppos.Y - spos.Y; bool is_up = false; bool is_left = false; if (diffX < 0) { is_left = true; } if (diffY < 0) { is_up = true; } diffX = Math.Abs(diffX); diffY = Math.Abs(diffY); if (Math.Abs(ppos.X - spos.X) >= pw + sw || Math.Abs(ppos.Y - spos.Y) >= ph + sh) { spikes_in_contact.RemoveAt(i); i--; } else if (diffX < sw + pw - eps && diffY < sh + ph - eps) { if ((s.direction == ReflectableAndOrientable.Direction.Up && is_up) || (s.direction == ReflectableAndOrientable.Direction.Down && !is_up) || (s.direction == ReflectableAndOrientable.Direction.Left && is_left) || (s.direction == ReflectableAndOrientable.Direction.Right && !is_left)) { GameEngine.Instance.currentLevel.SetGameOver(false); GameEngine.Instance.achievement_state.death_by_spike(); //Achievement logic - 'failure is an option' } } i++; } }
public void AddSpike(Spike s) { this.AddQueuedObject(s); }
public static Level CreateTempLevel() { if (USE_XML_LEVEL) { return(LevelCreator.ParseLevelFromFile("Content\\Levels\\something.xml")); } else { groundTexture = Reflexio.GameEngine.Instance.Content.Load <Texture2D>("Images\\block"); playerTexture = Reflexio.GameEngine.Instance.Content.Load <Texture2D>("Images\\koala"); Level level = new Level(WIDTH, HEIGHT, new Vector2(0, 9.8f)); foreach (int[] platform_discrete in platforms_disc) { level.AddMultipleWalls(platform_discrete[0], platform_discrete[1], platform_discrete[2], platform_discrete[3], platform_discrete[2] - platform_discrete[0] != 19 && platform_discrete[3] - platform_discrete[1] != 19); } level.AddMultipleWalls(7, 2, 7, 2, true); level.AddMultipleWalls(8, 3, 8, 3, true); level.AddMultipleWalls(1, 15, 2, 15, false); level.AddMultipleWalls(2, 14, 2, 14, false); level.AddMultipleWalls(1, 13, 1, 13, false); level.AddMultipleWalls(1, 5, 2, 5, false); //level.AddQueuedObject(new Wall(level, groundTexture, 1, 1, 1.0f, 1.0f, 0.0f, true)); Door d = new Door(level, GameEngine.Instance.GetTexture("openDoorTexture"), GameEngine.Instance.GetTexture("closeDoorTexture"), 18, 14, 0, 0.0f, 0.0f, true); level.AddDoor(d); level.AddKey(new Key(level, GameEngine.Instance.GetTexture("keyTexture"), 8, 2, 0, 0.0f, 0.0f, false)); Texture2D[] spikesTextures = new Texture2D[4] { GameEngine.Instance.GetTexture("spikesUpTexture"), GameEngine.Instance.GetTexture("spikesRightTexture"), GameEngine.Instance.GetTexture("spikesDownTexture"), GameEngine.Instance.GetTexture("spikesLeftTexture") }; for (int i = 1; i <= 18; i++) { Spike s = new Spike(level, spikesTextures, 12, i, 0, 0.0f, 0.0f, true, Spike.Direction.Left); level.AddQueuedObject(s); } for (int i = 13; i <= 18; i++) { Spike s = new Spike(level, spikesTextures, i, 5, 0, 0.0f, 0.0f, true, Spike.Direction.Up); level.AddQueuedObject(s); } Block b = new Block(level, GameEngine.Instance.GetTexture("buddyBlock"), 2, 16, 1.5f, 1.0f, 0.0f, true); level.AddQueuedObject(b); //level.AddMultipleWalls(3, 17, 3, 17, true); //Spike sx = new Spike(level, spikesTextures, 17, 18, 0, 0.0f, 0.0f, true, Spike.Direction.Up); //level.AddQueuedObject(sx); DialogDisplay dd = new DialogDisplay(); dd.AddDialog("Welcome to Reflexio", 100); dd.AddDialog("Use WASDX to change the lines of reflection", 100); dd.AddDialog("Use SPACE to reflect", 100); dd.AddDialog("Get the key to open the door", 100); dd.AddDialog("All the best!", 100); dd.Initialize(); level.AddDialogDisplay(dd); level.AddPlayerTemp(1, 18); level.SetReflectionOrientation("H"); level.AddHRLine(10); level.AddVRLine(10); level.AddDLine(1); level.AddDLine(-1); level.SetCanReflectVertical(true); level.SetCanReflectDiagonal(true); level.SetReflectionLinePosition(10); return(level); } }
public static bool BeginContact(Contact contact) { if (GameEngine.Instance.currentLevel.is_peeking) { return(false); } var obj1 = contact.FixtureA.Body.UserData; var obj2 = contact.FixtureB.Body.UserData; var body1 = contact.FixtureA.Body; var body2 = contact.FixtureB.Body; var ud1 = contact.FixtureA.UserData; var ud2 = contact.FixtureB.UserData; if ((obj1 is Player && !(obj2 is Player)) || (obj2 is Player && !(obj1 is Player))) { Player p = obj1 is Player ? (Player)obj1 : (Player)obj2; var other = obj1 is Player ? obj2 : obj1; if (!objects_in_contact.Contains(other)) { objects_in_contact.Add(other); } if (other is Reflexio.Wall) { ReflectableObject obj = (ReflectableObject)other; if (CheckPlayerInsideObject(obj)) { GameEngine.Instance.currentLevel.SetGameOver(false); GameEngine.Instance.achievement_state.death_by_wall(); //Achievement Logic - 'failure is an option' } PlayerGroundedStart(contact); return(true); } // Collision with Block else if (other is Reflexio.Block) { ReflectableObject obj = (ReflectableObject)other; if (CheckPlayerInsideObject(obj)) { GameEngine.Instance.currentLevel.SetGameOver(false); GameEngine.Instance.achievement_state.death_by_block(); //Achievement logic - 'failure is an option' } PlayerGroundedStart(contact); return(true); } // Collision With collectible else if (other is Reflexio.Collectible) { if (!((Collectible)other).is_inside_non_reflectable_object) { ((Collectible)other).CollectedByPlayer(); } } // Collision with Spike else if (other is Reflexio.Spike) { Spike s = (Reflexio.Spike)other; if (spikes_in_contact.Contains(s)) { return(false); } if (CheckPlayerInsideObject((ReflectableObject)s)) { GameEngine.Instance.currentLevel.SetGameOver(false); GameEngine.Instance.achievement_state.death_by_spike_collision(); //Achievement logic - 'failure is an option' } bool consider = PlayerSpikeContactStarted(s); if (!consider) { return(false); } PlayerGroundedStart(contact); return(true); } // Collision with Door else if (other is Reflexio.Door) { Door d = (Reflexio.Door)other; if (d.IsOpen() && !d.is_inside_non_reflectable_object && CheckPlayerInsideObject(d)) { GameEngine.Instance.currentLevel.SetGameOver(true); //Achievement logic - speed achievements and completion achievements GameEngine.Instance.achievement_state.register_level_complete_time(GameEngine.Instance.currentLevelPos, GameEngine.Instance.currentLevelStopwatch.ElapsedMilliseconds); GameEngine.Instance.achievement_state.complete_level(GameEngine.Instance.currentLevelPos, GameEngine.Instance.currentLevel.buddydeath); AchievementState.toSaveFile(GameEngine.Instance.achievement_state.toSaveState()); } //else // PlayerGroundedStart(contact); return(false); } } if (obj1 is Switch && !(obj2 is Player) || obj2 is Switch && !(obj1 is Player)) { Switch s = obj1 is Switch ? (Switch)obj1 : (Switch)obj2; s.PressSwitch((PhysicsObject)(obj1 is Switch ? obj2 : obj1)); return(false); } if (obj1 is Block || obj2 is Block) { object other = obj1 is Block ? obj2 : obj1; return(!(other is Key || other is Switch)); } return(false); }