Snek 🐍 - a simple terminal snake game

Here is a little terminal game I wrote during some free time at work. It’s not quite finished and may be buggy, but it’s good enough to share for testing.

Compile with:

cc snek.c -o snek -Wall

and run:

./snek

For now, it needs a terminal emulator that supports truecolor (works fine in Konsole). You can force it to work by setting COLORTERM=truecolor but it may look terrible. Eventually, I’ll fix this…

Fixed.

11 Likes

honka_animated-128px-41

1 Like

Nice, just gave it a go

1 Like

Here’s a simple pkgbuild if you’d like to put it up on the AUR. (or I could put it there if you’d like)

_pkgname=snek
pkgname="${_pkgname}-git"
pkgver=r8.2c92a3b
pkgrel=1
pkgdesc="A simple terminal snake game written in C"
arch=("any")
url="https://gitlab.com/Kresimir235/snek"
license=("MIT")
makedepends=( "git" )
provides=("snek")
source=("${_pkgname}::git+${url}.git")
sha256sums=("SKIP")

pkgver() {
  cd "${srcdir}/${_pkgname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  cd "${_pkgname}"
  cc snek.c -o snek -Wall -O2
}

package() {
  install -Dm0755 "${_pkgname}/${_pkgname}" "${pkgdir}/usr/bin/${_pkgname}"
}

Also...

I gotta rewrite this in rust :crab:

2 Likes

Optimisations? In my C? Outrageous! :rofl:

I don’t want to put it on the AUR before it is thoroughly tested… and I don’t really care about maintaining it.

But if you want to, feel free to, it’s MIT license, so anyone can do anything with it. Even compile it with -O2 :rofl:

MIT?! :scream:
You want to find out it used as some proprietary spy software later? :rofl:

1 Like

The target audience for this software is unlikely to use proprietary spyware, so I’m not terribly worried. It’s what I call the IDGAF license…

2 Likes

Who knows…maybe some day you will regret about it, maybe you’ll find modification of it in some smart watch or something :rofl:

2 Likes

6 Likes

What about -O3 & -flto? Can’t leave any performance on the table.

2 Likes

I know! Let’s use -O4!

image

4 Likes

There is a new commit to the Snek game. A bunch of new features have been added:

– command line arguments
– pause functionality: so you can go to the loo in the middle of the game
– repeat mode: so you start a new game automatically after losing
– setting game size: you can play on a board size between 18×14 and 160×100
– setting the game speed
– monochrome mode for :poop:-terminals

It should be feature complete now.

5 Likes

My favourite mode:

./snek -w 18 -h 14 -s 9 -r
1 Like

are you playing on a watch ?

I love the colors of the snake. usually the snek is a single color. great game.

2 Likes

Yeah, just added that feature… And another commit, fixed a little bug so that the game now automatically switches to monochrome mode in :poop:-terminals.

No :laughing:
I just love infinite death :rofl:

Well, it is a… *puts on sunglasses*

terminal game.

image

2 Likes

It’s actually pretty nice. Would love to see an animation when the snake hits the wall.

1 Like

Thanks! What kind of animation did you have in mind? I was thinking about letting Snek shrink to nothing (head standing still, tail continuing on its way). That would be fairly straightforward to implement, but if Snek is long, it might take awhile and detract from the gameplay. I don’t know…

1 Like

The snake shrinking and add a simple small “explosion” where the head runs into the wall.