public override void LoadContent()
        {
            var viewportAdapter = new DefaultViewportAdapter(_graphicsDevice);

            _camera = new OrthographicCamera(viewportAdapter);

            _playerSprite = new PlayerSprite(LoadTexture(PlayerFighter),
                                             LoadAnimation(PlayerAnimationTurnLeft),
                                             LoadAnimation(PlayerAnimationTurnRight));

            _playerSprite.Position = new Vector2(0, 0);

            _scene = new Scene();
            _scene.AddGameObject(_playerSprite);
            _scene.IsVisible = true;
        }
示例#2
0
        internal GameObject(string name, GameObject parent = null, Vector2 position = null, float rotation = 0, Vector2 scale = null, Scene scene = null)
        {
            if (scene == null)
            {
                scene = GameBase.Instance.ActiveScene;
            }

            if (position == null)
            {
                position = new Vector2();
            }

            if (scale == null)
            {
                scale = new Vector2(1, 1);
            }

            ID = Guid.NewGuid();

            Name      = name;
            IsEnabled = true;

            this.components  = new List <GameObjectComponent>();
            this.renderables = new List <IRendering>();

            this.transform = new Transform(this, position, rotation, scale);

            Parent        = parent;
            this.children = new HashSet <GameObject>();

            if (GameBase.Instance.ActiveScene == null)
            {
                throw new GameStateException("Cannote create GameObject when no scene is active.");
            }

            scene.AddGameObject(this);

            this.isAlive = true;
        }
示例#3
0
        protected override void Fire(Vector3 direction, float projectileSpeed = 40f)
        {
            MeshObject projectileMesh = PrimitiveMeshes.Octahedron(Position, 0.5f, Assets.projectile4Texture);

            Scene.AddGameObject(new EnemyProjectile(projectileMesh, direction, projectileSpeed, damage));
        }
示例#4
0
        /// <summary>
        /// Starts game by showing menu and instantiating player
        /// </summary>
        public void Start()
        {
            // Create quitter object
            GameObject  quitter = new GameObject("Quitter");
            KeyObserver quitSceneKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.Escape });

            quitter.AddComponent(quitSceneKeyListener);
            quitter.AddComponent(new Quitter());
            _scene.AddGameObject(quitter);

            // Instance variables for player
            Role   role;
            string name;

            // Render Start menu with options
            _render.StartMenu(out role);
            name = _render.AssignName();

            // Instantiate dungeon with number of rooms
            Dungeon _dungeon;

            _dungeon = new Dungeon(_rnd.Next(2, 10), _rnd);
            _scene.AddGameObject(_dungeon);

            CreateDungeons(_scene);

            // Instantiate player
            char[,] playerSprite = { { 'O' } };
            _player = new Player(role, name);
            KeyObserver playerKeys = new KeyObserver(new ConsoleKey[]
            {
                ConsoleKey.W,
                ConsoleKey.A,
                ConsoleKey.S,
                ConsoleKey.D,
                ConsoleKey.C,
                ConsoleKey.E,
                ConsoleKey.Spacebar
            });

            _player.AddComponent(playerKeys);
            _player.AddComponent(new PlayerController());
            _player.AddComponent(new Transform(5f, _y / 6 + 1, 2f));
            _player.AddComponent(new ConsoleSprite(
                                     playerSprite, ConsoleColor.White, ConsoleColor.Blue));
            _player.AddComponent(new ObjectCollider());

            _scene.AddGameObject(_player);

            _scene.GameLoop(_frameLength);

            if (_player.Life <= 0)
            {
                // LOST
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Black;
                _render.Loser(_player);
            }
            if (_dungeon.CheckAliveDead())
            {
                // WIN
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Black;
                _render.Victory(_player);
            }
        }
示例#5
0
        /// <summary>
        /// Add components to objets that compose the dungeon
        /// </summary>
        /// <param name="scene"> Accepts a Scene to add the components to
        /// </param>
        private void CreateDungeons(Scene scene)
        {
            GameObject  go      = scene.FindGameObjectByName("Dungeon");
            Dungeon     dungeon = go as Dungeon;
            GameObject  walls;
            GameObject  aux = null;         // Get previous gameObject (walls)
            Transform   wallTrans;          // Get walls Transform
            Transform   auxTrans;           // Previous gameObject transform
            DungeonRoom auxRoom = null;     // Get previous gameObject (room)
            int         index   = 1;

            Dictionary <Vector2, ConsolePixel> wallPixels;

            // Element's sprites
            char[,] doors = { { ' ' } };
            char[,] enemy = { { '☠' } }; // ☠

            // Foreach room create wall
            foreach (DungeonRoom room in dungeon.Rooms)
            {
                walls = new GameObject("Walls" + index);

                ConsolePixel wallPixel =
                    new ConsolePixel(' ', ConsoleColor.White,
                                     ConsoleColor.DarkYellow);

                wallPixels = new Dictionary <Vector2, ConsolePixel>();

                // WALLS
                for (int x = 0; x < room.Dim.X; x++)
                {
                    wallPixels[new Vector2(x, 0)] = wallPixel;
                }
                for (int x = 0; x < room.Dim.X; x++)
                {
                    wallPixels[new Vector2(x, room.Dim.Y - 1)] = wallPixel;
                }
                for (int y = 0; y < room.Dim.Y; y++)
                {
                    wallPixels[new Vector2(0, y)] = wallPixel;
                }
                for (int y = 0; y < room.Dim.Y; y++)
                {
                    wallPixels[new Vector2(room.Dim.X - 1, y)] = wallPixel;
                }

                float xdim;
                float ydim;
                int   xpos;
                int   xpos2;
                int   ypos;
                int   ypos2;

                // First room walls
                if (aux == null && auxRoom == null)
                {
                    xdim = 1;
                    ydim = _y / 6;

                    walls.AddComponent(new ConsoleSprite(wallPixels));
                    walls.AddComponent(new Transform(xdim, ydim, 1f));

                    xpos  = (int)xdim;
                    xpos2 = (int)xdim;
                    ypos  = (int)ydim;
                    ypos2 = (int)ydim;

                    // COLLIDERS
                    for (int x = 0; x < room.Dim.X; x++)
                    {
                        walls.AddComponent(new ObjectCollider(
                                               new Vector2(xpos, ydim)));
                        xpos++;
                        //Console.Write($"Col {x}: {xpos}, {ydim}");
                    }
                    for (int x = 0; x < room.Dim.X; x++)
                    {
                        walls.AddComponent(new ObjectCollider(
                                               new Vector2(xpos2, ydim + room.Dim.Y - 1)));
                        xpos2++;
                    }
                    for (int y = 0; y < room.Dim.Y; y++)
                    {
                        walls.AddComponent(new ObjectCollider(
                                               new Vector2(xdim, ypos)));
                        ypos++;
                    }
                    for (int y = 0; y < room.Dim.Y; y++)
                    {
                        walls.AddComponent(new ObjectCollider(
                                               new Vector2(xdim + room.Dim.X - 1, ypos2)));
                        ypos2++;
                    }

                    aux     = walls;
                    auxRoom = room;
                }
                else
                {
                    auxTrans = aux.GetComponent <Transform>();

                    // X of room is taken from the previus walls
                    // and room dimensions
                    xdim = Math.Clamp(
                        auxTrans.Pos.X + auxRoom.Dim.X - 1, 0, _x - 2);

                    // Y of room is taken from the previus walls and doors
                    // In relation with the center of the current room
                    ydim = auxTrans.Pos.Y + (auxRoom.Dim.Y / 2)
                           - (room.Dim.Y / 2);

                    // Make sure the room doesn't get out of bounds
                    if (auxTrans.Pos.X + auxRoom.Dim.X + room.Dim.X <= _x)
                    {
                        // Add the sprite and transform to assign position
                        walls.AddComponent(new ConsoleSprite(wallPixels));
                        walls.AddComponent(new Transform(xdim, ydim, 1f));

                        xpos  = (int)xdim;
                        xpos2 = (int)xdim;
                        ypos  = (int)ydim;
                        ypos2 = (int)ydim;

                        // COLLIDERS
                        for (int x = 0; x < room.Dim.X; x++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xpos, ydim)));
                            xpos++;
                        }
                        for (int x = 0; x < room.Dim.X; x++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xpos2, ydim + room.Dim.Y - 1)));
                            xpos2++;
                        }
                        for (int y = 0; y < room.Dim.Y; y++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xdim, ypos)));
                            ypos++;
                        }
                        for (int y = 0; y < room.Dim.Y; y++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xdim + room.Dim.X - 1, ypos2)));
                            ypos2++;
                        }
                    }
                    else
                    {
                        xdim = 1;
                        ydim = _y / 2;

                        walls.AddComponent(new ConsoleSprite(wallPixels));
                        walls.AddComponent(new Transform(xdim, ydim, 1f));

                        xpos  = (int)xdim;
                        xpos2 = (int)xdim;
                        ypos  = (int)ydim;
                        ypos2 = (int)ydim;

                        // COLLIDERS
                        for (int x = 0; x < room.Dim.X; x++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xpos, ydim)));
                            xpos++;
                        }
                        for (int x = 0; x < room.Dim.X; x++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xpos2, ydim + room.Dim.Y - 1)));
                            xpos2++;
                        }
                        for (int y = 0; y < room.Dim.Y; y++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xdim, ypos)));
                            ypos++;
                        }
                        for (int y = 0; y < room.Dim.Y; y++)
                        {
                            walls.AddComponent(new ObjectCollider(
                                                   new Vector2(xdim + room.Dim.X - 1, ypos2)));
                            ypos2++;
                        }
                    }

                    aux     = walls;
                    auxRoom = room;
                }

                scene.AddGameObject(walls);

                wallTrans = walls.GetComponent <Transform>();

                // DOORS IN ROOM
                for (int i = 0; i < room.Doors.Length; i++)
                {
                    // Assign door name
                    room.Doors[i].Name += i;
                    room.Doors[i].Name += index;

                    // Add sprite to door
                    room.Doors[i].AddComponent(new ConsoleSprite(
                                                   doors, ConsoleColor.White, ConsoleColor.Yellow));

                    if (i % 2 == 0)
                    {
                        // Add transform corresponding to the room it's in - X
                        room.Doors[i].AddComponent(
                            new Transform(wallTrans.Pos.X,
                                          wallTrans.Pos.Y + (room.Dim.Y / 2), 2));
                    }
                    else
                    {
                        // Add transform corresponding to the room it's in - Y
                        room.Doors[i].AddComponent(
                            new Transform(wallTrans.Pos.X + (room.Dim.X / 2),
                                          wallTrans.Pos.Y + room.Dim.Y - 1, 2));
                    }

                    scene.AddGameObject(room.Doors[i]);
                }

                // ENEMIES IN ROOM
                for (int i = 0; i < room.Enemies.Length; i++)
                {
                    int enemyX = Convert.ToInt32
                                     (wallTrans.Pos.X + (room.Dim.X / 2) + i);
                    int enemyY = Convert.ToInt32
                                     (wallTrans.Pos.Y + (room.Dim.Y / 2));

                    room.Enemies[i].Name += i;
                    room.Enemies[i].Name += index;

                    room.Enemies[i].AddComponent(new ConsoleSprite(
                                                     enemy, ConsoleColor.White, ConsoleColor.Red));

                    room.Enemies[i].AddComponent(
                        new Transform(enemyX, enemyY, 2f));

                    room.Enemies[i].AddComponent(
                        new ObjectCollider());

                    room.Enemies[i].AddComponent(new EnemyController(_rnd));

                    scene.AddGameObject(room.Enemies[i]);
                }

                index++;
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X = 100,

                Y            = 100,
                WindowWidth  = 1280,
                WindowHeight = 720,
                WindowTitle  = "Tortuga Demo"
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                debug: false,
                swapchainDepthFormat: PixelFormat.R16_UNorm,
                syncToVerticalBlank: true,
                resourceBindingModel: ResourceBindingModel.Improved,
                preferDepthRangeZeroToOne: true,
                preferStandardClipSpaceYDirection: true);

#if DEBUG
            options.Debug = true;
#endif
            var scene = new Scene();

            var types = new VoxelTypes(new[]
            {
                new VoxelType(
                    "DarkStone",
                    new Vector2(390, 1690),
                    new Vector2(390, 1690),
                    new Vector2(390, 1690)),
                new VoxelType(
                    "Metal",
                    new Vector2(650, 1300),
                    new Vector2(650, 1300),
                    new Vector2(650, 1300)),
                new VoxelType(
                    "Thruster",
                    new Vector2(650, 1170),
                    new Vector2(650, 1300),
                    new Vector2(650, 1300))
            });

            var resourceLoader        = new ResourceLoader();
            var voxelTexturesResource = resourceLoader.LoadImage("Assets\\spritesheet_tiles.png");

            var mesh3dMaterial        = new Material(Mesh3d.VertexCode, Mesh3d.FragmentCode);
            var voxelMaterialInstance = new MaterialInstance(mesh3dMaterial, voxelTexturesResource, new ObjectProperties()
            {
                Colour = RgbaFloat.White
            });

            var noCullingMaterial      = new Material(Mesh3d.VertexCode, Mesh3d.UnlitFragmentCode, true);
            var noCullingVoxelMaterial = new MaterialInstance(noCullingMaterial, voxelTexturesResource, new ObjectProperties()
            {
                Colour = RgbaFloat.White
            });

            //var cross = QuadCrossFactory.Build(new Rectangle(390, 130, 128, 128), true, noCullingVoxelMaterial);
            //cross.Name = "Cross";
            //scene.AddGameObject(cross);

            var tools = new Tool[]
            {
                new RemoveVoxelEditingTool()
                {
                    Name = "Remove"
                },
                new BasicVoxelAddingTool("DarkStone", 0, types, voxelMaterialInstance),
                new BasicVoxelAddingTool("Metal", 1, types, voxelMaterialInstance),
                new ThrusterVoxelEditingTool(new Rectangle(390, 130, 128, 128), noCullingVoxelMaterial, 2, types, voxelMaterialInstance)
                {
                    Name = "Thruster"
                }
            };

            var px = Image.Load("Assets\\skybox_px.png");
            var nx = Image.Load("Assets\\skybox_nx.png");
            var py = Image.Load("Assets\\skybox_py.png");
            var ny = Image.Load("Assets\\skybox_ny.png");
            var pz = Image.Load("Assets\\skybox_pz.png");
            var nz = Image.Load("Assets\\skybox_nz.png");

            var camera = new GameObject("Player");
            camera.Transform.Position = new Vector3(0, 0, 3);
            camera.AddComponent(new Camera());
            camera.AddComponent(new Character());
            camera.AddComponent(new CharacterInput());
            camera.AddComponent(new ComponentSwitcher(tools));
            //camera.AddComponent(new EditorMenu());
            //camera.AddComponent(new Inspector());
            //camera.AddComponent(new Clunker.Editor.Console.Console());
            camera.AddComponent(new Skybox(px, nx, py, ny, pz, nz));
            scene.AddGameObject(camera);

            var ship = CreateShip(types, voxelMaterialInstance);

            scene.AddGameObject(ship);

            //camera.AddComponent(new ObjectFollower() { ToFollow = ship, Distance = new Vector3(0.5f, 1, 6) });

            var chunkSize = 32;

            var worldSpaceObj = new GameObject("World Space");
            var worldSpace    = new VoxelSpace(new Vector3i(chunkSize, chunkSize, chunkSize), 1);
            worldSpaceObj.AddComponent(worldSpace);
            scene.AddGameObject(worldSpaceObj);

            var worldSystem = new WorldSystem(
                camera,
                worldSpace,
                new ChunkStorage(),
                new ChunkGenerator(types, voxelMaterialInstance, chunkSize, 1),
                10, chunkSize);

            scene.AddSystem(worldSystem);
            scene.AddSystem(new PhysicsSystem());

            var app = new ClunkerApp(resourceLoader, scene);

            app.Start(wci, options).Wait();
        }
示例#7
0
        protected override PopulateRoomResults PopulateRoom(Scene scene, Zone zone, int x, int y, PopulateSchemeFlags flags)
        {
            PopulateRoomResults results = new PopulateRoomResults
            {
                GenerateFloor = true
            };

            float   left       = x * tileSize - size * tileSize / 2;
            float   right      = left + tileSize;
            float   bottom     = y * tileSize - size * tileSize / 2;
            float   top        = bottom + tileSize;
            Vector3 roomCenter = new Vector3((left + right) / 2, 0f, (top + bottom) / 2);

            bool[] roomCorridors = Enumerable.Range(0, 4).Select(t => corridorLayout[x, y, t]).ToArray();

            if ((x != exitRoom.X || y != exitRoom.Y) && (x != size / 2 || y != size / 2))
            {
                int monsterCount = rand.Next(2, monstersPerRoom + 1);
                game.PlayerStats.totalMonsters += monsterCount;
                List <Vector3> spawnPoints = new List <Vector3>();
                Vector2        shift       = monsterCount == 1 ? Vector2.Zero : new Vector2(30f, 0f);
                float          angleOffset = (float)(rand.NextDouble() * Math.PI * 2f);
                for (int i = 0; i < monsterCount; i++)
                {
                    Vector2 position = new Vector2(roomCenter.X, roomCenter.Z);
                    position += Vector2.Transform(shift, Mathg.RotationMatrix2D(angleOffset + i * (float)Math.PI * 2f / monsterCount));
                    Vector3 position3 = new Vector3(position.X, -1f, position.Y);

                    Monster monster = Mathg.DiscreteChoiceFn(rand, new Func <Monster>[]
                    {
                        () => new BasicMonster(position3, monsterHP, monsterDamage),
                        () => new BasicMonster(position3, monsterHP, monsterDamage),
                        () => new ShotgunDude(position3, monsterHP, monsterDamage),
                        () => new SpinnyBoi(position3, monsterHP * 2, monsterDamage),
                        () => new Spooper(position3, monsterHP * 1.5f, monsterDamage)
                    }, monsterChances);

                    scene.AddGameObject(monster);
                }
            }



            if (rand.Next(7) == 0)
            {
                SceneStructures.PitWithBridges(FloorTexture, WallTexture, FloorTexture, roomCorridors).Invoke(scene, zone, roomCenter);
                SceneGenUtils.AddFloor(zone, -50f * Vector2.One, 50f * Vector2.One, -10f, Assets.lavaTexture, true, roomCenter, 75f);
                results.GenerateFloor = false;
            }
            else if (rand.Next(3) == 0)
            {
                if (x != size / 2 || y != size / 2)
                {
                    SpawnPools(scene, x, y, roomCenter, flags);
                }

                List <Generator> generators = new List <Generator>
                {
                    SceneStructures.Pillars4Inner(WallTexture),
                    SceneStructures.Pillars4Outer(WallTexture)
                };

                if (flags.ClearCenter)
                {
                    generators.Add(SceneStructures.PillarBig(WallTexture));
                    generators.Add(SceneStructures.PillarSmall(WallTexture));
                }

                Mathg.DiscreteChoice(rand, generators).Invoke(scene, zone, roomCenter);
            }

            return(results);
        }
示例#8
0
        /// <summary>
        /// Creates the first Level GameObjects.
        /// </summary>
        private void CreateLevel()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Escape };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Create walls
            GameObject   walls     = new GameObject("Walls");
            ConsolePixel wallPixel = new ConsolePixel(
                ' ', ConsoleColor.Blue, ConsoleColor.DarkGray);
            Dictionary <Vector2, ConsolePixel> wallPixels =
                new Dictionary <Vector2, ConsolePixel>();

            for (int x = 0; x < xdim; x++)
            {
                // Ground and walls
                if ((x > 0 && x < 25) ||
                    (x > 30 && x < 127) ||
                    (x > 135 && x < xdim))
                {
                    wallPixels[new Vector2(x, ydim - 1)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 1));
                    wallPixels[new Vector2(x, ydim - 2)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 2));
                    wallPixels[new Vector2(x, ydim - 3)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 3));
                    wallPixels[new Vector2(x, ydim - 4)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 4));
                    wallPixels[new Vector2(x, ydim - 5)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 5));
                    wallPixels[new Vector2(x, ydim - 6)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 6));
                    wallPixels[new Vector2(x, ydim - 7)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 7));
                }

                // Platform
                if (x > 30 && x < 45)
                {
                    wallPixels[new Vector2(x, ydim - 18)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 18));
                }
            }

            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(0, y)] = wallPixel;
                occupied.Add(new Vector2(0, y));
                wallPixels[new Vector2(xdim - 1, y)] = wallPixel;
                occupied.Add(new Vector2(xdim - 1, y));
            }

            // Create obstacles
            GameObject   obstacle      = new GameObject("Obstacle");
            ConsolePixel obstaclePixel = new ConsolePixel(
                ' ', ConsoleColor.Blue, ConsoleColor.Green);
            Dictionary <Vector2, ConsolePixel> obstaclePixels =
                new Dictionary <Vector2, ConsolePixel>();

            obstaclePixels[new Vector2(49, 19)] = obstaclePixel;
            occupied.Add(new Vector2(49, 19));

            obstaclePixels[new Vector2(52, 19)] = obstaclePixel;
            occupied.Add(new Vector2(52, 19));

            obstaclePixels[new Vector2(50, 20)] = obstaclePixel;
            occupied.Add(new Vector2(50, 20));

            obstaclePixels[new Vector2(50, 21)] = obstaclePixel;
            occupied.Add(new Vector2(50, 21));

            obstaclePixels[new Vector2(50, 19)] = obstaclePixel;
            occupied.Add(new Vector2(50, 19));

            obstaclePixels[new Vector2(50, 22)] = obstaclePixel;
            occupied.Add(new Vector2(50, 22));

            obstaclePixels[new Vector2(51, 20)] = obstaclePixel;
            occupied.Add(new Vector2(51, 20));

            obstaclePixels[new Vector2(51, 21)] = obstaclePixel;
            occupied.Add(new Vector2(51, 21));

            obstaclePixels[new Vector2(51, 19)] = obstaclePixel;
            occupied.Add(new Vector2(51, 19));

            obstaclePixels[new Vector2(51, 22)] = obstaclePixel;
            occupied.Add(new Vector2(51, 22));

            walls.AddComponent(new ConsoleSprite(wallPixels));
            walls.AddComponent(new Position(0, 0, 1));
            gameScene.AddGameObject(walls);

            obstacle.AddComponent(new ConsoleSprite(obstaclePixels));
            obstacle.AddComponent(new Position(0, 0, 0));
            gameScene.AddGameObject(obstacle);

            // Create game object for showing score
            GameObject score = new GameObject("Score");

            score.AddComponent(new Position(1, 0, 10));
            score.AddComponent(new Score());
            RenderableStringComponent visualScore = new RenderableStringComponent(
                () => "Score: " + 3000.ToString(),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta,
                ConsoleColor.White);

            score.AddComponent(visualScore);
            gameScene.AddGameObject(score);

            // Create Coin Sprite
            char[,] coinSprite =
            {
                { '█' },
            };

            // Coin 1
            GameObject coin1 = new GameObject("Coin1");

            coin1.AddComponent(new ConsoleSprite(coinSprite));
            coin1.AddComponent(new Position(80, 19, 0f));
            coin1.AddComponent(new CoinConfirmation());
            gameScene.AddGameObject(coin1);
            coins.Add(coin1);

            // Coin 2
            GameObject coin2 = new GameObject("Coin2");

            coin2.AddComponent(new ConsoleSprite(coinSprite));
            coin2.AddComponent(new Position(35, 8, 0f));
            coin2.AddComponent(new CoinConfirmation());
            gameScene.AddGameObject(coin2);
            coins.Add(coin2);

            // Box sprite
            char[,] boxSprite =
            {
                { '█', '█', '█', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '█', '█', '█' },
            };

            // Create Box1
            GameObject box = new GameObject("Box");

            box.AddComponent(new ConsoleSprite(
                                 boxSprite,
                                 ConsoleColor.Yellow,
                                 ConsoleColor.DarkGray));
            box.AddComponent(new Position(100, 8, 0f));
            box.AddComponent(new BoxConfirmation());
            gameScene.AddGameObject(box);
            boxes.Add(box);

            // Create Box2
            GameObject box2 = new GameObject("Box2");

            box2.AddComponent(new ConsoleSprite(
                                  boxSprite,
                                  ConsoleColor.Yellow,
                                  ConsoleColor.DarkGray));
            box2.AddComponent(new Position(150, 8, 0f));
            box2.AddComponent(new BoxConfirmation());
            gameScene.AddGameObject(box2);
            boxes.Add(box2);

            // Create dead text
            GameObject dead = new GameObject("Dead");

            dead.AddComponent(new Position(70, 10, 10));
            RenderableStringComponent deadString = new RenderableStringComponent(
                () => string.Empty,
                i => new Vector2(i, 0),
                ConsoleColor.Red,
                ConsoleColor.Gray);

            dead.AddComponent(deadString);
            gameScene.AddGameObject(dead);

            // Create player object
            // ─▄████▄▄
            // ▄▀█▀▐└─┐
            // █▄▐▌▄█▄┘
            // └▄▄▄▄▄┘
            char[,] playerSprite =
            {
                { '─', '▄', '█', '└' },
                { '▄', '▀', '▄', '▄' },
                { '█', '█', '▐', '▄' },
                { '█', '▀', '▐', '▄' },
                { '█', '▐', '▄', '▄' },
                { '█', '└', '█', '▄' },
                { '▄', '─', '▄', '┘' },
                { '▄', '┐', '┘', ' ' },
            };

            // Create player
            GameObject  player            = new GameObject("Player");
            KeyObserver playerKeyListener = new KeyObserver(
                new ConsoleKey[] {
                ConsoleKey.RightArrow,
                ConsoleKey.Spacebar,
                ConsoleKey.UpArrow,
                ConsoleKey.LeftArrow,
                ConsoleKey.Escape,
            });

            player.AddComponent(playerKeyListener);
            Position playerPos = new Position(1f, 19f, 0f);

            player.AddComponent(playerPos);
            player.AddComponent(new Player(
                                    occupied,
                                    score.GetComponent <Score>(),
                                    boxes,
                                    coins,
                                    dead,
                                    1));
            player.AddComponent(new ConsoleSprite(
                                    playerSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(player);

            // Create game object for showing time limit
            GameObject time = new GameObject("Time");

            time.AddComponent(new Position(190, 0, 10));
            time.AddComponent(new Time());
            RenderableStringComponent visualTime = new RenderableStringComponent(
                () => "Time: " + 200.ToString(),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta,
                ConsoleColor.White);

            time.AddComponent(visualTime);
            gameScene.AddGameObject(time);
        }
示例#9
0
        /// <summary>
        /// Совершить выстрел ракетой.
        /// </summary>
        protected void Shoot()
        {
            Inventory  inventory = controlledObject.GetComponent("inventory") as Inventory;
            GameObject rocket    = inventory.GetRocket();

            if (rocket == null)
            {
                return;
            }

            Transform transform = controlledObject.GetComponent("transform") as Transform;
            Texture2D texture   = controlledObject.GetComponent("texture") as Texture2D;
            Texture2D rocketTex = rocket.GetComponent("texture") as Texture2D;

            float x = rocketTex.Width * transform.Scale.X;
            float y = rocketTex.Height * transform.Scale.Y;

            Vector2 spawnPoint = new Vector2(
                -texture.Width * transform.Scale.X,
                -texture.Height * transform.Scale.Y);

            spawnPoint = new Vector2(
                (float)(Math.Cos(transform.Rotation *
                                 Math.Sign(transform.Scale.X)) * spawnPoint.X -
                        Math.Sin(transform.Rotation *
                                 Math.Sign(transform.Scale.X)) * spawnPoint.Y),
                (float)(Math.Sin(transform.Rotation *
                                 Math.Sign(transform.Scale.X)) * spawnPoint.X +
                        Math.Cos(transform.Rotation *
                                 Math.Sign(transform.Scale.X)) * spawnPoint.Y));

            Vector2 rocketPoint = new Vector2(
                (float)(Math.Cos(transform.Rotation *
                                 -Math.Sign(transform.Scale.X)) * -x -
                        Math.Sin(transform.Rotation *
                                 -Math.Sign(transform.Scale.X)) * -y),
                (float)(Math.Sin(transform.Rotation *
                                 -Math.Sign(transform.Scale.X)) * -x +
                        Math.Cos(transform.Rotation *
                                 -Math.Sign(transform.Scale.X)) * -y));

            spawnPoint.Y += texture.Height * transform.Scale.Y / 2;
            spawnPoint.X -= rocketPoint.X / 2;
            spawnPoint.Y -= rocketPoint.Y / 2;


            Transform rocketTransform = rocket.GetComponent("transform") as Transform;

            rocketTransform.Position = transform.Position + spawnPoint;
            rocketTransform.Rotation = transform.Rotation;
            rocketTransform.Scale    = transform.Scale;

            rocket.AddScript(new PhysicScript(
                                 new Vector2((float)(-Math.Sign(transform.Scale.X) * 15 * Math.Cos(transform.Rotation)),
                                             (float)(-15 * Math.Sin(transform.Rotation))),
                                 new Vector2(0, 0.2f)));

            scene.AddGameObject(rocket);

            Rocket rocketComponent = rocket.GetComponent("rocket") as Rocket;

            Cooldown   = rocketComponent.Cooldown;
            LastShoot  = 0;
            isCooldown = true;
        }
示例#10
0
        public override void OnCreated()
        {
            GameApplication.SetGameFrameTime(1);
            GameApplication.SetGameTickTime(16);
            GameApplication.SetLogger(new Logger(Path.Combine(GameApplication.AppDataGameRoot, "Logs"), "testGame"));
            GameApplication.Log(LogEntryType.Info, "Initializing Game...");
            //GameClient gameClient = new GameClient(this);
            //gameClient.Connect("127.0.0.1", 2000);
            //this.Controls.Add(Program.labelDebug);
            Random rnd = new Random();

            scene.AddAudioChannel(new craftersmine.GameEngine.Objects.AudioChannel("aud", cs.LoadAudio("aud")));
            //Program.labelDebug.Font = cs.LoadFont("andy", 9);
            scene.SetAudioChannelVolume("aud", 0.1f);
            scene.SetAudioChannelRepeat("aud", true);
            Gamepad.SetDeadzone(Player.First, DeadZoneControl.LeftTrigger, 0.0f);
            scene.SetBackgroundColor(Color.Black);
            this.AddScene(scene);
            scene.SetBackgroundTexture(cs.LoadTexture("bg", TextureLayout.Stretch));

            scene.AddGameObject(obj1);
            scene.AddGameObject(obj3);
            scene.AddGameObject(obj2);
            obj1.ApplyTexture(cs.LoadTexture("obj1", TextureLayout.Tile));
            obj3.ApplyTexture(cs.LoadTexture("obj1", TextureLayout.Tile));
            obj2.ApplyTexture(cs.LoadTexture("obj2", TextureLayout.Stretch));

            obj2.AddAnimation("anim", cs.LoadAnimation("anim"));

            //obj1.ApplyAnimation(cs.LoadAnimation("anim"));

            ShowScene(0);
            bordersGrads = new GameObject[4];
            for (int c = 0; c < 4; c++)
            {
                switch (c)
                {
                case 0:
                    bordersGrads[c] = new GameObject()
                    {
                        Height = this.Height, Width = 64, X = 0, Y = 0, IsCollidable = false
                    };
                    bordersGrads[c].ApplyTexture(gc1.LoadTexture("bordergrad-left", TextureLayout.Tile));
                    break;

                case 1:
                    bordersGrads[c] = new GameObject()
                    {
                        Height = 64, Width = this.Width, X = 0, Y = 0, IsCollidable = false
                    };
                    bordersGrads[c].ApplyTexture(gc1.LoadTexture("bordergrad-up", TextureLayout.Tile));
                    break;

                case 2:
                    bordersGrads[c] = new GameObject()
                    {
                        Height = this.Height, Width = 64, X = this.Width - 64, Y = 0, IsCollidable = false
                    };
                    bordersGrads[c].ApplyTexture(gc1.LoadTexture("bordergrad-right", TextureLayout.Tile));
                    break;

                case 3:
                    bordersGrads[c] = new GameObject()
                    {
                        Height = 64, Width = this.Width, X = 0, Y = this.Height - 64, IsCollidable = false
                    };
                    bordersGrads[c].ApplyTexture(gc1.LoadTexture("bordergrad-down", TextureLayout.Tile));
                    break;
                }
                scene.AddGameObject(bordersGrads[c]);
            }

            scene.AddRectangle(rectangleObject);
            scene.AddLabel(label);
            scene.PlayAudioChannel("aud");
        }
示例#11
0
        public bool Update(float deltaTime)
        {
            PlayerStats playerStats = game.PlayerStats;

            if (playerStats.dead)
            {
                return(false);
            }

            Scene scene = game.Scene;

            float sprintMultiplier = Controls.IsDown(Keybinds.sprint) ? 2.5f : 1f;

            Vector3 shift = Vector3.Zero;

            if (Controls.IsDown(Keybinds.forward))
            {
                shift += 20f * deltaTime * scene.Camera.Forward * sprintMultiplier;
            }
            if (Controls.IsDown(Keybinds.backwards))
            {
                shift -= 20f * deltaTime * scene.Camera.Forward;
            }
            if (Controls.IsDown(Keybinds.strafeRight))
            {
                shift += 15f * deltaTime * scene.Camera.Right;
            }
            if (Controls.IsDown(Keybinds.strafeLeft))
            {
                shift -= 15f * deltaTime * scene.Camera.Right;
            }

            float rotation = 0f;

            if (Controls.Scheme == ControlScheme.MouseKeyboard)
            {
                rotation += MathF.PI * 100f * deltaTime * Controls.MouseDelta();
            }
            else
            {
                if (Controls.IsDown(Keybinds.turnLeft))
                {
                    rotation -= 0.5f * MathF.PI * deltaTime * sprintMultiplier;
                }
                if (Controls.IsDown(Keybinds.turnRight))
                {
                    rotation += 0.5f * MathF.PI * deltaTime * sprintMultiplier;
                }
            }

            Vector3 realShift = scene.SmoothMovement(scene.Camera.CameraPos, shift, PlayerStats.thickness);

            scene.Camera.CameraPos += realShift;
            scene.Camera.Rotation  += rotation;

            int playerRoomX = (int)(scene.Camera.CameraPos.X / SceneGenerator.tileSize + SceneGenerator.size / 2f);
            int playerRoomY = (int)(scene.Camera.CameraPos.Z / SceneGenerator.tileSize + SceneGenerator.size / 2f);

            scene.Visited[playerRoomX, playerRoomY] = true;

            if (playerStats.tempHealth > 0f)
            {
                playerStats.tempHealth -= deltaTime * 0.2f;
                if (playerStats.tempHealth < 0f)
                {
                    playerStats.tempHealth = 0f;
                }
            }

            if (playerStats.shootTime > 0f)
            {
                playerStats.shootTime -= deltaTime;
            }

            if (playerStats.hit)
            {
                playerStats.hitTime -= deltaTime;
                if (playerStats.hitTime < 0f)
                {
                    playerStats.hitTime = 0f;
                    playerStats.hit     = false;
                }
            }

            playerStats.onFire = false;

            if (Controls.IsDown(Keybinds.fire) || (Controls.Scheme == ControlScheme.MouseKeyboard && Controls.IsLMBDown()))
            {
                if (playerStats.shootTime <= 0f)
                {
                    playerStats.shootTime = 1f / (3f + playerStats.skillShootingSpeed * 0.5f);
                    Assets.tsch.Play();

                    MeshObject projectileMesh = PrimitiveMeshes.Octahedron(scene.Camera.CameraPos + Vector3.Down, 0.4f, Assets.projectileTexture);
                    scene.AddGameObject(new Projectile(projectileMesh, scene.Camera.Forward, 75f, 2f));
                }
            }

            if (Controls.IsPressed(Keybinds.action))
            {
                if (Vector3.Distance(scene.Camera.CameraPos, new Vector3(playerStats.exitPosition.X, 0f, playerStats.exitPosition.Y)) < 7f &&
                    2 * playerStats.monsters >= playerStats.totalMonsters)
                {
                    if (playerStats.monsters < playerStats.totalMonsters)
                    {
                        playerStats.fullClear = false;
                    }
                    foreach (Collectible.Type?collectible in scene.Collectibles)
                    {
                        if (collectible != null)
                        {
                            playerStats.fullClear = false;
                        }
                    }

                    playerStats.floor++;
                    Achievements.UnlockLeveled("Level", playerStats.floor, game.HUD);

                    if (playerStats.fullClear)
                    {
                        Achievements.UnlockLeveled("100%", playerStats.floor - 1, game.HUD);
                    }

                    return(true);
                }
                else
                {
                    foreach (GameObject gameObject in scene.gameObjects)
                    {
                        if (gameObject is Collectible collectible && Vector3.Distance(scene.Camera.CameraPos, collectible.Position) < 7f)
                        {
                            collectible.PickUp(playerStats);
                        }
                    }
                }
            }

            if (playerStats.skillPoints > 0 && Controls.IsPressed(Keybinds.skills))
            {
                HUD.skillPointMenu = !HUD.skillPointMenu;
            }
            if (playerStats.skillPoints == 0)
            {
                HUD.skillPointMenu = false;
            }
            if (HUD.skillPointMenu)
            {
                if (Controls.IsPressed(Keybinds.skill1))
                {
                    playerStats.skillPoints--;
                    playerStats.skillMaxHealth++;
                    playerStats.maxHealth += 20f;
                    playerStats.AddHealth(20f);
                    Achievements.UnlockLeveled("HP", playerStats.skillMaxHealth, game.HUD);
                }
                else if (Controls.IsPressed(Keybinds.skill2))
                {
                    playerStats.skillPoints--;
                    playerStats.skillMaxArmor++;
                    playerStats.maxArmor += 20f;
                    playerStats.AddArmor(20f);
                    Achievements.UnlockLeveled("Armor", playerStats.skillMaxArmor, game.HUD);
                }
                else if (Controls.IsPressed(Keybinds.skill3) && playerStats.skillArmorProtection < 35)
                {
                    playerStats.skillPoints--;
                    playerStats.skillArmorProtection++;
                    playerStats.armorProtection += 0.02f;
                    Achievements.UnlockLeveled("AP", playerStats.skillArmorProtection, game.HUD);
                }
                else if (Controls.IsPressed(Keybinds.skill4))
                {
                    playerStats.skillPoints--;
                    playerStats.skillShootingSpeed++;
                    Achievements.UnlockLeveled("Speed", playerStats.skillShootingSpeed, game.HUD);
                }
            }

            return(false);
        }
示例#12
0
        private Game()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Escape };
            gameScene = new Scene(xdim, ydim,
                                  new InputHandler(quitKeys),
                                  new ConsoleRenderer(xdim, ydim, new ConsolePixel('.')),
                                  new CollisionHandler(xdim, ydim));

            // Create quitter object
            GameObject  quitter = new GameObject("Quitter");
            KeyObserver quitSceneKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.Escape });

            quitter.AddComponent(quitSceneKeyListener);
            quitter.AddComponent(new Quitter());
            gameScene.AddGameObject(quitter);

            // Create player object
            char[,] playerSprite =
            {
                { '-', '|', '-' },
                { '-', '0', '-' },
                { '-', '|', '-' }
            };
            GameObject  player            = new GameObject("Player");
            KeyObserver playerKeyListener = new KeyObserver(new ConsoleKey[] {
                ConsoleKey.DownArrow,
                ConsoleKey.UpArrow,
                ConsoleKey.RightArrow,
                ConsoleKey.LeftArrow
            });

            player.AddComponent(playerKeyListener);
            Position playerPos = new Position(10f, 10f, 0f);

            player.AddComponent(playerPos);
            player.AddComponent(new Player());
            player.AddComponent(new ConsoleSprite(
                                    playerSprite, ConsoleColor.Red, ConsoleColor.DarkGreen));
            gameScene.AddGameObject(player);

            // Create walls
            GameObject   walls     = new GameObject("Walls");
            ConsolePixel wallPixel = new ConsolePixel(
                '#', ConsoleColor.Blue, ConsoleColor.White);
            Dictionary <Vector2, ConsolePixel> wallPixels =
                new Dictionary <Vector2, ConsolePixel>();

            for (int x = 0; x < xdim; x++)
            {
                wallPixels[new Vector2(x, 0)] = wallPixel;
            }
            for (int x = 0; x < xdim; x++)
            {
                wallPixels[new Vector2(x, ydim - 1)] = wallPixel;
            }
            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(0, y)] = wallPixel;
            }
            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(xdim - 1, y)] = wallPixel;
            }
            walls.AddComponent(new ConsoleSprite(wallPixels));
            walls.AddComponent(new Position(0, 0, 1));
            gameScene.AddGameObject(walls);

            // Create game object for showing date and time
            GameObject dtGameObj = new GameObject("Time");

            dtGameObj.AddComponent(new Position(xdim / 2 + 1, 0, 10));
            RenderableStringComponent rscDT = new RenderableStringComponent(
                () => DateTime.Now.ToString("F"),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta, ConsoleColor.White);

            dtGameObj.AddComponent(rscDT);
            gameScene.AddGameObject(dtGameObj);

            // Create game object for showing position
            GameObject pos = new GameObject("Position");

            pos.AddComponent(new Position(1, 0, 10));
            RenderableStringComponent rscPos = new RenderableStringComponent(
                () => $"({playerPos.Pos.X}, {playerPos.Pos.Y})",
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta, ConsoleColor.White);

            pos.AddComponent(rscPos);
            gameScene.AddGameObject(pos);
        }
示例#13
0
        public void ToScene(Scene currentScene, MainCaches caches)
        {
            foreach (var obj in objects)
            {
                GameObject gameObject = GetGameObject(obj);
                if (obj.type == "mmdModel")
                {
                    string    pmxPath   = obj.path;
                    ModelPack modelPack = caches.GetModel(pmxPath);

                    gameObject.LoadPmx(modelPack);
                    var renderer       = gameObject.GetComponent <MMDRendererComponent>();
                    var animationState = gameObject.GetComponent <AnimationStateComponent>();
                    if (obj.skinning != null)
                    {
                        renderer.skinning = (bool)obj.skinning;
                    }
                    if (obj.enableIK != null)
                    {
                        renderer.enableIK = (bool)obj.enableIK;
                    }
                    if (obj.properties != null)
                    {
                        if (obj.properties.TryGetValue("motion", out string motion))
                        {
                            animationState.motionPath = motion;
                        }
                    }
                    if (obj.materials != null)
                    {
                        Mat2Mat(obj.materials, renderer.Materials);
                    }
                    currentScene.AddGameObject(gameObject);
                }
                else if (obj.type == "model")
                {
                    string    path      = obj.path;
                    ModelPack modelPack = caches.GetModel(path);

                    modelPack.LoadMeshComponent(gameObject);
                    var renderer = gameObject.GetComponent <MeshRendererComponent>();

                    if (obj.materials != null)
                    {
                        Mat2Mat(obj.materials, renderer.Materials);
                    }
                    currentScene.AddGameObject(gameObject);
                }
                else
                {
                    Caprice.Display.UIShowType uiShowType = default;
                    switch (obj.type)
                    {
                    case "lighting":
                        uiShowType = Caprice.Display.UIShowType.Light;
                        break;

                    case "decal":
                        uiShowType = Caprice.Display.UIShowType.Decal;
                        break;

                    case "particle":
                        uiShowType = Caprice.Display.UIShowType.Particle;
                        break;

                    default:
                        continue;
                    }
                    VisualComponent component = new VisualComponent();
                    component.UIShowType = uiShowType;
                    gameObject.AddComponent(component);
                    if (obj.visual != null)
                    {
                        component.material = Mat2Mat(obj.visual.material);
                    }
                    currentScene.AddGameObject(gameObject);
                }
            }
        }
示例#14
0
        /// <summary>
        /// Creates obstacles game  Objects.
        /// </summary>
        public void BuildObstacles()
        {
            GameObject   obstacle      = new GameObject("Obstacle");
            ConsolePixel obstaclePixel = new ConsolePixel(
                ' ', ConsoleColor.Blue, ConsoleColor.Green);
            Dictionary <Vector2, ConsolePixel> obstaclePixels =
                new Dictionary <Vector2, ConsolePixel>();

            // Obstacle GreenTube 1
            obstaclePixels[new Vector2(34, 19)] = obstaclePixel;
            occupied.Add(new Vector2(34, 19));

            obstaclePixels[new Vector2(37, 19)] = obstaclePixel;
            occupied.Add(new Vector2(37, 19));

            obstaclePixels[new Vector2(35, 20)] = obstaclePixel;
            occupied.Add(new Vector2(35, 20));

            obstaclePixels[new Vector2(35, 21)] = obstaclePixel;
            occupied.Add(new Vector2(35, 21));

            obstaclePixels[new Vector2(35, 19)] = obstaclePixel;
            occupied.Add(new Vector2(35, 19));

            obstaclePixels[new Vector2(35, 22)] = obstaclePixel;
            occupied.Add(new Vector2(35, 22));

            obstaclePixels[new Vector2(36, 20)] = obstaclePixel;
            occupied.Add(new Vector2(36, 20));

            obstaclePixels[new Vector2(36, 21)] = obstaclePixel;
            occupied.Add(new Vector2(36, 21));

            obstaclePixels[new Vector2(36, 19)] = obstaclePixel;
            occupied.Add(new Vector2(36, 19));

            obstaclePixels[new Vector2(36, 22)] = obstaclePixel;
            occupied.Add(new Vector2(36, 22));

            // Obstacle GreenTube 2
            obstaclePixels[new Vector2(54, 19)] = obstaclePixel;
            occupied.Add(new Vector2(54, 19));

            obstaclePixels[new Vector2(57, 19)] = obstaclePixel;
            occupied.Add(new Vector2(57, 19));

            obstaclePixels[new Vector2(55, 20)] = obstaclePixel;
            occupied.Add(new Vector2(55, 20));

            obstaclePixels[new Vector2(55, 21)] = obstaclePixel;
            occupied.Add(new Vector2(55, 21));

            obstaclePixels[new Vector2(55, 19)] = obstaclePixel;
            occupied.Add(new Vector2(55, 19));

            obstaclePixels[new Vector2(55, 22)] = obstaclePixel;
            occupied.Add(new Vector2(55, 22));

            obstaclePixels[new Vector2(56, 20)] = obstaclePixel;
            occupied.Add(new Vector2(56, 20));

            obstaclePixels[new Vector2(56, 21)] = obstaclePixel;
            occupied.Add(new Vector2(56, 21));

            obstaclePixels[new Vector2(56, 19)] = obstaclePixel;
            occupied.Add(new Vector2(56, 19));

            obstaclePixels[new Vector2(56, 22)] = obstaclePixel;
            occupied.Add(new Vector2(56, 22));

            // Obstacle GreenTube 3
            obstaclePixels[new Vector2(84, 19)] = obstaclePixel;
            occupied.Add(new Vector2(84, 19));

            obstaclePixels[new Vector2(87, 19)] = obstaclePixel;
            occupied.Add(new Vector2(87, 19));

            obstaclePixels[new Vector2(85, 20)] = obstaclePixel;
            occupied.Add(new Vector2(85, 20));

            obstaclePixels[new Vector2(85, 21)] = obstaclePixel;
            occupied.Add(new Vector2(85, 21));

            obstaclePixels[new Vector2(85, 19)] = obstaclePixel;
            occupied.Add(new Vector2(85, 19));

            obstaclePixels[new Vector2(85, 22)] = obstaclePixel;
            occupied.Add(new Vector2(85, 22));

            obstaclePixels[new Vector2(86, 20)] = obstaclePixel;
            occupied.Add(new Vector2(86, 20));

            obstaclePixels[new Vector2(86, 21)] = obstaclePixel;
            occupied.Add(new Vector2(86, 21));

            obstaclePixels[new Vector2(86, 19)] = obstaclePixel;
            occupied.Add(new Vector2(86, 19));

            obstaclePixels[new Vector2(86, 22)] = obstaclePixel;
            occupied.Add(new Vector2(86, 22));

            obstacle.AddComponent(new ConsoleSprite(obstaclePixels));
            obstacle.AddComponent(new Position(0, 0, 0));
            gameScene.AddGameObject(obstacle);
        }
示例#15
0
        /// <summary>
        /// Private method which makes the scene and put the following
        /// game objects on it for the menu.
        /// </summary>
        private void CreateMenu()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Enter };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Creates title
            char[,] titleSprite =
            {
                { '█', '█', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', '█', ' ', ' ', '█', ' ', ' ', ' ' },
                { '█', ' ', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', '█', ' ', '█', ' ', '█', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', ' ', ' ', '█', ' ', '█', '█', ' ' },
                { '█', '█', '█', ' ', ' ', ' ', '█', '█', '█', ' ', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', ' ', ' ', ' ', '█' },
                { '█', ' ', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', '█', ' ', '█', ' ', ' ', ' ', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', '█', ' ', ' ', '█', ' ', ' ', ' ', '█' },
                { '█', '█', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
            };
            GameObject title    = new GameObject("Title");
            Position   titlePos = new Position(65f, 3f, 0f);

            title.AddComponent(titlePos);
            title.AddComponent(new Title());
            title.AddComponent(new ConsoleSprite(
                                   titleSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(title);

            // Creates buttons
            char[,] buttonSprite1 =
            {
                { 'L' },
                { 'e' },
                { 'v' },
                { 'e' },
                { 'l' },
                { '1' },
            };
            char[,] buttonSprite2 =
            {
                { 'L' },
                { 'e' },
                { 'v' },
                { 'e' },
                { 'l' },
                { '2' },
            };
            char[,] buttonSprite3 =
            {
                { 'H' },
                { 'e' },
                { 'l' },
                { 'p' },
            };
            char[,] buttonSprite4 =
            {
                { 'Q' },
                { 'u' },
                { 'i' },
                { 't' },
            };
            GameObject button1    = new GameObject("Button1");
            GameObject button2    = new GameObject("Button2");
            GameObject button3    = new GameObject("Button3");
            GameObject button4    = new GameObject("Button4");
            Position   buttonPos1 = new Position(72f, 19f, 1f);
            Position   buttonPos2 = new Position(72f, 21f, 1f);
            Position   buttonPos3 = new Position(73f, 23f, 1f);
            Position   buttonPos4 = new Position(73f, 25f, 1f);

            button1.AddComponent(buttonPos1);
            button2.AddComponent(buttonPos2);
            button3.AddComponent(buttonPos3);
            button4.AddComponent(buttonPos4);
            button1.AddComponent(new ConsoleSprite(
                                     buttonSprite1, ConsoleColor.Red, ConsoleColor.Blue));
            button2.AddComponent(new ConsoleSprite(
                                     buttonSprite2, ConsoleColor.Red, ConsoleColor.Blue));
            button3.AddComponent(new ConsoleSprite(
                                     buttonSprite3, ConsoleColor.Red, ConsoleColor.Blue));
            button4.AddComponent(new ConsoleSprite(
                                     buttonSprite4, ConsoleColor.Red, ConsoleColor.Blue));
            gameScene.AddGameObject(button1);
            gameScene.AddGameObject(button2);
            gameScene.AddGameObject(button3);
            gameScene.AddGameObject(button4);

            // Creates indicator
            char[,] indicatorSprite =
            {
                { '>' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { '<' },
            };
            KeyObserver indicatorKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.UpArrow, ConsoleKey.DownArrow, ConsoleKey.Enter });
            GameObject indicator    = new GameObject("Indicator");
            Position   indicatorPos = new Position(70f, 19f, 0f);

            indicator.AddComponent(indicatorKeyListener);
            indicator.AddComponent(new Indicator());
            indicator.AddComponent(indicatorPos);
            indicator.AddComponent(new ConsoleSprite(
                                       indicatorSprite, ConsoleColor.Red, ConsoleColor.DarkBlue));
            gameScene.AddGameObject(indicator);
        }
示例#16
0
        /// <summary>
        /// Private method which makes the scene and put the following
        /// game objects on it for the help menu.
        /// </summary>
        private void CreateHelp()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Enter };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Creates help instruction
            char[,] instructionsSprite =
            {
                { 'M', ' ', 'J', ' ', 'S', ' ', 'E' },
                { 'o', ' ', 'u', ' ', 't', ' ', 'x' },
                { 'v', ' ', 'm', ' ', 'r', ' ', 'i' },
                { 'e', ' ', 'p', ' ', 'a', ' ', 't' },
                { 'm', ' ', ':', ' ', 'i', ' ', ' ' },
                { 'e', ' ', ' ', ' ', 'g', ' ', 'T' },
                { 'n', ' ', 'S', ' ', 't', ' ', 'o' },
                { 't', ' ', 'p', ' ', ' ', ' ', ' ' },
                { ':', ' ', 'a', ' ', 'J', ' ', 'M' },
                { ' ', ' ', 'c', ' ', 'u', ' ', 'a' },
                { 'A', ' ', 'e', ' ', 'm', ' ', 'i' },
                { 'r', ' ', ' ', ' ', 'p', ' ', 'n' },
                { 'r', ' ', '+', ' ', ':', ' ', ' ' },
                { 'o', ' ', ' ', ' ', ' ', ' ', 'M' },
                { 'w', ' ', 'L', ' ', 'A', ' ', 'e' },
                { 's', ' ', 'a', ' ', 'r', ' ', 'n' },
                { ' ', ' ', 's', ' ', 'r', ' ', 'u' },
                { 'L', ' ', 't', ' ', 'o', ' ', ':' },
                { 'e', ' ', ' ', ' ', 'w', ' ', ' ' },
                { 'f', ' ', 'p', ' ', ' ', ' ', 'E' },
                { 't', ' ', 'r', ' ', 'U', ' ', 's' },
                { ' ', ' ', 'e', ' ', 'p', ' ', 'c' },
                { 'a', ' ', 's', ' ', ' ', ' ', 'a' },
                { 'n', ' ', 's', ' ', 't', ' ', 'p' },
                { 'd', ' ', 'e', ' ', 'h', ' ', 'e' },
                { ' ', ' ', 'd', ' ', 'e', ' ', ' ' },
                { 'R', ' ', ' ', ' ', 'n', ' ', ' ' },
                { 'i', ' ', 'A', ' ', ' ', ' ', ' ' },
                { 'g', ' ', 'r', ' ', 'S', ' ', ' ' },
                { 'h', ' ', 'r', ' ', 'p', ' ', ' ' },
                { 't', ' ', 'o', ' ', 'a', ' ', ' ' },
                { ' ', ' ', 'w', ' ', 'c', ' ', ' ' },
                { ' ', ' ', ' ', ' ', 'e', ' ', ' ' },
            };
            GameObject instructions    = new GameObject("Instructions");
            Position   instructionsPos = new Position(60f, 10f, 0f);

            instructions.AddComponent(instructionsPos);
            instructions.AddComponent(new ConsoleSprite(
                                          instructionsSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(instructions);

            // Creates the button to return to the menu
            char[,] buttonSprite =
            {
                { 'B' },
                { 'a' },
                { 'c' },
                { 'k' },
            };
            GameObject button    = new GameObject("Button");
            Position   buttonPos = new Position(73f, 23f, 1f);

            button.AddComponent(buttonPos);
            button.AddComponent(new ConsoleSprite(
                                    buttonSprite, ConsoleColor.Red, ConsoleColor.Blue));
            gameScene.AddGameObject(button);

            // Creates the indicator to press the buttons
            char[,] indicatorSprite =
            {
                { '>' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { '<' },
            };
            KeyObserver indicatorKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.W, ConsoleKey.S, ConsoleKey.Enter });
            GameObject indicator    = new GameObject("Indicator");
            Position   indicatorPos = new Position(72f, 23f, 0f);

            indicator.AddComponent(indicatorKeyListener);
            indicator.AddComponent(new ReturnMenu());
            indicator.AddComponent(indicatorPos);
            indicator.AddComponent(new ConsoleSprite(
                                       indicatorSprite, ConsoleColor.Red, ConsoleColor.DarkBlue));
            gameScene.AddGameObject(indicator);
        }