johnroids

package module
v0.0.0-...-3890067 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2018 License: MIT Imports: 12 Imported by: 0

README

This is JohnRoids. A simple but addictive game whose sole purpose is to kill John.

Johnroids GIF

Play the game online.

See also Technical Writeup

I wrote this game originally in 1991 on my Acorn Archimedes to annoy John when I was bored one rainy afternoon. John came round and instead of being annoyed played the game for hours and hours - there is obviously some kind of perverse thrill in shooting oneself!

Back in 1991 digitised pictures were still something of a rarity. I made the one of John from a camcorder video and an extremely hacky black and white video digitiser which I built myself. Note there are actually two images of John - one looking happy and the other not!

The original was written entirely in ARM assembler to make it go fast enough. However I thought the program deserved not to wither away so in 2001 I ported it to C and SDL and in 2018 ported it to Go to run in the browser so many more hours can be wasted shooting at John.

When you run the game you'll notice the playing area is rather small (320x256 pixels). I'm afraid this was all that was available in 1991! I tried making the playing area bigger but the game lost some of its visceral thrill, so you are left with a small screen. If you want it bigger use the zoom function of your browser.

This is an entirely faithful conversion of the original except for the fact that I haven't put the sound back in yet. The original samples are in a very strange format I haven't managed to translate.

You can find the source code on github - report issues and send fixes there please!

The instructions are printed on the screen to start, but to summarise they are:

Z      - Rotate left
X      - Rotate right
Shift  - Fire thruster
Return - Fire gun
Space  - Start the game

If you press "Toggle Keyboard" you'll get an onscreen keyboard which works pretty well on mobile devices.

Shoot everything before it touches you. Note that you lose a point of score for every bullet you fire. Some of the roids may shoot at you - using thrust is a good idea at this point. Things get very hectic as you go through the levels.

Installation

This repository contains 3 implementation of johnroids for SDL, gopherjs and go/wasm.

If you want to try it locally then do

go get github.com/ncw/johnroids/...

And run the johnroids-sdl binary.

Note that you'll need the SDL headers and libraries installed for this to work.

You can play the gopherjs and go/wasm versions online.

To build these versions cd to johnroids-js then make build then make serve. You may have to alter the path to your go1.11 binary in the Makefile.

Enjoy

Nick Craig-Wood
nick@craig-wood.com
@njcw
2018-07-14

Documentation

Overview

JohnRoids - the conversion!

note that the error checking for object table full has been taken out...

make a rand_chance (x/y) function

Note that object 0 is the ship

Speed goes wrong when we have the ghostship countdown

Need to figure out what happens on gameover! gamepause should be in main loop really...

Try making an explode image function which makes an object per pixel in the object and gives then the right velocities to make an explosion. Could then have a fade table for each of 256 pixels. Will run out of objects pretty quickly! Perhaps only want to explode every 10th pixel in the roids or something like that. Could record the x and y of the hit and use that as the centre of the explosion.

Could reduce the width and height of the sprite by removing all the black rows at the top and the bottom left and right. This would speed up the plotter and enable us to calculate the c of g so we could split the roids so that the bits always came apart from the centre.

Could make the explosion always start from the bullet hit - this might be quite realistic.

Index

Constants

View Source
const (
	SW            = 320
	SH            = 256
	MinMsPerFrame = 20
)

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game state

func New

func New() *Game

func (*Game) Frame

func (g *Game) Frame() *image.Paletted

This plots a single frame of the game

func (*Game) KeyEvent

func (g *Game) KeyEvent(key KeyCode, pressed bool)

Key event should be used to deliver key presses to the game.

key should be one of the define KeyCodes and pressed should be true for key depressed and false for key released

type KeyCode

type KeyCode byte

KeyCode defines keys to pass to Game.KeyEvent

const (
	KeyCodeZ KeyCode = iota
	KeyCodeX
	KeyCodeShift
	KeyCodeReturn
	KeyCodeSpace
)

Keys that need to be passed to Game.KeyEvent

Directories

Path Synopsis
SDL version of johnroids
SDL version of johnroids

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL