private bool TryAddSpecialDoor(MapTile tile, Point location) { DoorBase door; Direction direction; switch (tile) { case MapTile.DoorSpecialLeft2_1: door = new DoorSpecialLeft2_1(_dungeonManager, location); direction = Direction.Left; break; case MapTile.DoorSpecialRight3_1: door = new DoorSpecialRight3_1(_dungeonManager, location); direction = Direction.Right; break; default: return(false); } Doors.Add(direction, door); Drawables.Add(door); Collidables.Add(door); return(true); }
private bool TryAddBarrier(MapTile tile, Point location) { BlockType blockType; switch (tile) { case MapTile.InvisibleWall: blockType = BlockType.InvisibleBlock; break; case MapTile.BlackBarrier: blockType = BlockType.BlackBarrier; break; case MapTile.InvisibleProjectileBarrier: blockType = BlockType.InvisibleProjectileBarrier; break; default: return(false); } var barrier = new Barrier(location, blockType); Collidables.Add(barrier); Drawables.Add(barrier); return(true); }
private bool TryAddStair(MapTile tile, Point location) { BlockType blockType; switch (tile) { case MapTile.DungeonStairs: blockType = BlockType.DungeonStair; break; case MapTile.BasementStairs: blockType = BlockType.BasementStair; break; case MapTile.StairSpecialUp1_1: blockType = BlockType.StairSpecialUp1_1; break; default: return(false); } var stairs = new Stair(_dungeonManager, location, blockType); Collidables.Add(stairs); Drawables.Add(stairs); return(true); }
private bool TryAddNormalDoor(MapTile tile, Point location) { BlockType blockType; Direction direction; // ReSharper disable once SwitchStatementMissingSomeCases switch (tile) { case MapTile.DoorUp: blockType = BlockType.DoorUp; direction = Direction.Up; break; case MapTile.DoorDown: blockType = BlockType.DoorDown; direction = Direction.Down; break; default: return(false); } var door = new NormalDoor(_survivalManager, location, blockType); Doors.Add(direction, door); Drawables.Add(door); Collidables.Add(door); return(true); }
private bool TryAddNonStandardTiles(MapTile tile, Point location) { // ReSharper disable once SwitchStatementMissingSomeCases (cases are covered elsewhere) switch (tile) { case MapTile.Key: Items.Add(new Key(location, this)); break; case MapTile.Compass: Items.Add(new Compass(location)); break; case MapTile.Map: Items.Add(new Map(location)); break; case MapTile.Bow: Items.Add(new BowItem(location, Secondary.Bow, 10)); break; case MapTile.Triforce: Items.Add(new Triforce(location)); break; case MapTile.PushableBlock: var pushableBlock = new MovableBlock(location); Collidables.Add(pushableBlock); Drawables.Add(pushableBlock); TransitionResetables.Add(pushableBlock); break; case MapTile.SpawnEnemy: SpawnTiles.Add(location); break; case MapTile.Sand: Drawables.Add(new Overlay(location, BlockType.Sand)); break; case MapTile.Heart: Items.Add(new HeartContainer(location, this)); break; case MapTile.Boomerang: Items.Add(new BoomerangItem(location, this, 20)); break; case MapTile.BasementBricks: case MapTile.BlackOverlay: case MapTile.None: case MapTile.Room2_1Block: break; default: return(false); } return(true); }
/// <summary> /// Instantiates the cursor. /// Sets the cursor's layer. /// Offsets the cursor to be centered on it's position. /// </summary> private void CreateCursor() { _cursor = new Sprite(Content.Load <Texture2D>("cursor"), Vector2.Zero); _cursor.Layer = 1.0f; _cursor.SetOffset(Anchor.Center); Drawables.Add(_cursor); }
/// <summary> /// Add game module /// </summary> public Game AddModule <T>() where T : IModule { PulsarHost.Instance.Kernel.Bind <IModule> ().To <T> ().InSingletonScope(); var module = PulsarHost.Instance.Kernel.GetService(typeof(T)); var wasAdded = Modules.Any(x => x.GetType().IsInstanceOfType(module)); if (wasAdded) { throw new InvalidOperationException(string.Format("Module {0} already added", module.GetType())); } if (module is GameModule) { var gm = (GameModule)module; gm.GlobalData = GlobalData; gm.TempData = GlobalData; } Modules.Add((IModule)module); if (module is IDrawable) { Drawables.Add((IDrawable)module); } return(this); }
/// <summary> /// Adds sprite to game and puts it on field on board /// </summary> /// <param name="sprite"></param> public void AddObject(Sprite sprite) { var spritePosition = sprite.GetPosition(); if (IsPositionValid(spritePosition)) { Drawables.Add(sprite); Fields[spritePosition.X, spritePosition.Y].Sprite = sprite; } }
/// <summary> /// Creates a series of 10 blocks centered on the screen. /// </summary> private void CreatePlatform() { Vector2 blockPosition = new Vector2(352f, 500f); for (int x = 0; x < 10; x++) { _blocks.Add(new Block(Content.Load <Texture2D>("BlockA0"), blockPosition)); Drawables.Add(_blocks.Last()); blockPosition.X += 64f; } }
public override void LoadContent(ContentManager content) { // TODO: This should be generic, it should not have access to the Content of the Game. StaticImage image = new StaticImage( content.Load <Texture2D>("Misc/Zone"), new Rectangle(0, 0, _width, _height)); image.Origin = new Vector2(0, 0); GameDrawableInstance instance = Drawables.Add("Standard", image, "Body"); instance.Color = new Color(1.0f, 1.0f, 1.0f, 0.5f); instance.Layer = 0; CurrentDrawableState = "Standard"; }
/// <summary> /// Add a transition between the two given states. /// If a transition already exists a TransitionAlreadyExistsException is thrown. /// </summary> /// <param name="start">State to transition from</param> /// <param name="end">State to transition to</param> /// <param name="id">ID to give the transition</param> /// <param name="label">The label (determines how to transition)</param> /// <exception cref="TransitionAlreadyExistsException"></exception> public void AddTransition(State start, State end, int id, string label) { // check if this transition already exists if (!Drawables.Exists(x => ((x is Transition t) && (((t.StartPoint.Id == start.Id) && (t.EndPoint.Id == end.Id)) || (t.Id == id))))) { Transition transition = new Transition { Id = id, StartPoint = start, EndPoint = end, Label = label, Z = Drawables.Count + 1 }; Drawables.Add(transition); Drawables.Sort((x, y) => (y.Z - x.Z)); }
// *** Updated in Assignment 3: Section2 ****************************** public void Add <T>(T component) where T : Component { Remove <T>(); component.GameObject = this; component.Transform = Transform; Components.Add(typeof(T), component); if (component is IUpdateable) { Updatables.Add(component as IUpdateable); } if (component is IRenderable) { Renderables.Add(component as IRenderable); } if (component is IDrawable) { Drawables.Add(component as IDrawable); } }
private bool TryAddProjectilPassthroughBarrier(MapTile tile, Point location) { BlockType blockType; switch (tile) { case MapTile.Fire: blockType = BlockType.Fire; break; case MapTile.Water: blockType = BlockType.Water; break; case MapTile.FishStatue: blockType = BlockType.FishStatue; break; case MapTile.DragonStatue: blockType = BlockType.DragonStatue; break; case MapTile.ImmovableBlock: blockType = BlockType.ImmovableBlock; break; case MapTile.InvisibleProjectileBarrier: blockType = BlockType.InvisibleProjectileBarrier; break; default: return(false); } var barrier = new ProjectilePassthroughBarrier(location, blockType); Collidables.Add(barrier); Drawables.Add(barrier); return(true); }
//********************************************************** public T Add <T>() where T : Component, new() { Remove <T>(); T component = new T(); component.GameObject = this; component.Transform = Transform; Components.Add(typeof(T), component); if (component is IUpdateable) { Updatables.Add(component as IUpdateable); } if (component is IRenderable) { Renderables.Add(component as IRenderable); } if (component is IDrawable) { Drawables.Add(component as IDrawable); } return(component); }
private bool TryAddLockedDoor(MapTile tile, Point location) { BlockType blockType; Direction direction; // ReSharper disable once SwitchStatementMissingSomeCases switch (tile) { case MapTile.DoorLockedRight: blockType = BlockType.DoorLockedRight; direction = Direction.Right; break; case MapTile.DoorLockedLeft: blockType = BlockType.DoorLockedLeft; direction = Direction.Left; break; case MapTile.DoorLockedUp: blockType = BlockType.DoorLockedUp; direction = Direction.Up; break; case MapTile.DoorLockedDown: blockType = BlockType.DoorLockedDown; direction = Direction.Down; break; default: return(false); } var door = new LockedDoor(_dungeonManager, location, blockType); Doors.Add(direction, door); Drawables.Add(door); Collidables.Add(door); return(true); }
/// <summary> /// AddObject is called to add a new GameObject to the Objects list. /// </summary> /// public void AddObject(GameObject newObject) { Objects.Add(newObject); // Adds to Drawables if drawable. if (newObject is Drawable drawable) { Drawables.Add(drawable); } // Adds to Collidables if collidable. if (newObject is Collider) { Collidables.Add(newObject); } if (newObject is Player) { Player = (Player)newObject; } if (newObject is Npc) { Npcs.Add((Npc)newObject); } if (newObject is EndObject) { End = (EndObject)newObject; } if (newObject is Event) { Events.Add((Event)newObject); } }
private bool TryAddBombableWall(MapTile tile, Point location) { BlockType blockType; Direction direction; switch (tile) { case MapTile.DoorBombableLeft: blockType = BlockType.BombableWallLeft; direction = Direction.Right; break; case MapTile.DoorBombableRight: blockType = BlockType.BombableWallRight; direction = Direction.Left; break; case MapTile.DoorBombableUp: blockType = BlockType.BombableWallTop; direction = Direction.Up; break; case MapTile.DoorBombableDown: blockType = BlockType.BombableWallBottom; direction = Direction.Down; break; default: return(false); } var door = new BombDoor(_dungeonManager, location, blockType); Doors.Add(direction, door); Drawables.Add(door); Collidables.Add(door); return(true); }
public void AddItem(IDrawable8D drawable) { Drawables.Add(drawable); }
/// <summary> /// Creates an instance of the player. /// </summary> private void CreatePlayer() { _player = new Player(Content.Load <Texture2D>("megaman"), new Vector2(623f, 300f)); Drawables.Add(_player); }
/// <summary> /// Instantiates the grass sprite and puts it on the bottomost layer of the scene. /// </summary> private void CreateGrass() { _grass = new Sprite(Content.Load <Texture2D>("grass"), Vector2.Zero); _grass.Layer = 0.0f; Drawables.Add(_grass); }
public void AddRenderer(IDrawable drawable) { Drawables.Add(drawable); Drawables = Drawables.OrderBy(x => (int)(x.DrawOrder)).ToList(); }
internal void AddEnemy(AbstractEnemy e) { Drawables.Add(e); }
internal void AddBullet(Bullet b) { totalBullets++; Drawables.Add(b); }
internal void Tick(int frame) { for (int i = 0; i < frame; i++) { Ship.SpeedX = 0; Ship.SpeedY = 0; if (IsKeyDown(VirtualKey.Left)) { Ship.SpeedX = -Ship.Speed; } if (IsKeyDown(VirtualKey.Right)) { Ship.SpeedX = Ship.Speed; } if (IsKeyDown(VirtualKey.Up)) { Ship.SpeedY = -Ship.Speed; } if (IsKeyDown(VirtualKey.Down)) { Ship.SpeedY = Ship.Speed; } if (IsKeyDown(VirtualKey.Space)) { Bullet b = new Bullet(Ship.X + Ship.Width / 2, Ship.Y + Ship.Height / 2); AddBullet(b); keyMap[VirtualKey.Space] = false; PlaySound?.Invoke(SoundEffect.Shoot); } Message.Tick(); foreach (Drawable e in Drawables.ToArray()) { e.Tick(); Rect r = e.Rect; r.Intersect(Field); if (!e.IsValid || r.IsEmpty) { Drawables.Remove(e); } if (e is AbstractEnemy) { AbstractEnemy enemy = (AbstractEnemy)e; if (enemy.IsFire) { CreateEnemyBullet(enemy); } if (Crash(e, Ship)) { Ship.IsValid = false; Message.Text = "GAME OVER"; PlaySound?.Invoke(SoundEffect.Blast); } } } foreach (Bullet b in Bullets) { if (b.IsEnemy) { if (Crash(b, Ship)) { Ship.IsValid = false; Message.Text = "GAME OVER"; PlaySound?.Invoke(SoundEffect.Blast); } continue; } foreach (AbstractEnemy e in Enemies) { if (Crash(b, e) && b.IsValid && e.IsValid) { e.IsValid = false; b.IsValid = false; Blast blast = new Blast(b.X + b.Width / 2, b.Y + b.Height / 2); Drawables.Add(blast); PlaySound?.Invoke(SoundEffect.Blast); } } } } Ship.Y = Math.Max(0, Math.Min(Field.Height - Ship.Height, Ship.Y)); Ship.X = Math.Max(0, Math.Min(Field.Width - Ship.Width, Ship.X)); }
public void AddDrawableBase(DrawableBase drawable) { Drawables.Add(drawable); }