Snek šŸ - a simple terminal snake game

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

The source code consists of only one file (snek.c). Compile with:

cc snek.c -o snek -Wall

and run:

./snek

For help, run:

./snek --help

Enjoy!

12 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:

3 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

image

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.