Skip to content

Commit

Permalink
Merge pull request #8 from firefly-zero/badges
Browse files Browse the repository at this point in the history
Badges
  • Loading branch information
orsinium authored Jan 22, 2025
2 parents 7a13411 + 8df79e6 commit 9706eab
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions firefly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ font = { path = "font.fff", url = "https://fonts.fireflyzero.com/fonts/ascii/eg_
move-apple = 1 # Move apple into a new random position
inc-score = 2 # Increment the score by the given value
dec-score = 3 # Decrement the score by the given value

[badges]
1 = { name = "m i tasti", descr = "bite yourself" }
2 = { name = "u r tasti", descr = "bite someone else" }
3 = { name = "apel tasti", descr = "eat 100 apples", steps = 100 }
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module snek
go 1.22.1

require (
github.com/firefly-zero/firefly-go v0.4.1
github.com/orsinium-labs/tinymath v1.0.0
github.com/firefly-zero/firefly-go v0.8.0
github.com/orsinium-labs/tinymath v1.1.0
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/firefly-zero/firefly-go v0.4.1 h1:GFx+uFK+Ea5Ezyr6/OPzGvRiiDkea4vJ5m4/uzmUMwI=
github.com/firefly-zero/firefly-go v0.4.1/go.mod h1:Uzie8FNoYCjp1mDxnzWnLQv7+ABS/LC7T7kPoJZtIF8=
github.com/orsinium-labs/tinymath v1.0.0 h1:Uzp3GmjWIBxMObx4MQi9ACDu4Q8WKjSRakB1OMo9Bu0=
github.com/orsinium-labs/tinymath v1.0.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
github.com/firefly-zero/firefly-go v0.6.0 h1:IKSyir8rEs2TGcar+m8khoGIa3H+0gUxIhFofTjUm04=
github.com/firefly-zero/firefly-go v0.6.0/go.mod h1:Uzie8FNoYCjp1mDxnzWnLQv7+ABS/LC7T7kPoJZtIF8=
github.com/firefly-zero/firefly-go v0.8.0 h1:op6OBwafWkF8JaauhV5WkJoyF6sGIVi0qV23St/sT60=
github.com/firefly-zero/firefly-go v0.8.0/go.mod h1:Uzie8FNoYCjp1mDxnzWnLQv7+ABS/LC7T7kPoJZtIF8=
github.com/orsinium-labs/tinymath v1.1.0 h1:KomdsyLHB7vE3f1nRAJF2dyf1m/gnM2HxfTeV1vS5UA=
github.com/orsinium-labs/tinymath v1.1.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
}

func boot() {
font = firefly.LoadROMFile("font").Font()
font = firefly.LoadFile("font", nil).Font()
apple = NewApple()
peers := firefly.GetPeers()
snakes = make([]*Snake, peers.Len())
Expand Down
16 changes: 12 additions & 4 deletions score.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import (
"github.com/firefly-zero/firefly-go/firefly"
)

// How long (in frames) the snake can go without food.
const HungerPeriod = 6 * 60
const (
// How long (in frames) the snake can go without food.
HungerPeriod = 6 * 60

// For how long (in frames) the snake is invulnerable after a collision.
const IFrames = 60
// For how long (in frames) the snake is invulnerable after a collision.
IFrames = 60

BadgeBiteSelf firefly.Badge = 1
BadgeBiteOther firefly.Badge = 2
BadgeEat100Apples firefly.Badge = 3
)

var score Score

Expand Down Expand Up @@ -50,6 +56,7 @@ func (s *Score) Update(snake *Snake) {
s.hunger -= 1
}
if snake.Collides(snake.Mouth) {
firefly.AddProgress(snake.Peer, BadgeBiteSelf, 1)
score.Dec()
}
}
Expand All @@ -60,6 +67,7 @@ func (s *Score) Update(snake *Snake) {
func (s *Score) Inc() {
s.hunger = HungerPeriod
s.val += 1
firefly.AddProgress(firefly.Combined, BadgeEat100Apples, 1)
}

// Decrease the score.
Expand Down

0 comments on commit 9706eab

Please sign in to comment.