Skip to content

Commit

Permalink
added snake to rpc
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 22, 2024
1 parent 2957262 commit a925a99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/main/kotlin/gay/j10a1n15/sillygames/games/Snake.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gay.j10a1n15.sillygames.games

import gay.j10a1n15.sillygames.rpc.RpcInfo
import gay.j10a1n15.sillygames.rpc.RpcProvider
import gay.j10a1n15.sillygames.utils.Vector2d
import gg.essential.elementa.UIComponent
import gg.essential.elementa.components.UIBlock
Expand All @@ -18,7 +20,7 @@ import gg.essential.elementa.dsl.plus
import gg.essential.universal.UKeyboard
import java.awt.Color

class Snake : Game() {
class Snake : Game(), RpcProvider {

private val gridWidth = 30
private val gridHeight = 20
Expand All @@ -32,6 +34,12 @@ class Snake : Game() {
private val gameSpeed = 200L
private var lastUpdateTime = System.currentTimeMillis()

private val rpc = RpcInfo(
firstLine = "Snake",
secondLine = "Score: $score",
start = System.currentTimeMillis(),
)

override fun onTick() {
if (gameOver) return
if (snake.isEmpty()) return
Expand All @@ -49,6 +57,7 @@ class Snake : Game() {
if (newHead == foodPosition) {
score += 1
foodPosition = randomLocation()
rpc.secondLine = "Score: $score"
} else if (it.size > 4) {
return@let it.dropLast(1)
}
Expand Down Expand Up @@ -174,4 +183,6 @@ class Snake : Game() {
override val pip = true

override val name = "Snake"

override fun getRpcInfo() = rpc
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gay.j10a1n15.sillygames.screens

import gay.j10a1n15.sillygames.games.Game
import gay.j10a1n15.sillygames.games.Snake
import gay.j10a1n15.sillygames.games.wordle.Wordle
import gay.j10a1n15.sillygames.utils.SillyUtils.display
Expand All @@ -16,7 +17,7 @@ import gg.essential.elementa.utils.withAlpha
import gg.essential.universal.GuiScale
import java.awt.Color

val gameFactories = setOf(
val gameFactories = setOf<() -> Game>(
{ Wordle() },
{ Snake() },
)
Expand Down

0 comments on commit a925a99

Please sign in to comment.