Skip to content

Instantly share code, notes, and snippets.

@erap129
Created September 26, 2022 07:58
Show Gist options
  • Save erap129/b8d58dcd6b349187f422a2323a6dcae5 to your computer and use it in GitHub Desktop.
Save erap129/b8d58dcd6b349187f422a2323a6dcae5 to your computer and use it in GitHub Desktop.
Snake - snake.go
package main
type SnakeBody struct {
X int
Y int
Xspeed int
Yspeed int
}
func (sb *SnakeBody) ChangeDir(vertical int, horizontal int) {
sb.Yspeed = vertical
sb.Xspeed = horizontal
}
func (sb *SnakeBody) Update(width int, height int) {
sb.X = (sb.X + sb.Xspeed) % width
if sb.X < 0 {
sb.X += width
}
sb.Y = (sb.Y + sb.Yspeed) % height
if sb.Y < 0 {
sb.Y += height
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment