コード例 #1
0
        public void Update(GameEngine engine)
        {
            if (Input.IsKeyDown(Keys.LEFT))
            {
                x -= speed;
            }
            else if (Input.IsKeyDown(Keys.RIGHT))
            {
                x += speed;
            }

            if (Input.IsKeyDown(Keys.UP))
            {
                y -= speed;
            }
            else if (Input.IsKeyDown(Keys.DOWN))
            {
                y += speed;
            }

            if (!wasLeftMouseButtonDown && Input.IsMouseLeftButtonDown)
            {
                engine.AddObject(new SampleBullet(x, y, speed));
            }
            if (!wasRightMouseButtonDown && Input.IsMouseRightButtonDown)
            {
                engine.AddObject(new SampleBullet(x, y, speed));
            }

            wasLeftMouseButtonDown  = Input.IsMouseLeftButtonDown;
            wasRightMouseButtonDown = Input.IsMouseRightButtonDown;
        }
コード例 #2
0
 public SnakeF(ConsoleGraphics graphics, GameEngine engine)
 {
     this.engine = engine;
     snake       = new List <Part>();
     head        = new Part(20, 20, 0xFFFF0000);
     snake.Add(head);
     fieldHeight = graphics.ClientHeight;
     fieldWidth  = graphics.ClientWidth;
     Direction   = Direction.Down;
     GameOver    = false;
     GameInfo    = false;
     Score       = 0;
     Points      = 100;
     food        = new Part();
     food.X      = random.Next(0, fieldWidth / food.Width);
     food.Colour = 0xFFFFFF00;
     food.Y      = random.Next(0, fieldHeight / food.Height);
     food.Render(graphics);
     buttonRestart   = new Button(10, 10, 200, 50, "NEW GAME");
     buttonHighScore = new Button(10, 120, 200, 50, "BEST SCORE");
     engine.ClearScreen();
     engine.AddObject(head);
     engine.AddObject(food);
 }
コード例 #3
0
        private void CreateFood(GameEngine engine)
        {
            bool needNewFood = true;

            while (needNewFood)
            {
                food        = new Part();
                food.X      = random.Next(0, fieldWidth / food.Width);
                food.Colour = 0xFFFFFF00;
                food.Y      = random.Next(0, fieldHeight / food.Height);

                for (int i = 0; i < snake.Count; i++)
                {
                    if (!(snake[i].X == food.X && snake[i].Y == food.Y))
                    {
                        needNewFood = false;
                    }
                }
            }
            engine.AddObject(food);
        }