29

GitHub - spinzed/tpong: Classical pong game remade in terminal with Go

 4 years ago
source link: https://github.com/spinzed/tpong
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

It's Pong!

The old school Atari Pong game remade in terminal with Golang.

General Info

For best experience, make your terminal fullscreen or zoom out.
The game currently works only on Linux systems due to platform-dependent key detection.
For a similar reason, this game must be run with superuser privileges.

To interact with terminal, the tcell package API is used.
For keyboard events detection, the keylogger package API is used.

Why sudo?

It is a compromise that had to be made. Since you cannot detect keyboard press and release key events through terminal, package keylogger is used to do it. Basically, it reads input from /dev/input/event* which requires root access. It is a drawback, but without it, the game would not be playable.

Compile & Run

To compile this project into an executable, run:

go get github.com/spinzed/tpong

You should be able to run the game via command sudo tpong.
Note: make sure than $GOPATH/bin is in your path, otherwise you won't be able to run the command from anywhere else but from $GOPATH/bin.

Alternative is to git clone this repo, cd into it and run:

sudo go run .

Game Screenshot

Controls

Key Action
W Player1 Up
S Player1 Down
Player2 Up
Player2 Down
Space Start
Q Quit
P Toggle Pause
R Restart Round
T Switch Theme
B Toggle Background

Further Plans & Todos

Eventually, this project may be expanded:

  1. that it can be hosted via HTTP API
  2. that it is compatible with online play

Keep in Mind

This project is primarily an exercise for me to learn more about the Go language. That being said, any constructive feedback is appreciated!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK