public override void MousePressed(MouseState mouseState, Vector2 offset) { PlatformerEditor actualGame = (PlatformerEditor)UIManager.Game; if (mouseState.MiddlePressed()) { PanIsPressed = true; } else if (mouseState.LeftPressed()) { Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y) - offset - Position - SoftOffset; if (actualGame.CurrentWorldLayer != null) { WorldItem item = new WorldItem(UIManager, actualGame.CurrentWorldItemType, SnapPosition(mousePos), actualGame.CurrentWorldLayer.DrawLayer); actualGame.CurrentWorldLayer.WorldItems.Add(item); } } else if (mouseState.RightPressed()) { if (actualGame.CurrentWorldLayer != null) { Vector2 mousePos = GetMousePosition(offset); for (int i = 0; i < actualGame.CurrentWorldLayer.WorldItems.Count; i++) { WorldItem item = actualGame.CurrentWorldLayer.WorldItems[i]; if (PlatformerMath.PointInRectangle(new Rectangle(item.Position.ToPoint(), item.Size.ToPoint()), mousePos)) { actualGame.CurrentWorldLayer.WorldItems.RemoveAt(i); break; } } } } base.MousePressed(mouseState, offset); }
public PreparedMaObject(Room room, Vector2 position) : base(room, position) { Vector2 viewSize = new Vector2(Room.Engine.Game.GraphicsDevice.Viewport.Width, Room.Engine.Game.GraphicsDevice.Viewport.Height); Light = new Light(viewSize / 2); Font = null; Text = PlatformerMath.Choose("Ready or not, here I come.", "I'm coming.", "Are you ready?", "Are you prepared?", "I hope you're prepared to die."); TextOpacity = 0; Timer = MaxTimer; Persistent = true; Room.Engine.Assets.RequestFont("fnt_main", (font) => { Font = font; Text = Text; }); Light = new Light(viewSize / 2); Room.Engine.Assets.RequestTexture("lgt_circular", (tex) => { Light.Sprite.Change(tex); Light.Sprite.Size = new Vector2(384, 256); Light.Sprite.Offset = -Light.Sprite.Size / 2; Light.Color = new Color(255, 102, 102); }); Room.LightList.Add(Light); }
public Room GetRandomDungeonRoom() { string filename = "Levels\\dungeon"; filename += PlatformerMath.Choose("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") + ".json"; return((new Room(Engine)).Load(filename)); }
public override void Update() { GameObject coll = Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position), "obj_player"); if (coll != null) { if (Room.FindObject("obj_fairy") == null && Room.FindObject("obj_boss") == null) { if (!HasPlayedSound) { Room.Sounds.PlaySound(levelCompleteSound); HasPlayedSound = true; } Room nextRoom = new Room(Room.Engine); //find the room number if (Room.CurrentFileName.Substring(0, 12).Equals("Levels/level")) { int endInd = Room.CurrentFileName.IndexOf('.'); string numStr = Room.CurrentFileName.Substring(12, endInd - 12); int num = Convert.ToInt32(numStr); nextRoom.Load("Levels/level" + (num + 1) + ".json"); Room.Engine.ChangeRoom(nextRoom); } } } base.Update(); }
/*public void ChangeHitbox(Rectangle rect) * { * Hitbox = rect; * }*/ public override void Update() { GameObject coll = Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position), "obj_player"); if (coll != null) { ((PlayerObject)coll).Damage(1); } base.Update(); }
public override void Scroll(MouseState mouseState, float amount) { Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y) - Position; for (int i = Elements.Count - 1; i >= 0; i--) { UIElement elem = Elements[i]; if (PlatformerMath.PointInRectangle(new Rectangle(elem.Position.ToPoint(), elem.Size.ToPoint()), mousePos)) { elem.Scroll(mouseState, amount); } } base.Scroll(mouseState, amount); }
public override void Use(PlayerObject player) { MouseState mouseState = Mouse.GetState(); float dir = (float)Math.Atan2(mouseState.Y - (player.Position.Y + player.Room.ViewPosition.Y), mouseState.X - (player.Position.X + player.Room.ViewPosition.X)); ProjectileObject proj = new ProjectileObject(player.Room, player.Position, dir, 8, Damage, "obj_enemy", "obj_boss"); proj.TimeToLive = 10; proj.Sprite.Change(SwipeTexture); proj.Sprite.Angle = dir; proj.Sprite.Size = new Vector2(16, 32); proj.Sprite.Origin = proj.Sprite.Size / 2; player.Room.GameObjectList.Add(proj); player.Room.Sounds.PlaySound(SwipeSounds[PlatformerMath.Choose(0, 1, 2)], 1); }
public override void Use(PlayerObject player) { MouseState mouseState = Mouse.GetState(); float dir = (float)Math.Atan2(mouseState.Y - (player.Position.Y + player.Room.ViewPosition.Y), mouseState.X - (player.Position.X + player.Room.ViewPosition.X)); ProjectileObject proj = new ProjectileObject(player.Room, player.Position, dir, 6, Damage, "obj_enemy", "obj_boss"); proj.TimeToLive = 150; proj.Sprite.Change(MagicBallTexture); proj.Sprite.Size = new Vector2(32, 32); proj.Sprite.Offset = -proj.Sprite.Size / 2; proj.Sprite.Speed = 0.3f; player.Room.GameObjectList.Add(proj); player.Room.Sounds.PlaySound(MagicSounds[PlatformerMath.Choose(0, 1)], 1); }
public override void MouseReleased(MouseState mouseState, Vector2 offset) { Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y) - Position - SoftOffset; for (int i = Elements.Count - 1; i >= 0; i--) { UIElement elem = Elements[i]; if (PlatformerMath.PointInRectangle(new Rectangle(elem.Position.ToPoint(), elem.Size.ToPoint()), mousePos)) { elem.MouseReleased(mouseState, offset); break; } } base.MouseReleased(mouseState, offset); }
public override void Load(AssetManager assets) { assets.RequestTexture(PlatformerMath.Choose("spr_dirt", "spr_dirt2"), (tex) => { Sprite.Change(tex); }); bool left = Room.CheckTileAt(Position - new Vector2(Sprite.Size.X, 0)); bool right = Room.CheckTileAt(Position + new Vector2(Sprite.Size.X, 0)); bool top = Room.CheckTileAt(Position - new Vector2(0, Sprite.Size.Y)); bool bottom = Room.CheckTileAt(Position + new Vector2(0, Sprite.Size.Y)); LayerData nextLayer = new LayerData(Sprite.LayerData.Layer + 1); //todo if (!bottom) { GameTile tl = new DirtSideBottomTile(Room, Position); tl.Sprite.LayerData = nextLayer; Room.GameTileList.Add(tl); } if (!top) { GameTile tl = new DirtSideTopTile(Room, Position); tl.Sprite.LayerData = nextLayer; Room.GameTileList.Add(tl); } if (!left) { GameTile tl = new DirtSideLeftTile(Room, Position); tl.Sprite.LayerData = nextLayer; Room.GameTileList.Add(tl); } if (!right) { GameTile tl = new DirtSideRightTile(Room, Position); tl.Sprite.LayerData = nextLayer; Room.GameTileList.Add(tl); } }
public GameOverObject(Room room, Vector2 position) : base(room, position) { Font = null; Text = PlatformerMath.Choose("I don't think you were prepared.", "Back to the hole where you belong.", "Are you even trying?", "Time's up.", "Even SCP-999 would stand a better chance than you."); TextOpacity = 0; }
public override void Update() { if (cooldown > 0) { cooldown--; } if (animationindex == -10) { goingUp = true; } if (animationindex == 14) { goingUp = false; } if (goingUp) { animationindex++; } else { animationindex--; } Vector2 vel = Velocity; PlayerObject reimu = (PlayerObject)Room.FindObject("reimu"); if (moving) { if (facingRight) { vel.X = MoveSpeed; } else { vel.X = -MoveSpeed; } if ((Math.Pow(Position.X - reimu.Position.X, 2) + Math.Pow(Position.Y - reimu.Position.Y, 2)) < (400 * 400)) { if (cooldown <= 0) { moving = false; } } } else { Rectangle hitbox = reimu.GetHitbox(); Vector2 size = new Vector2(hitbox.Width, hitbox.Height); Vector2 playerPos = reimu.Position + (size / 2); Vector2 fairyPos = Position + (size / 2); /*Vector2 fairyOnScreenPos = fairyPos - Room.ViewOffset; * Vector2 playerRelativePos = playerPos - fairyOnScreenPos;*/ float dir = (float)Math.Atan2(playerPos.Y - Position.Y, playerPos.X - Position.X); ProjectileObject proj = new ProjectileObject(Room, fairyPos, dir, 3, 1, "obj_player"); proj.TimeToLive = 1000; proj.Sprite.Change(BulletSprite); proj.Sprite.Angle = dir; proj.Sprite.Size = new Vector2(16, 16); proj.Sprite.Origin = proj.Sprite.Size / 2; proj.Sprite.Offset = -(new Vector2(Sprite.Size.X / 2, Sprite.Size.Y / 2 + (Sprite.Size.Y - Sprite.Size.X) / 2)); Room.GameObjectList.Add(proj); Room.Sounds.PlaySound(ShootSound); moving = true; cooldown = 60; } Velocity = vel; if (Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(1, 0)), "obj_block") != null) { facingRight = false; } if (Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(-1, 0)), "obj_block") != null) { facingRight = true; } if (Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(0, 1)), "obj_block") != null && !(Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(-1, 1)), "obj_block") != null)) { facingRight = true; } if (Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(0, 1)), "obj_block") != null && !(Room.FindCollision(PlatformerMath.AddVectorToRect(GetHitbox(), Position, new Vector2(1, 1)), "obj_block") != null)) { facingRight = false; } base.Update(); }
public GameWinObject(Room room, Vector2 position) : base(room, position) { Font = null; Text = PlatformerMath.Choose("Surely you must be cheating?", "I didn't expect that.", "Game over. For me. I guess."); TextOpacity = 0; }