예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 /// <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);
 }
예제 #7
0
파일: Game.cs 프로젝트: Vtek/Pulsar
        /// <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);
        }
예제 #8
0
        /// <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;
            }
        }
예제 #9
0
        /// <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;
            }
        }
예제 #10
0
        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";
        }
예제 #11
0
        /// <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));
            }
예제 #12
0
 // *** 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);
     }
 }
예제 #13
0
        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);
        }
예제 #14
0
        //**********************************************************

        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
파일: Level.cs 프로젝트: LifeOfTony/Tony
        /// <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);
            }
        }
예제 #17
0
        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);
        }
예제 #18
0
 public void AddItem(IDrawable8D drawable)
 {
     Drawables.Add(drawable);
 }
예제 #19
0
 /// <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);
 }
예제 #20
0
 /// <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);
 }
예제 #21
0
        public void AddRenderer(IDrawable drawable)
        {
            Drawables.Add(drawable);

            Drawables = Drawables.OrderBy(x => (int)(x.DrawOrder)).ToList();
        }
예제 #22
0
 internal void AddEnemy(AbstractEnemy e)
 {
     Drawables.Add(e);
 }
예제 #23
0
 internal void AddBullet(Bullet b)
 {
     totalBullets++;
     Drawables.Add(b);
 }
예제 #24
0
        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));
        }
예제 #25
0
 public void AddDrawableBase(DrawableBase drawable)
 {
     Drawables.Add(drawable);
 }