world ticking
parent
81801e640a
commit
0c812ce97b
@ -0,0 +1,8 @@
|
||||
package sim
|
||||
|
||||
type floor int
|
||||
|
||||
const (
|
||||
fl_nothing floor = iota
|
||||
fl_rock
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
package sim
|
||||
|
||||
// player represents a player character in the simulation
|
||||
type player struct {
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package sim
|
||||
|
||||
type point struct { x, y int }
|
@ -1,4 +1,7 @@
|
||||
package sim
|
||||
|
||||
type Room struct {
|
||||
type room struct {
|
||||
origin point
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package sim
|
||||
|
||||
type tile struct {
|
||||
floor floor
|
||||
contents []entity
|
||||
}
|
@ -1,4 +1,44 @@
|
||||
package sim
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jordanorelli/blammo"
|
||||
)
|
||||
|
||||
// World is the entire simulated world. A world consists of many rooms.
|
||||
type World struct {
|
||||
*blammo.Log
|
||||
rooms []room
|
||||
}
|
||||
|
||||
func NewWorld(log *blammo.Log) *World {
|
||||
return &World{
|
||||
Log: log,
|
||||
rooms: []room{
|
||||
room{
|
||||
origin: point{0, 0},
|
||||
width: 10,
|
||||
height: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (w *World) Run(hz int) {
|
||||
period := time.Second / time.Duration(hz)
|
||||
w.Info("starting world with a tick rate of %dhz, frame duration of %v", hz, period)
|
||||
ticker := time.NewTicker(period)
|
||||
lastTick := time.Now()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
w.tick(time.Since(lastTick))
|
||||
lastTick = time.Now()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *World) tick(d time.Duration) {
|
||||
w.Info("tick. elapsed: %v", d)
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package ui
|
||||
|
||||
// buffer is a rect of tiles
|
||||
type buffer struct {
|
||||
width int
|
||||
height int
|
||||
tiles []tile
|
||||
}
|
||||
|
||||
func newBuffer(width, height int) *buffer {
|
||||
return &buffer{
|
||||
width: width,
|
||||
height: height,
|
||||
tiles: make([]tile, width*height),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *buffer) set(x, y int, t tile) { b.tiles[y*b.width+x] = t }
|
||||
func (b *buffer) get(x, y int) tile { return b.tiles[y*b.width+x] }
|
@ -0,0 +1,11 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type tile struct {
|
||||
r rune
|
||||
combc []rune
|
||||
style tcell.Style
|
||||
}
|
Loading…
Reference in New Issue