Example #1
0
 public override void Update(GameTime gameTime, IInput input)
 {
     if (input != null)
     {
         if (input.IsKeyDown(Keys.Left) && direction != Direction.Right)
         {
             Direction = Direction.Left;
             return;
         }
         if (input.IsKeyDown(Keys.Right) && direction != Direction.Left)
         {
             Direction = Direction.Right;
             return;
         }
         if (input.IsKeyDown(Keys.Up) && direction != Direction.Bottom)
         {
             Direction = Direction.Top;
             return;
         }
         if (input.IsKeyDown(Keys.Down) && direction != Direction.Top)
         {
             Direction = Direction.Bottom;
             return;
         }
     }
 }
Example #2
0
File: Field.cs Project: K0bin/Snake
 public virtual void Update(GameTime gameTime, IInput input)
 {
 }
Example #3
0
File: Game.cs Project: K0bin/Snake
        public void Update()
        {
            GameTime gameTime = new GameTime(new TimeSpan(watch.ElapsedTicks), new TimeSpan(watch.ElapsedTicks - lastElapsedTicks));
            lastElapsedTicks = watch.ElapsedTicks;

            //Update
            if (world != null)
                world.Update(gameTime, input);

            //Update
            if (gameTime.TotalGameTime.TotalMilliseconds - lastMilliseconds > Rules.Duration)
            {
                if (world != null)
                    world.SnakeTick();

                lastMilliseconds = (long)gameTime.TotalGameTime.TotalMilliseconds;
            }

            //Render
            renderer.Clear();

            if(world != null)
                world.Render(renderer);
        }
Example #4
0
File: World.cs Project: K0bin/Snake
        public void Update(GameTime gameTime, IInput input)
        {
            if (Head != null)
                Head.Update(gameTime, input);

            if (Treat != null)
                Treat.Update(gameTime, input);

            for (int i = 0; i < blocks.Count; i++)
                if (blocks != null && blocks[i] != null)
                    blocks[i].Update(gameTime, input);

            for (int i = 0; i < bodies.Count; i++)
                if (bodies != null && bodies[i] != null)
                    bodies[i].Update(gameTime, input);

            for (int i = 0; i < clearPowerups.Count; i++)
                if (clearPowerups != null && clearPowerups[i] != null)
                    clearPowerups[i].Update(gameTime, input);

            for (int i = 0; i < speedPowerups.Count; i++)
                if (speedPowerups != null && speedPowerups[i] != null)
                    speedPowerups[i].Update(gameTime, input);
        }