Exemplo n.º 1
0
		public Game(Window window)
		{
			screenSpace = new Camera2DScreenSpace(window);
			screenSpace.Zoom = 1 / window.ViewportPixelSize.AspectRatio;
			gridSize = 25;
			blockSize = 1.0f / gridSize;
			this.window = window;
			menu = new Menu();
			menu.InitGame += StartGame;
			menu.Quit += window.CloseAfterFrame;
			window.ViewportSizeChanged +=
				size => screenSpace.Zoom = (size.AspectRatio > 1) ? 1 / size.AspectRatio : size.AspectRatio;
		}
Exemplo n.º 2
0
        /// <summary>
        /// 允许游戏在开始运行之前执行其所需的任何初始化。
        /// 游戏能够在此时查询任何所需服务并加载任何非图形
        /// 相关的内容。调用 base.Initialize 将枚举所有组件
        /// 并对其进行初始化。 
        /// </summary>
        protected override void Initialize()
        {
            // TODO: 在此处添加初始化逻辑
            currentState = GameState.main_menu;
            preState = GameState.main_menu;

            Components.Clear();
            Menu menu = new Menu(this);
            menu.Initialize();
            Components.Add(menu);

            base.Initialize();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 允许游戏在开始运行之前执行其所需的任何初始化。
        /// 游戏能够在此时查询任何所需服务并加载任何非图形
        /// 相关的内容。调用 base.Initialize 将枚举所有组件
        /// 并对其进行初始化。 
        /// </summary>
        protected override void Initialize()
        {
            // TODO: 在此处添加初始化逻辑
            TouchPanel.EnabledGestures = GestureType.VerticalDrag | GestureType.HorizontalDrag | GestureType.Tap;

            currentState = GameState.main_menu;
            preState = GameState.main_menu;
            sceneChangeLag = 0;

            Components.Clear();
            Menu menu = new Menu(this);
            menu.Initialize();
            Components.Add(menu);

            base.Initialize();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 允许游戏运行逻辑,例如更新全部内容、
        /// 检查冲突、收集输入信息以及播放音频。
        /// </summary>
        /// <param name="gameTime">提供计时值的快照。</param>
        protected override void Update(GameTime gameTime)
        {
            // 允许游戏退出
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: 在此处添加更新逻辑
            if (currentState != preState)
            {
                sceneChangeLag -= gameTime.ElapsedGameTime.Milliseconds;
                if (sceneChangeLag <= 0)
                {
                    preState = currentState;
                    switch (currentState)
                    {
                        case GameState.main_menu:
                            Components.Clear();
                            Menu menu = new Menu(this);
                            menu.Initialize();
                            Components.Add(menu);
                            break;
                        case GameState.playing:
                            Components.Clear();
                            Scene scene = new Scene(this);
                            scene.Initialize();
                            Components.Add(scene);
                            break;
                        case GameState.lose:
                            Components.Clear();
                            Lose lose = new Lose(this);
                            lose.Initialize();
                            Components.Add(lose);
                            break;
                        case GameState.win:
                            Components.Clear();
                            Win win = new Win(this);
                            win.Initialize();
                            Components.Add(win);
                            break;
                        default:
                            break;
                    }
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 5
0
			public ColorOptionsMenu(Menu parentMenu)
			{
				this.parentMenu = parentMenu;
				SetViewportBackground("SnakeMainMenuBackground");
				AddBackgroundAndColorDisplay();
				AddGameElementSelection();
				AddColorSliders();
				AddDoneButton();
			}