This class holds data about the snake body and checks for snake collisions with either
itself or with the borders and whether the snake must grow in size.
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Entities Entity
DeltaEngine.Entities DrawableEntity
DeltaEngine.Rendering2D Entity2D
Snake Snake
Namespace: Snake
Assembly: Snake (in Snake.exe) Version: 1.1.1.0 (1.1.1)
Syntax
The Snake type exposes the following members.
Constructors
Name | Description | |
---|---|---|
Snake | Initializes a new instance of the Snake class |
Methods
Extension Methods
Name | Description | |
---|---|---|
AffixToPhysics | (Defined by Entity2DPhysicsExtensions.) | |
StartBouncingOffScreenEdges | (Defined by Entity2DExtensions.) | |
StartFalling | (Defined by Entity2DExtensions.) | |
StartMoving | (Defined by Entity2DExtensions.) | |
StartRotating | (Defined by Entity2DExtensions.) |
Fields
Name | Description | |
---|---|---|
components | (Inherited from Entity.) | |
lastTickLerpComponents |
Each element can either be a Lerp, a Lerp List or an array of Lerp objects.
View code on GitHub (Inherited from DrawableEntity.) |
Properties
Name | Description | |
---|---|---|
Alpha | (Inherited from Entity2D.) | |
Center | (Inherited from Entity2D.) | |
Color | (Inherited from Entity2D.) | |
DidFootprintChange | (Inherited from Entity2D.) | |
DrawArea | (Inherited from Entity2D.) | |
IsActive | (Inherited from DrawableEntity.) | |
IsPauseable | (Inherited from Entity.) | |
IsVisible | (Inherited from DrawableEntity.) | |
LastColor | (Inherited from Entity2D.) | |
LastDrawArea | (Inherited from Entity2D.) | |
NumberOfComponents | (Inherited from Entity.) | |
RenderLayer | (Inherited from DrawableEntity.) | |
Rotation | (Inherited from Entity2D.) | |
RotationCenter | (Inherited from Entity2D.) | |
Size | (Inherited from Entity2D.) | |
TopLeft | (Inherited from Entity2D.) | |
UpdatePriority | (Inherited from Entity.) |
Remarks
Examples
[Test, CloseAfterFirstFrame] public void StartGame() { new Game(Resolve<Window>()); }
[Test, CloseAfterFirstFrame] public void RespawnChunkIfCollidingWithSnake() { var game = new Game(Resolve<Window>()); game.StartGame(); game.Chunk.DrawArea = game.Snake.Get<Body>().BodyParts[0].DrawArea; Assert.IsTrue(game.Chunk.IsCollidingWithSnake(game.Snake.Get<Body>().BodyParts)); game.RespawnChunk(); Assert.IsFalse(game.Chunk.IsCollidingWithSnake(game.Snake.Get<Body>().BodyParts)); }
[Test, CloseAfterFirstFrame] public void SnakeEatsChunk() { var game = new Game(Resolve<Window>()); game.StartGame(); var snakeHead = game.Snake.Get<Body>().BodyParts[0].DrawArea; var direction = game.Snake.Get<Body>().Direction; var originalLength = game.Snake.Get<Body>().BodyParts.Count; game.Chunk.DrawArea = new Rectangle(new Vector2D(snakeHead.Left + direction.X, snakeHead.Top + direction.Y), new Size(blockSize)); game.MoveUp(); AdvanceTimeAndUpdateEntities(moveSpeed); Assert.AreEqual(originalLength + 1, game.Snake.Get<Body>().BodyParts.Count); }
See Also