80 likes | 354 Vues
MoveSnake () Method. Moving the Snake. How do we move the snake?. In the program, the snake head and tail are the only parts that move. Tail. Head. How do we move the snake?. The snake head and tail are each tracked in the SnakeSpriteData structure. public struct SnakeSpriteData {
E N D
MoveSnake() Method Moving the Snake
How do we move the snake? • In the program, the snake head and tail are the only parts that move. Tail Head
How do we move the snake? • The snake head and tail are each tracked in the SnakeSpriteDatastructure. publicstructSnakeSpriteData { publicintsnakeLength; publicintsnakeHeadXCoordinate; publicintsnakeHeadYCoordinate; publicSegmentDirectionsnakeHeadDirection; publicintsnakeTailXCoordinate; publicintsnakeTailYCoordinate; publicSegmentDirectionsnakeTailDirection; publicintamountOfBends; publicsnakeBendData[] snakeBendArray; }
How do we move the snake? • Snake movement is determined based upon the direction the head and tail are moving • publicSegmentDirectionsnakeHeadDirection • publicSegmentDirectionsnakeTailDirection Tail Head (10,5) x y (21,7) x y
How do we move the snake? • The direction of the snake head and tail indicate which coordinate components (x or y coordinate) need to be changed X Tail Head (10,5) x y (21,7) x y Y
How do we move the snake? • The direction of the snake head and tail indicate which coordinate components (x or y coordinate) need to be changed X Tail Head (10,5) x y (21,7) x y Y
How do we move the snake? • The components that should be changed follow based on the direction • Up • Y component needs to decremented (subtracted from) • Down • Y component needs to incremented (added to) • Right • X component needs to incremented • Left • X component needs to decremented