sprite

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 11 Imported by: 30

README

Go-Asciisprite Logo

A simple golang sprite library for animating ASCII and Unicode art

What is a sprite? A sprite is a two-dimensional object which you can use in videogames and animations.

Features

  • Easy to use routines for creating and manipulating text sprites

  • Block interpolation for creating unicode "pixel" graphics

  • Simple ascii "fonts" for creating block based text

  • Event system for triggering sprite events

Usage

package main

import (
        "time"

        sprite "github.com/pdevine/go-asciisprite"
        tm "github.com/pdevine/go-asciisprite/termbox"
)

var allSprites sprite.SpriteGroup
var Width int
var Height int

const cow_c0 = `
^__^xxxxxxxxxxxx
(oo)\_______
(__)\       )\/\
xxxx||----w |xxx
xxxx||xxxxx||xxx
`

type Cow struct {
	sprite.BaseSprite
	VX int
	VY int
}

func NewCow() *Cow {
	cow := &Cow{BaseSprite: sprite.BaseSprite{
		X: 5,
		Y: 5,
		Visible: true},
		VX: 1,
		VY: 1,
	}
	cow.AddCostume(sprite.NewCostume(cow_c0, 'x'))

	return cow
}

func (cow *Cow) Update() {
	cow.X += cow.VX
	cow.Y += cow.VY
	if cow.X <= 0 {
		cow.VX = 1
	} else if cow.X >= (Width-cow.Width) {
		cow.VX = -1
	}
	if cow.Y <= 0 {
		cow.VY = 1
	} else if cow.Y >= (Height-cow.Height) {
		cow.VY = -1
	}
}


func main() {
	err := tm.Init()
	if err != nil {
		panic(err)
	}
	defer tm.Close()

	Width, Height = tm.Size()

	event_queue := make(chan tm.Event)
	go func() {
		for {
			event_queue <- tm.PollEvent()
		}
	}()

	cow := NewCow()
	c := sprite.NewCostume("Press 'ESC' to quit", '~')
	text := sprite.NewBaseSprite(Width/2-c.Width/2, Height-2, c)

	allSprites.Sprites = append(allSprites.Sprites, cow)
	allSprites.Sprites = append(allSprites.Sprites, text)

mainloop:
	for {
		tm.Clear(tm.ColorDefault, tm.ColorDefault)

		select {
		case ev := <-event_queue:
			if ev.Type == tm.EventKey {
				if ev.Key == tm.KeyEsc {
					break mainloop
				}
			} else if ev.Type == tm.EventResize {
				Width = ev.Width
				Height = ev.Height
			}
		default:
			allSprites.Update()
			allSprites.Render()
			time.Sleep(60 * time.Millisecond)
		}
	}
}

Bouncing Cow

Documentation

Overview

Package sprite provides a framework for creating ASCII and Unicode based animations and games.

Index

Constants

View Source
const Font_0 = `
 XX
X X
X X
X X
XX`
View Source
const Font_1 = `
 X
XX
 X
 X
XXX`
View Source
const Font_2 = `
XX
  X
XXX
X
XXX`
View Source
const Font_3 = `
XX
  X
XX
  X
XXX`
View Source
const Font_4 = `
X X
X X
XXX
  X
  X`
View Source
const Font_5 = `
XXX
X
XXX
  X
XX`
View Source
const Font_6 = `
 XX
X
XXX
X X
XX`
View Source
const Font_7 = `
XXX
  X
 X
X
X`
View Source
const Font_8 = `
 XX
X X
XXX
X X
XX`
View Source
const Font_9 = `
 XX
X X
XXX
  X
XXX`
View Source
const Font_90s_0 = `
 XXX
X   X
X   X
X   X
X   X
X   X
 XXX`
View Source
const Font_90s_1 = `
   X
 XXX
   X
   X
   X
   X
   X`
View Source
const Font_90s_2 = `
 XXX
X   X
    X
  XX
 X
X
XXXXX`
View Source
const Font_90s_3 = `
 XXX
X   X
    X
  XX
    X
X   X
 XXX`
View Source
const Font_90s_4 = `
   X
  XX
 X X
X  X
XXXXX
   X
   X`
View Source
const Font_90s_5 = `
XXXX
X
XXXX
    X
    X
X   X
 XXX`
View Source
const Font_90s_6 = `
  XX
 X
X
XXXX
X   X
X   X
 XXX`
View Source
const Font_90s_7 = `
XXXXX
    X
   X
   X
  X
  X
  X`
View Source
const Font_90s_8 = `
 XXX
X   X
X   X
 XXX
X   X
X   X
 XXX`
View Source
const Font_90s_9 = `
 XXX
X   X
X   X
 XXXX
    X
   X
 XX`
View Source
const Font_90s_A = `
  X
 X X
X   X
X   X
XXXXX
X   X
X   X`
View Source
const Font_90s_B = `
XXXX
X   X
X   X
XXXX
X   X
X   X
XXXX`
View Source
const Font_90s_C = `
 XXX
X   X
X
X
X
X   X
 XXX`
View Source
const Font_90s_D = `
XXXX
 X  X
 X  X
 X  X
 X  X
 X  X
XXXX`
View Source
const Font_90s_E = `
XXXXX
X
X
XXXX
X
X
XXXXX`
View Source
const Font_90s_F = `
XXXXX
X
X
XXXX
X
X
X`
View Source
const Font_90s_G = `
 XXX
X   X
X
X XXX
X   X
X   X
 XXX`
View Source
const Font_90s_H = `
X   X
X   X
X   X
XXXXX
X   X
X   X
X   X`
View Source
const Font_90s_I = `
 XXX 
  X
  X
  X
  X
  X
 XXX `
View Source
const Font_90s_J = `
XXXXX
   X
   X
   X
   X
X  X
 XX`
View Source
const Font_90s_K = `
X   X
X  X
X X
XX
X X
X  X
X   X`
View Source
const Font_90s_L = `
X
X
X
X
X
X
XXXXX`
View Source
const Font_90s_M = `
X   X
XX XX
X X X
X X X
X   X
X   X
X   X`
View Source
const Font_90s_N = `
X   X
X   X
XX  X
X X X
X  XX
X   X
X   X`
View Source
const Font_90s_O = `
 XXX
X   X
X   X
X   X
X   X
X   X
 XXX`
View Source
const Font_90s_P = `
XXXX
X   X
X   X
XXXX
X
X
X`
View Source
const Font_90s_Q = `
 XXX
X   X
X   X
X   X
X X X
X  X 
 XX X`
View Source
const Font_90s_R = `
XXXX
X   X
X   X
XXXX
X X
X  X
X   X`
View Source
const Font_90s_S = `
 XXX
X   X
X
 XXX
    X
X   X
 XXX`
View Source
const Font_90s_T = `
XXXXX
  X
  X
  X
  X
  X
  X`
View Source
const Font_90s_U = `
X   X
X   X
X   X
X   X
X   X
X   X
 XXX`
View Source
const Font_90s_V = `
X   X
X   X
X   X
X   X
 X X
 X X
  X`
View Source
const Font_90s_W = `
X   X
X   X
X   X
X X X
X X X
XX XX
X   X`
View Source
const Font_90s_X = `
X   X
X   X
 X X
  X
 X X
X   X
X   X`
View Source
const Font_90s_Y = `
X   X
X   X
X   X
 X X
  X
  X
  X`
View Source
const Font_90s_Z = `
XXXXX
    X
   X
  X
 X
X
XXXXX`
View Source
const Font_90s_a = `


 XXX
    X
 XXXX
X   X
 XXXX`
View Source
const Font_90s_apostrophe = `
    X
   X
`
View Source
const Font_90s_b = `
X
X
XXXX
X   X
X   X
X   X
XXXX`
View Source
const Font_90s_c = `


 XXXX
X
X
X
 XXXX`
View Source
const Font_90s_colon = `

  X



  X

`
View Source
const Font_90s_comma = `    





  X
  X`
View Source
const Font_90s_d = `
    X
    X
 XXXX
X   X
X   X
X   X
 XXXX`
View Source
const Font_90s_dash = `    


XXXXX`
View Source
const Font_90s_e = `


 XXX
X   X
XXXXX
X
 XXXX`
View Source
const Font_90s_exclamation = `    
  X
  X
  X
  X


  X`
View Source
const Font_90s_f = `
   XX
  X
XXXXX
  X
  X
  X
  X`
View Source
const Font_90s_g = `

 XX X
X  X
X  X
 XXX
   X
XXX`
View Source
const Font_90s_gt = `
 X
  X
   X
    X
   X
  X
 X`
View Source
const Font_90s_h = `
X
X
X XX
XX  X
X   X
X   X
X   X`
View Source
const Font_90s_i = `
 XX

 XX
  X
  X
  X
 XXX`
View Source
const Font_90s_j = `
 XX

 XX
  X
  X
X X
 X`
View Source
const Font_90s_k = `
X
X
X  X
X X
XX
X X
X  X`
View Source
const Font_90s_l = `
 XX
  X
  X
  X
  X
  X
 XXX`
View Source
const Font_90s_l_paren = `
 X
  X
   X
   X
   X
  X
 X`
View Source
const Font_90s_lt = `
    X
   X
  X
 X
  X
   X
    X`
View Source
const Font_90s_m = `


XX X
X X X
X X X
X X X
X X X`
View Source
const Font_90s_n = `


X XX
XX  X
X   X
X   X
X   X`
View Source
const Font_90s_o = `


 XXX
X   X
X   X
X   X
 XXX`
View Source
const Font_90s_p = `


XXXX
X   X
X   X
XXXX
X`
View Source
const Font_90s_percent = `    
XX  X
XX  X
   X
  X
 X
X  XX
X  XX`
View Source
const Font_90s_period = `    





  X
`
View Source
const Font_90s_q = `

 XX X
X  X
X  X
 XXX
   X
   XX`
View Source
const Font_90s_question = `
 XXX
X   X
    X
   X
  X

  X`
View Source
const Font_90s_r = `


 X XX
 XX
 X
 X
 X`
View Source
const Font_90s_r_paren = `
   X
  X
 X
 X
 X
  X
   X`
View Source
const Font_90s_right_arrow = `

  X
  XX
XXXXX
  XX
  X
`
View Source
const Font_90s_s = `


 XXXX
X
 XXX
    X
XXXX`
View Source
const Font_90s_slash = `    
    X
    X
   X
  X
 X
X
X`
View Source
const Font_90s_t = `
  X
  X
 XXXX
  X
  X
  X
   XX`
View Source
const Font_90s_u = `


X   X
X   X
X   X
X  XX
 XX X`
View Source
const Font_90s_v = `


X   X
X   X
 X X
 X X
  X`
View Source
const Font_90s_w = `


X   X
X X X
X X X
XX XX
X   X`
View Source
const Font_90s_x = `


X   X
 X X
  X
 X X
X   X`
View Source
const Font_90s_y = `


X   X
X   X
 XXXX
    X
 XXX`
View Source
const Font_90s_z = `


XXXXX
   X
  X
 X
XXXXX`
View Source
const Font_JR_0 = `
  XXX
 X   X
X   X X
X  X  X
X X   X
 X   X
  XXX`
View Source
const Font_JR_1 = `
   X
  XX
 X X
   X
   X
   X
 XXXXX`
View Source
const Font_JR_2 = `
 XXXXX
X     X
      X
     X
  XXX
XX
XXXXXXX`
View Source
const Font_JR_3 = `
XXXXXXX
X    X
    X
    XX
      X
X     X
 XXXXX`
View Source
const Font_JR_4 = `
   XX
  X X
 X  X
X   X
XXXXXXX
    X
    X`
View Source
const Font_JR_5 = `
XXXXXXX
X     X
X
XXXXXX
      X
X     X
 XXXXX`
View Source
const Font_JR_6 = `
 XXXXX
X     X
X
XXXXXX
X     X
X     X
 XXXXX`
View Source
const Font_JR_7 = `
XXXXXXX
X     X
     X
    X
   X
   X
   X`
View Source
const Font_JR_8 = `
 XXXXX
X     X
X     X
 XXXXX
X     X
X     X
 XXXXX`
View Source
const Font_JR_9 = `
 XXXXX
X     X
X     X
 XXXXXX
      X
X     X
 XXXXX`
View Source
const Font_JR_A = `
XXXX
 X  X
 X   X
 XXXXX
 X   X
 X   X
XX   XX`
View Source
const Font_JR_B = `
XXXX
 X  X
 X  X
 XXXXX
 X    X
 X    X
XXXXXX`
View Source
const Font_JR_C = `
  XXX X
 X   XX
X
X
X
 X    X
  XXXX`
View Source
const Font_JR_D = `
XXXXX
 X   X
 X    X
 X    X
 X    X
 X    X
XXXXXX`
View Source
const Font_JR_E = `
XXXXXXX
 X    X
 X
 XXX
 X
 X    X
XXXXXXX`
View Source
const Font_JR_F = `
XXXXXXX
 X    X
 X
 XXX
 X
 X
XXX`
View Source
const Font_JR_G = `
  XXX X
 X   XX
X
X
X   XXX
 X    X
  XXXXX`
View Source
const Font_JR_H = `
XXX XXX
 X   X
 X   X
 XXXXX
 X   X
 X   X
XXX XXX`
View Source
const Font_JR_I = `
 XXXX
  X
  X
  X
  X
  X
 XXXX`
View Source
const Font_JR_J = `
 XXXXXXX
  X   X
      X
      X
 XX   X
  X   X
   XXX`
View Source
const Font_JR_K = `
XXX  XX
 X  X
 X X
 XXXX
 X   X
 X   X
XXX  XX`
View Source
const Font_JR_L = `
XXX
 X
 X
 X
 X
 X    X
XXXXXXX`
View Source
const Font_JR_M = `
XX   XX
 XX XX
 X X X
 X   X
 X   X
 X   X
XXX XXX`
View Source
const Font_JR_N = `
XX  XXX
 XX  X
 XX  X
 X X X
 X  XX
 X  XX
XXX  XX`
View Source
const Font_JR_O = `
  XXX
 X   X
X     X
X     X
X     X
 X   X
  XXX`
View Source
const Font_JR_P = `
XXXXX
 X   X
 X   X
 XXXX
 X
 X
XXX`
View Source
const Font_JR_Q = `
  XXX
 X   X
X     X
X     X
X   X X
 X   X
  XXX X`
View Source
const Font_JR_R = `
XXXXX
 X   X
 X   X
 XXXX
 X   X
 X   X
XXX XXX`
View Source
const Font_JR_S = `
 XXXX X
X    XX
X
 XXXXX
      X
XX    X
X XXXX`
View Source
const Font_JR_T = `
XXXXXXX
X  X  X
   X
   X
   X
   X
  XXX`
View Source
const Font_JR_U = `
XXX XXX
 X   X
 X   X
 X   X
 X   X
 X   X
  XXX`
View Source
const Font_JR_V = `
XXX XXX
 X   X
 X   X
 X  X
 X X
 XX
XX`
View Source
const Font_JR_W = `
XX   XX
 X   X
 X   X
 X   X
 X X X
 XX XX
XX   XX`
View Source
const Font_JR_X = `
XX   XX
 X   X
  X X
   X
  X X
 X   X
XX   XX`
View Source
const Font_JR_Y = `
XXX XXX
 X   X
 X   X
  XXX
   X
   X
  XXX`
View Source
const Font_JR_Z = `
XXXXXXX
X     X
     X
  XXX
 X
X     X
XXXXXXX`
View Source
const Font_JR_a = `


 XXXX
     X
 XXXXX
X    X
 XXXX X`
View Source
const Font_JR_amp = `
  XX
 X  X
 X  X
 XXX
X   X X
X    X
 XXXX X`
View Source
const Font_JR_at = `
  XXX
 X   X
X XXX X
X X X X
X  XXX
 X
  XXXX`
View Source
const Font_JR_b = `
XX
 X
 XXXXX
 X    X
 X    X
 X    X
XXXXXX`
View Source
const Font_JR_b_slash = `

  X
   X
   X
    X
    X
     X`
View Source
const Font_JR_c = `


 XXXXX
X     X
X
X
 XXXXX`
View Source
const Font_JR_colon = `

  XX
  XX

  XX
  XX`
View Source
const Font_JR_comma = `





  XX
  XX
   X`
View Source
const Font_JR_d = `
     XX
     X
 XXXXX
X    X
X    X
X    X
 XXXXXX`
View Source
const Font_JR_dollars = `
   X
 XXXXX
X  X
 XXXXX
   X  X
 XXXXX
   X`
View Source
const Font_JR_double_quot = `
 XX XX
 XX XX
  X  X`
View Source
const Font_JR_down = `



 X   X
  X X
   X`
View Source
const Font_JR_e = `


 XXXXX
X     X
XXXXXXX
X
 XXXXX`
View Source
const Font_JR_equals = `


 XXXXX

 XXXXX`
View Source
const Font_JR_eszett = `
  XX
 X  X
 X X
 X  XX
 X    X
 X X  X
 X  XX
X`
View Source
const Font_JR_exclamation = `
   XX
   XX
   X
   X

  XX
  XX`
View Source
const Font_JR_f = `
   XXX
  X  X
 XXX
  X
  X
  X
 XXX`
View Source
const Font_JR_g = `


 XXXXXX
X     X
X     X
 XXXXXX
      X
XXXXXX`
View Source
const Font_JR_gt = `

  X
   X
    X
   X
  X`
View Source
const Font_JR_h = `
XX
 X
 XXXX
 X   X
 X   X
 X   X
XX   XX`
View Source
const Font_JR_i = `
  X

 XXX
  X
  X
  X
 XXXX`
View Source
const Font_JR_j = `
   X

  XXXX
  X  X
     X
     X
     X
  XXX`
View Source
const Font_JR_k = `
XX
 X   X
 X  X
 XXX
 X  X
 X   X
XX   XX`
View Source
const Font_JR_l = `
  XX
   X
   X
   X
   X
   X
    XX`
View Source
const Font_JR_l_brace = `
    XX
   X
   X
  X
   X
   X
    XX`
View Source
const Font_JR_l_bracket = `
  XXX
  X
  X
  X
  X
  X
  XXX`
View Source
const Font_JR_l_paren = `
    X
   X
  X
  X
  X
   X
    X`
View Source
const Font_JR_lt = `

    X
   X
  X
   X
    X`
View Source
const Font_JR_m = `


XXX X
 X X X
 X X X
 X X X
XX   XX`
View Source
const Font_JR_minus = `


 XXXXX`
View Source
const Font_JR_n = `


XXXXX
 X   X
 X   X
 X   X
XX   XX`
View Source
const Font_JR_o = `


 XXXX
X    X
X     X
X     X
 XXXXX`
View Source
const Font_JR_p = `


XXXXXX
 X    X
 X    X
 XXXXX
 X
XX`
View Source
const Font_JR_percent = `

 XX  X
 XX X
    X
   X
   X XX
  X  XX`
View Source
const Font_JR_period = `





  XX
  XX`
View Source
const Font_JR_pipe = `
   X
   X
   X
   X
   X
   X
   X
   X`
View Source
const Font_JR_plus = `

   X
   X
 XXXXX
   X
   X`
View Source
const Font_JR_q = `


 XXXXXX
X    X
X    X
 XXXXX
     X
     XX`
View Source
const Font_JR_question = `
  XXXX
 X   XX
     XX
   XXX
   XX

   XX`
View Source
const Font_JR_quot = `
   XX
   XX
    X`
View Source
const Font_JR_r = `


XX XXX
 XX   X
 X
 X
XXX`
View Source
const Font_JR_r_brace = `
  XX
    X
    X
     X
    X
    X
  XX`
View Source
const Font_JR_r_bracket = `
  XXX
    X
    X
    X
    X
    X
  XXX`
View Source
const Font_JR_r_paren = `
  X
   X
    X
    X
    X
   X
  X`
View Source
const Font_JR_s = `


 XXXXX
X
 XXXXX
      X
 XXXXX`
View Source
const Font_JR_semicolon = `

  XX
  XX

  XX
  XX
   X`
View Source
const Font_JR_sharp = `

  X  X
 XXXXXX
  X  X
 XXXXXX
  X  X`
View Source
const Font_JR_slash = `

     X
    X
    X
   X
   X
  X`
View Source
const Font_JR_sm_0 = `
XX
X X
X X
X X
X X
 XX`
View Source
const Font_JR_sm_1 = `
 X
 X
XX
 X
 X
XXX`
View Source
const Font_JR_sm_2 = `
XX
X X
  X
  X
 X
XXX`
View Source
const Font_JR_sm_3 = `
XX
X X
  X
 X
  X
XXX`
View Source
const Font_JR_sm_4 = `
X
X X
X X
XXX
  X
  X`
View Source
const Font_JR_sm_5 = `
XXX
X
X
XXX
  X
XX`
View Source
const Font_JR_sm_6 = `
XX
X X
X
XXX
X X
 XX`
View Source
const Font_JR_sm_7 = `
XXX
  X
  X
 X
 X
 X`
View Source
const Font_JR_sm_8 = `
XX
X X
X X
 X
X X
 XX`
View Source
const Font_JR_sm_9 = `
XX
X X
X X
 XX
  X
XX`
View Source
const Font_JR_sm_A = `
XX
X X
X X
XXX
X X
X X`
View Source
const Font_JR_sm_B = `
XX
X X
X X
XX
X X
XX`
View Source
const Font_JR_sm_C = `
XX
X X
X
X
X
 XX`
View Source
const Font_JR_sm_D = `
XX
X X
X X
X X
X X
XX`
View Source
const Font_JR_sm_E = `
XXX
X
X
XX
X
XXX`
View Source
const Font_JR_sm_F = `
XXX
X
X
XX
X
X`
View Source
const Font_JR_sm_G = `
XX
X X
X
X X
X X
XXX`
View Source
const Font_JR_sm_H = `
X X
X X
X X
XXX
X X
X X`
View Source
const Font_JR_sm_I = `
XXX
 X
 X
 X
 X
XXX`
View Source
const Font_JR_sm_J = `
XXX
  X
  X
  X
  X
  X
XX`
View Source
const Font_JR_sm_K = `
X X
X X
X X
XX
X X
X X`
View Source
const Font_JR_sm_L = `
X
X
X
X
X
XXX`
View Source
const Font_JR_sm_M = `
X X
XXX
XXX
X X
X X
X X`
View Source
const Font_JR_sm_N = `
XX
X X
X X
X X
X X
X X`
View Source
const Font_JR_sm_O = `
XX
X X
X X
X X
X X
 XX`
View Source
const Font_JR_sm_P = `
XX
X X
X X
XX
X
X`
View Source
const Font_JR_sm_Q = `
XX
X X
X X
X X
X X
 XX
 X`
View Source
const Font_JR_sm_R = `
XX
X X
X X
XX
X X
X X`
View Source
const Font_JR_sm_S = `
 X
X X
X
XXX
  X
XX`
View Source
const Font_JR_sm_T = `
XXX
 X
 X
 X
 X
 X`
View Source
const Font_JR_sm_U = `
X X
X X
X X
X X
X X
 XX`
View Source
const Font_JR_sm_V = `
X X
X X
X X
X X
XX
X`
View Source
const Font_JR_sm_W = `
X X
X X
X X
XXX
XXX
X X`
View Source
const Font_JR_sm_X = `
X X
X X
X X
 X
X X
X X`
View Source
const Font_JR_sm_Y = `
X X
X X
X X
 X
 X
 X`
View Source
const Font_JR_sm_Z = `
XXX
  X
 X
X
X
XXX`
View Source
const Font_JR_sm_a = `

XX
  X
 XX
X X
 XX`
View Source
const Font_JR_sm_amp = `
 X
X X
 X
X X
X
 XX`
View Source
const Font_JR_sm_at = `
 X
X X
XXX
XXX
X
 XX`
View Source
const Font_JR_sm_b = `
X
XX
X X
X X
X X
XXX`
View Source
const Font_JR_sm_b_slash = `
X
X
 X
 X
  X
  X`
View Source
const Font_JR_sm_c = `

XX
X X
X
X
 XX`
View Source
const Font_JR_sm_colon = `

XX
XX

XX
XX`
View Source
const Font_JR_sm_comma = `




XX
XX
 X`
View Source
const Font_JR_sm_d = `
  X
 XX
X X
X X
X X
XXX`
View Source
const Font_JR_sm_dollars = `
 X
XXX
XX
  X
XXX
 X`
View Source
const Font_JR_sm_double_quot = `
X X
X X`
View Source
const Font_JR_sm_down = `



X X
 X`
View Source
const Font_JR_sm_e = `

XX
X X
XXX
X
 XX`
View Source
const Font_JR_sm_equals = `

XXX

XXX`
View Source
const Font_JR_sm_eszett = `
 X
X X
XX
X X
X X
XXX
 X`
View Source
const Font_JR_sm_exclamation = `
XX
XX
XX
X

X`
View Source
const Font_JR_sm_f = `
  X
 X
 X
XXX
 X
 X`
View Source
const Font_JR_sm_g = `

XX
X X
X X
 XX
  X
XX`
View Source
const Font_JR_sm_gt = `
X
 X
  X
 X
X`
View Source
const Font_JR_sm_h = `
X
XX
X X
X X
X X
X X`
View Source
const Font_JR_sm_i = `
 X

XX
 X
 X
XXX`
View Source
const Font_JR_sm_j = `
 X

XXX
  X
  X
  X
XX`
View Source
const Font_JR_sm_k = `
X
X X
X X
XX
X X
X X`
View Source
const Font_JR_sm_l = `
XX
 X
 X
 X
 X
  X`
View Source
const Font_JR_sm_l_brace = `
 XX
 X
X 
 X
 X
 XX`
View Source
const Font_JR_sm_l_bracket = `
XX
X
X
X
X
XX`
View Source
const Font_JR_sm_l_paren = `
 X
X
X
X
X
 X`
View Source
const Font_JR_sm_lt = `
  X
 X
X
 X
  X`
View Source
const Font_JR_sm_m = `

X X
XXX
XXX
X X
X X`
View Source
const Font_JR_sm_minus = `


XXX`
View Source
const Font_JR_sm_n = `

XX
X X
X X
X X
X X`
View Source
const Font_JR_sm_o = `

XX
X X
X X
X X
 XX`
View Source
const Font_JR_sm_p = `

XX
X X
X X
X X
XX
X`
View Source
const Font_JR_sm_percent = `
X X
  X
 X
 X
X
X X`
View Source
const Font_JR_sm_period = `




XX
XX`
View Source
const Font_JR_sm_pipe = `X
X
X
X
X
X
X
 X`
View Source
const Font_JR_sm_plus = `
 X
 X
XXX
 X
 X`
View Source
const Font_JR_sm_q = `

 XX
X X
X X
X X
 XX
  X`
View Source
const Font_JR_sm_question = `
XX
X X
  X
 X

 X`
View Source
const Font_JR_sm_quot = `
 X
 X`
View Source
const Font_JR_sm_r = `

XX
X X
X
X
X`
View Source
const Font_JR_sm_r_brace = `
XX
 X
  X
 X
 X
XX`
View Source
const Font_JR_sm_r_bracket = `
 XX
  X
  X
  X
  X
 XX`
View Source
const Font_JR_sm_r_paren = `
 X
  X
  X
  X
  X
 X`
View Source
const Font_JR_sm_s = `

 XX
X
XXX
  X
XX`
View Source
const Font_JR_sm_semicolon = `

XX
XX

XX
XX
 X`
View Source
const Font_JR_sm_sharp = `
X X
XXX
X X
XXX
X X`
View Source
const Font_JR_sm_slash = `
  X
  X
 X
 X
X
X`
View Source
const Font_JR_sm_star = `
X X
XXX
XXX
X X`
View Source
const Font_JR_sm_t = `
 X
XXX
 X
 X
 X
  X`
View Source
const Font_JR_sm_tilde = `
XX
X X`
View Source
const Font_JR_sm_times = `
X X
 X
XXX
 X
X X`
View Source
const Font_JR_sm_u = `

X X
X X
X X
X X
 XX`
View Source
const Font_JR_sm_underscore = `






XXX`
View Source
const Font_JR_sm_up = `

 X
X X`
View Source
const Font_JR_sm_v = `

X X
X X
X X
XX
X`
View Source
const Font_JR_sm_w = `

X X
X X
XXX
XXX
X X`
View Source
const Font_JR_sm_x = `

X X
X X
 X
X X
X X`
View Source
const Font_JR_sm_y = `

X X
X X
X X
 XX
  X
XX`
View Source
const Font_JR_sm_z = `

XXX
  X
 X
X
XXX`
View Source
const Font_JR_star = `

 X   X
  XXX
  X X
  XXX
 X   X`
View Source
const Font_JR_t = `

   X
  XXXX
   X
   X
   X
    XX`
View Source
const Font_JR_tilde = `
 XXX  X
X  XXX`
View Source
const Font_JR_times = `

   X
 X X X
  XXX
  XXX
 X X X
   X`
View Source
const Font_JR_u = `


XX   XX
 X   X
 X   X
 X   X
  XXX`
View Source
const Font_JR_underscore = `







XXXXXXXX`
View Source
const Font_JR_up = `

   X
  X X
 X   X`
View Source
const Font_JR_v = `


XX   XX
 X   X
 X  X
 X X
 XX`
View Source
const Font_JR_w = `


XX   XX
 X X X
 X X X
 X X X
 XX X`
View Source
const Font_JR_x = `


XX   XX
  X X
   X
  X X
XX   XX`
View Source
const Font_JR_y = `


XX   XX
 X   X
 X   X
  XXXX
     X
 XXXX`
View Source
const Font_JR_z = `


XXXXXXX
X    XX
  XXX
XX    X
XXXXXXX`
View Source
const Font_a = `
 X
X X
XXX
X X
X X`
View Source
const Font_b = `
XX
X X
XX
X X
XX`
View Source
const Font_c = `
 XX
X
X
X
 XX`
View Source
const Font_comma = `    



 X
 X`
View Source
const Font_d = `
XX
X X
X X
X X
XXX`
View Source
const Font_dash = `    


XXX`
View Source
const Font_e = `
XXX
X
XX
X
XXX`
View Source
const Font_exclamation = `    
 X
 X
 X

 X`
View Source
const Font_f = `
XXX
X
XX
X
X`
View Source
const Font_g = `
 XX
X
X
X X
XXX`
View Source
const Font_h = `
X X
X X
XXX
X X
X X`
View Source
const Font_i = `
XXX
 X
 X
 X
XXX`
View Source
const Font_j = `
XXX
 X
 X
 X
XX`
View Source
const Font_k = `
X X
X X
XX
X X
X X`
View Source
const Font_l = `
X
X
X
X
XXX`
View Source
const Font_m = `
X X
XXX
XXX
X X
X X`
View Source
const Font_n = `
XX
X X
X X
X X
X X`
View Source
const Font_o = `
 XX
X X
X X
X X
XX`
View Source
const Font_p = `
XX
X X
XX
X
X`
View Source
const Font_percent = `    
X X
  X
 X
X
X X`
View Source
const Font_period = `    




 X`
View Source
const Font_q = `
 XX
X X
X X
XXX
  X`
View Source
const Font_r = `
XX
X X
XX
X X
X X`
View Source
const Font_s = `
 XX
X
XXX
  X
XX`
View Source
const Font_slash = `    
  X
 X
 X
 X
X`
View Source
const Font_t = `
XXX
 X
 X
 X
 X`
View Source
const Font_u = `
X X
X X
X X
X X
 XX`
View Source
const Font_v = `
X X
X X
X X
X X
 X`
View Source
const Font_w = `
X X
X X
XXX
XXX
X X`
View Source
const Font_x = `
X X
X X
 X
X X
X X`
View Source
const Font_y = `
X X
X X
XXX
  X
XXX`
View Source
const Font_z = `
XXX
  X
 X
X
XXX`

Variables

View Source
var Blocks = map[int]rune{
	0:  ' ',
	1:  '▘',
	2:  '▝',
	3:  '▀',
	4:  '▖',
	5:  '▌',
	6:  '▞',
	7:  '▛',
	8:  '▗',
	9:  '▚',
	10: '▐',
	11: '▜',
	12: '▄',
	13: '▙',
	14: '▟',
	15: '█',
}

Blocks provides a map of bits to Unicode block character runes.

View Source
var ColorMap = map[rune]tm.Attribute{
	'R': tm.ColorRed,
	'b': tm.Attribute(53),
	't': tm.Attribute(180),
	'Y': tm.ColorYellow,
	'N': tm.ColorBlack,
	'B': tm.ColorBlue,
	'o': tm.Attribute(209),
	'O': tm.Attribute(167),
	'w': tm.ColorWhite,
	'X': tm.ColorWhite,
	'g': tm.ColorGreen,
	'G': tm.Attribute(35),
}

ColorMap provides an interpolation map of characters to termbox colors.

Functions

This section is empty.

Types

type Background

type Background interface {
	Init()
	Update()
	Render()
	AddBackground(t string)
}

A Background interface provides methods for initializing, updating, and rendering sprites.

type BaseBackground

type BaseBackground struct {
	X          int
	Y          int
	Height     int
	Width      int
	Tiled      bool
	Background []Block
}

A BaseBackground is a 2D background which sits behind Sprites.

func (*BaseBackground) AddBackground

func (s *BaseBackground) AddBackground(t string)

func (*BaseBackground) Init

func (s *BaseBackground) Init()

Init provides a hook for initializing a background.

func (*BaseBackground) Render

func (s *BaseBackground) Render()

Render draws background to the buffer.

func (*BaseBackground) Update

func (s *BaseBackground) Update()

Update provides a hook for updating a background during the main loop.

type BaseSprite

type BaseSprite struct {
	X              int
	Y              int
	Height         int
	Width          int
	Costumes       []*Costume
	BlockCostumes  []*Surface
	Alpha          rune
	Visible        bool
	CurrentCostume int
	Dead           bool
	Events         map[string]*Event
}

A BaseSprite is a 2D sprite primitive.

func NewBaseSprite

func NewBaseSprite(x, y int, costume Costume) *BaseSprite

NewBaseSprite creates a new BaseSprite from X and Y coordinates and a costume.

func (*BaseSprite) AddCostume

func (s *BaseSprite) AddCostume(costume Costume)

AddCostume adds a costume to a BaseSprite.

func (*BaseSprite) BlockRender

func (s *BaseSprite) BlockRender(bg *Surface)

BlockRender draws the sprite to the background surface

func (*BaseSprite) HitAtPoint

func (s *BaseSprite) HitAtPoint(x, y int) bool

HitAtPoint reports whether a point on the screen intersects with this sprite.

func (*BaseSprite) HitAtPointSurface

func (s *BaseSprite) HitAtPointSurface(x, y int) bool

HitAtPointSurface reports whether a point on the surface intersects with this sprite.

func (*BaseSprite) Init

func (s *BaseSprite) Init()

Init provides a hook for initializing a sprite.

func (*BaseSprite) IsDead added in v0.1.6

func (s *BaseSprite) IsDead() bool

IsDead returns if the sprite is dead and should be reaped.

func (*BaseSprite) NextCostume

func (s *BaseSprite) NextCostume()

NextCostume changes a sprite's costume to the next costume.

func (*BaseSprite) PrevCostume

func (s *BaseSprite) PrevCostume()

PrevCostume changes a sprite's costume to the previous costume.

func (*BaseSprite) RegisterEvent

func (s *BaseSprite) RegisterEvent(name string, fn func())

RegisterEvent registers a callback function with a name in this sprite.

func (*BaseSprite) RemoveEvent

func (s *BaseSprite) RemoveEvent(name string) bool

RemoveEvent removes an event with a given name from this sprite.

func (*BaseSprite) Render

func (s *BaseSprite) Render()

Render draws the sprite to the screen buffer.

func (*BaseSprite) SetCostume

func (s *BaseSprite) SetCostume(c int)

SetCostume sets the current costume of a BaseSprite.

func (*BaseSprite) TriggerEvent

func (s *BaseSprite) TriggerEvent(name string) bool

TriggerEvent causes a previously registered callback function to be called.

func (*BaseSprite) Update

func (s *BaseSprite) Update()

Update provides a hook for updating a sprite during the main loop.

type Block

type Block struct {
	Char rune
	Fg   tm.Attribute
	Bg   tm.Attribute
	X    int
	Y    int
}

Block holds a rune at (X,Y).

type Costume

type Costume struct {
	Blocks []*Block
	Width  int
	Height int
}

Costume contains a slice of Block pointers.

func ColorConvert

func ColorConvert(s string, bg tm.Attribute) Costume

ColorConvert convenience function to create a color Costume from a string

func Convert

func Convert(s string) Costume

Convert is a convenience function to create a 1 bit Costume from a string

func NewCostume

func NewCostume(t string, alpha rune) Costume

NewCostume provides a new Costume from a string.

func (*Costume) BottomEdge

func (c *Costume) BottomEdge() int

BottomEdge returns the Y value of the lowest Block in a Costume.

func (*Costume) BottomEdgeByColumn

func (c *Costume) BottomEdgeByColumn() map[int]int

BottomEdgeByColumn returns a map of the lowest Y value in each column of a Costume.

func (*Costume) ChangeCostume

func (c *Costume) ChangeCostume(t string, alpha rune)

ChangeCostume replaces a Costume with a new Costume from a string.

func (*Costume) LeftEdge

func (c *Costume) LeftEdge() int

LeftEdge returns the X value of the furthest left Block in a Costume.

func (*Costume) LeftEdgeByRow

func (c *Costume) LeftEdgeByRow() map[int]int

LeftEdgeByRow returns a map of the left most X value in each row of a Costume.

func (*Costume) RightEdge

func (c *Costume) RightEdge() int

RightEdge returns the X value of the furthest right Block in a Costume.

func (*Costume) RightEdgeByRow

func (c *Costume) RightEdgeByRow() map[int]int

RightEdgeByRow returns a map of the right most X value in each row of a Costume.

func (*Costume) TopEdge

func (c *Costume) TopEdge() int

TopEdge returns the Y value of the heighest Block in a Costume.

func (*Costume) TopEdgeByColumn

func (c *Costume) TopEdgeByColumn() map[int]int

TopEdgeByColumn returns a map of the heighest Y value in each column of a Costume.

type EdgeType

type EdgeType int
const (
	UpperLeftEdge EdgeType = iota
	UpperRightEdge
	LowerLeftEdge
	LowerRightEdge
)

type Event

type Event struct {
	Callback func()
	Count    int
}

type Font

type Font struct {
	Map    map[rune]string
	Width  int
	Height int
}

Font provides monospaced Unicode banner fonts

func New90sFont added in v0.1.3

func New90sFont() *Font

New90sFont provides a new font from based upon 90s era LCDs

func NewFont

func NewFont(m map[rune]string, w, h int) *Font

NewFont provides a monospaced banner font based upon a mapping and size

func NewJRFont

func NewJRFont() *Font

NewJRFont provides a font based upon Jim Reed's RPG Tileset

func NewJRSMFont

func NewJRSMFont() *Font

NewJRFont provides a font based upon Jim Reed's RPG Tileset

func NewPakuFont

func NewPakuFont() *Font

NewPakuFont provides a new font from based upon Paku Paku

func (*Font) BuildString

func (f *Font) BuildString(s string) string

BuildString provides a unicode block string from an ASCII string.

type Point

type Point struct {
	X int
	Y int
}

A Point provides a point on the screen at (X,Y)

type Rect

type Rect struct {
	X int
	Y int
	W int
	H int
}

A Rect provides a rectangle starting at (X,Y) with W width and H height

type Sprite

type Sprite interface {
	Init()
	Update()
	Render()
	BlockRender(*Surface)
	AddCostume(Costume)
	SetCostume(int)
	NextCostume()
	PrevCostume()
	TriggerEvent(string) bool
	IsDead() bool
}

A Sprite interface provides methods for initializing, updating, and rendering sprites.

type SpriteGroup

type SpriteGroup struct {
	Sprites    []Sprite
	Events     chan string
	BlockMode  bool
	Background tm.Attribute
	// contains filtered or unexported fields
}

A SpriteGroup is a convenience method for holding groups of sprites.

func (*SpriteGroup) Init

func (sg *SpriteGroup) Init(width, height int, blockMode bool)

Init initializes the event channel and sets the BlockMode

func (*SpriteGroup) MoveToTop added in v0.1.3

func (sg *SpriteGroup) MoveToTop(s Sprite)

MoveToTop renders a sprite over all other sprites in the SpriteGroup.

func (*SpriteGroup) Remove

func (sg *SpriteGroup) Remove(s Sprite)

Remove removes a given sprite from the SpriteGroup.

func (*SpriteGroup) RemoveAll

func (sg *SpriteGroup) RemoveAll()

RemoveAll removes all sprites from the SpriteGroup.

func (*SpriteGroup) Render

func (sg *SpriteGroup) Render()

Render draws each sprite in the SpriteGroup to the buffer.

func (*SpriteGroup) Resize

func (sg *SpriteGroup) Resize(width, height int)

Resize changes the size of the drawing buffer in BlockMode

func (*SpriteGroup) TriggerEvent

func (sg *SpriteGroup) TriggerEvent(name string)

TriggerEvent causes all events of this name to be called.

func (*SpriteGroup) Update

func (sg *SpriteGroup) Update()

Update updates each sprite in the SpriteGroup.

type Surface

type Surface struct {
	Blocks [][]rune
	Width  int
	Height int
	Alpha  bool
}

func NewSurface

func NewSurface(width, height int, alpha bool) Surface

NewSurface creates a Surface

func NewSurfaceFromImage added in v0.1.5

func NewSurfaceFromImage(img image.Image, alpha bool) Surface

NewSurfaceFromImage returns a Surface from an image.Image

func NewSurfaceFromPng

func NewSurfaceFromPng(fn string, alpha bool) Surface

NewSurfaceFromPng returns a Surface from a PNG file

func NewSurfaceFromString

func NewSurfaceFromString(s string, alpha bool) Surface

NewSurfaceFromString creates a Surface which can be converted to a Costume

func NewSurfacesFromPngSheet added in v0.1.5

func NewSurfacesFromPngSheet(fn string, r image.Rectangle, alpha bool) []Surface

func (Surface) Blit

func (s Surface) Blit(t Surface, x, y int) error

Blit a Surface onto a Surface

func (Surface) Circle added in v0.1.6

func (s Surface) Circle(xc, yc, r int, ch rune, fill bool) error

Draw a circle on a Surface

func (*Surface) Clear

func (s *Surface) Clear()

Clear removes all blocks from a Surface

func (Surface) ConvertToColorCostume

func (s Surface) ConvertToColorCostume(bg tm.Attribute) Costume

ConvertToColorCostume converts a Surface into a color Costume usable in a Sprite

func (Surface) ConvertToCostume

func (s Surface) ConvertToCostume() Costume

ConvertToCostume converts a Surface into a Costume usable in a Sprite

func (*Surface) Fill added in v0.1.6

func (s *Surface) Fill(ch rune)

Fill fills an entire surface with a rune

func (Surface) Line

func (s Surface) Line(x0, y0, x1, y1 int, ch rune) error

Draw a line between two points on a Surface

func (Surface) Point added in v0.1.6

func (s Surface) Point(x, y int, ch rune)

Draw a point on a Surface

func (Surface) Rectangle

func (s Surface) Rectangle(x0, y0, x1, y1 int, ch rune, fill bool) error

Draw a rectangle on a Surface

func (Surface) Triangle added in v0.1.6

func (s Surface) Triangle(x0, y0, x1, y1, x2, y2 int, ch rune, fill bool) error

Draw a triangle on a Surface

type TitleArrow

type TitleArrow struct {
	BaseSprite
	DX    float64
	DY    float64
	Angle float64
	Type  EdgeType
}

func NewTitleArrow

func NewTitleArrow(t EdgeType, r Rect) *TitleArrow

NewTitleArrow creates a TitleArrow in the TitleScreen.

func (*TitleArrow) Update

func (s *TitleArrow) Update()

Update moves a TitleArrow in a TitleScreen.

type TitleEdge

type TitleEdge struct {
	BaseSprite
}

func NewTitleEdge

func NewTitleEdge(t EdgeType, r Rect) *TitleEdge

NewTitleEdge create an edge marker in the TitleScreen.

type TitleScreen

type TitleScreen struct {
	Sprites SpriteGroup
}

func InitTitleScreen

func InitTitleScreen(r Rect) *TitleScreen

InitTitleScreen creates a default TitleScreen.

func (*TitleScreen) Render

func (t *TitleScreen) Render()

Render renders all of the Sprites in a TitleScreen.

func (*TitleScreen) Update

func (t *TitleScreen) Update()

Update updates all of the Sprites in a TitleScreen.

Directories

Path Synopsis
Package termbox is a compatibility layer to allow tcell to emulate the github.com/nsf/termbox package.
Package termbox is a compatibility layer to allow tcell to emulate the github.com/nsf/termbox package.

Jump to

Keyboard shortcuts

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