public IGameElement Create(LevelContext context, IList<IGameElement> elements, double timeDelta) { passedTime += timeDelta; Food food = null; if (passedTime >= foodCreationTimeInterval) { passedTime = 0.0d; ResetTimer(); Vector2 newLocation; do { newLocation = new Vector2(rand.Next(0, context.Settings.HorizontalTileCount - 1), rand.Next(0, context.Settings.VerticalTileCount - 1)); } while (context.IsCellEmpty(newLocation)); food = new Food( aliveTime, new Transform( () => new Color(230, 126, 34), () => AssetReference.WhitePixel, () => Vector2.One, () => newLocation, () => 0.0f, () => 0.0f)); food.SetDisposable(Disposable.Create(elements, food)); } return food; }
public void Handle(LevelContext context) { context.SnakeHead.Bind(context.TailSpawner.Spawn(context. SnakeHead. TailLocation .AsVector2())); context.Score++; }
public void Update(LevelContext context, double deltaTime) { passedTime += deltaTime; if (passedTime >= aliveTime) { disposable.Dispose(); } if (transform.Location == context.SnakeHead.HeadGridLocation) { context.AddState(new AddTailState()); disposable.Dispose(); } }
public Level(ILevelProvider levelProvider, Action next, Action restart) { this.levelProvider = levelProvider; grid = levelProvider.Grid; levelSettings = levelProvider.LevelSettings; adjustmentRules = AdjustmentRules.Default(levelProvider.LevelSettings.HorizontalTileCount - 1, levelProvider.LevelSettings.VerticalTileCount - 1); context = new LevelContext(levelProvider.Head, levelProvider.LevelSettings, levelProvider.TailSpawner, Direction.Left, restart, next, location => { bool intersects = grid[(int)location.X, (int)location.Y].Collide(); elements.ForEach(element => intersects|= element.Intersects(location)); return intersects; }, levelProvider.LevelSettings.MaxLives); elements.Add(levelProvider.Head); }
public void Handle(LevelContext context) { context.Direction = direction; }
private void CheckBodyCollision(SnakePiece piece, LevelContext context, Point locationToTest) { if (piece != null) { if (locationToTest == piece.location) { if (piece.hasMoved) { context.AddState(new DeathState()); } } CheckBodyCollision(piece.Tail,context, locationToTest); } }
public void Update(LevelContext context, double deltaTime) { CheckBodyCollision(Tail, context, location); }