Skip to content

Commit

Permalink
add snake logo
Browse files Browse the repository at this point in the history
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Sep 29, 2024
1 parent 1ef6424 commit 580a551
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/kotlin/gay/j10a1n15/sillygames/games/Snake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Snake : Game(), RpcProvider {
private val rpc = RpcInfo(
firstLine = "Snake",
secondLine = "Score: $score",
icon = "snake_logo",
start = System.currentTimeMillis(),
)

Expand Down Expand Up @@ -110,28 +111,28 @@ class Snake : Game(), RpcProvider {
x = CenterConstraint()
} childOf background

for (_y in 0 until gridHeight) {
for (y in 0 until gridHeight) {
val row = UIContainer().constrain {
width = ChildBasedSizeConstraint()
height = cellHeightPercent.percent()
y = SiblingConstraint()
this.y = SiblingConstraint()
} childOf grid

for (_x in 0 until gridWidth) {
val indexInSnake = snake.indexOfFirst { it.x == _x && it.y == _y }
for (x in 0 until gridWidth) {
val indexInSnake = snake.indexOfFirst { it.x == x && it.y == y }
val gridColor = when {
foodPosition.x == _x && foodPosition.y == _y -> Color.BLUE
foodPosition.x == x && foodPosition.y == y -> Color.BLUE
indexInSnake == 0 -> Color.RED
indexInSnake != -1 && indexInSnake % 2 == 1 -> Color(23, 172, 16)
indexInSnake != -1 -> Color(72, 232, 40)
(_x + _y) % 2 == 0 -> Color(0, 100, 0)
(x + y) % 2 == 0 -> Color(0, 100, 0)
else -> Color(0, 120, 0)
}

UIBlock().constrain {
height = 100.percent()
width = AspectConstraint(1f)
x = SiblingConstraint()
this.x = SiblingConstraint()
color = gridColor.constraint
} childOf row
}
Expand Down Expand Up @@ -187,5 +188,6 @@ object SnakeInformation : GameInformation() {
override val name = "Snake"
override val description = "A classic game of Snake"
override val factory = { Snake() }
override val icon = "snake_logo"
override val supportsPictureInPicture = true
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 580a551

Please sign in to comment.