add types, experiments
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"title" : "Test Go+BLT App",
|
||||||
|
"fpsLimit" : 60
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,26 +5,59 @@ import (
|
|||||||
blt "bearlibterminal"
|
blt "bearlibterminal"
|
||||||
"ui"
|
"ui"
|
||||||
"util"
|
"util"
|
||||||
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
"encoding/json"
|
||||||
|
"game"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var version = "0.0.0"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting...")
|
log.Println("Starting...")
|
||||||
|
|
||||||
|
var configArg string = "./config.json"
|
||||||
|
flag.StringVar(&configArg, "cfg", configArg, "config file location")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
// get config
|
||||||
|
data, err := ioutil.ReadFile(configArg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("quoteCompressor can't read config at %s", configArg)
|
||||||
|
}
|
||||||
|
config := new(util.Config)
|
||||||
|
err = json.Unmarshal(data, config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
game.Init(config)
|
||||||
|
|
||||||
blt.Open()
|
blt.Open()
|
||||||
|
//blt.Set("window: size=80x25, title="+config.Title+" v"+string(version)+"; font: ./fonts/Monaco-Linux.ttf, size=10")
|
||||||
|
blt.Set("window: size=100x47, title="+config.Title+" v"+string(version)+"; font: ./fonts/UbuntuMono-R.ttf, size=10;")
|
||||||
defer blt.Close()
|
defer blt.Close()
|
||||||
blt.Print(1, 1, "Hello, world!")
|
blt.Print(1, 1, "Hello, [font=italic]world[/font]!")
|
||||||
|
blt.PrintExt(1, 6, 5, 4, 1, "Lorem ipsum dolor sit amet")
|
||||||
blt.Refresh()
|
blt.Refresh()
|
||||||
|
|
||||||
|
|
||||||
|
mainLoop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainLoop () {
|
||||||
|
|
||||||
var exit = false
|
var exit = false
|
||||||
|
|
||||||
for !exit {
|
for !exit {
|
||||||
var key, keycode = ui.ReadKey();
|
var key, keycode = ui.ReadKey();
|
||||||
if (key != "") {
|
if key != "" {
|
||||||
blt.Print( 1, 3, "Key: ")
|
blt.Print( 1, 3, "Key: ")
|
||||||
}
|
}
|
||||||
blt.Print( 1, 3, "Key: " + key )
|
blt.Print( 1, 3, "Key: " + key )
|
||||||
exit, _ = util.InArray(keycode, []int{blt.TK_CLOSE, blt.TK_ESCAPE})
|
exit, _ = util.InArray(keycode, []int{blt.TK_CLOSE, blt.TK_ESCAPE})
|
||||||
if (!exit) {
|
if (!exit) {
|
||||||
exit = (key == "Ctrl+q")
|
exit = key == "Ctrl+q"
|
||||||
}
|
}
|
||||||
blt.Refresh()
|
blt.Refresh()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
type char byte
|
||||||
|
type MapColor [3]int
|
||||||
|
|
||||||
|
type Level struct {
|
||||||
|
Branch string
|
||||||
|
Exits []string
|
||||||
|
Rooms []string
|
||||||
|
Map LevelMap
|
||||||
|
Mobs []*Mob
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (level *Level) Remove (mob *Mob) bool {
|
||||||
|
return DeleteFromMobSlice(level.Mobs, mob)
|
||||||
|
}
|
||||||
|
|
||||||
|
type LevelMap struct {
|
||||||
|
SizeX int
|
||||||
|
SizeY int
|
||||||
|
Geometry [][]Tile
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tile struct {
|
||||||
|
Glyph *TileGlyph
|
||||||
|
Explored bool
|
||||||
|
IsSafe bool
|
||||||
|
MustDraw bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Graphical representation of tile's glyph
|
||||||
|
type TileGlyph struct {
|
||||||
|
Char char
|
||||||
|
FgColor MapColor
|
||||||
|
BgColor MapColor
|
||||||
|
DarkFgColor MapColor
|
||||||
|
DarkBgColor MapColor
|
||||||
|
ColorDance bool
|
||||||
|
BlocksPass bool
|
||||||
|
BlocksSight bool
|
||||||
|
WaterTight bool
|
||||||
|
GasTight bool
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func DeleteFromMobSlice (slice []*Mob, item *Mob) bool {
|
||||||
|
for i := range slice {
|
||||||
|
if slice[i].name == item.name && slice[i].id == item.id {
|
||||||
|
copy(slice[i:], slice[i+1:])
|
||||||
|
slice[len(slice)-1] = nil
|
||||||
|
slice = slice[:len(slice)-1]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteFromItemSlice (slice []*Item, item *Item) bool {
|
||||||
|
for i := range slice {
|
||||||
|
if slice[i].name == item.name && slice[i].id == item.id {
|
||||||
|
copy(slice[i:], slice[i+1:])
|
||||||
|
slice[len(slice)-1] = nil
|
||||||
|
slice = slice[:len(slice)-1]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
type Identifiable struct {
|
||||||
|
id int
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (item *Identifiable) getId() int {
|
||||||
|
return item.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (item *Identifiable) getName() string {
|
||||||
|
return item.name
|
||||||
|
}
|
||||||
|
|
||||||
|
//Really this is MapObject, but htis name is ugly
|
||||||
|
type Mob struct {
|
||||||
|
Identifiable
|
||||||
|
Char char
|
||||||
|
X int
|
||||||
|
Y int
|
||||||
|
Name string
|
||||||
|
Color MapColor
|
||||||
|
BgColor MapColor
|
||||||
|
BlocksPass bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Monster struct {
|
||||||
|
*Mob
|
||||||
|
Waypoints [][2]int
|
||||||
|
//*AiInstance
|
||||||
|
//*Fighter
|
||||||
|
BackPack MonsterInventory
|
||||||
|
Size int
|
||||||
|
Weight int
|
||||||
|
}
|
||||||
|
|
||||||
|
type MonsterInventory struct {
|
||||||
|
MaxSize int
|
||||||
|
MaxWeight float32
|
||||||
|
Content []*Item
|
||||||
|
}
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
*Mob
|
||||||
|
Weight float32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me Item) Pickup(carrier *Monster) bool {
|
||||||
|
carrier.BackPack.Content = append(carrier.BackPack.Content, &me)
|
||||||
|
return State.Level.Remove(me.Mob)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me Item) Drop(carrier *Monster) bool {
|
||||||
|
State.Level.Mobs = append(State.Level.Mobs, me.Mob)
|
||||||
|
return DeleteFromItemSlice(carrier.BackPack.Content, &me)
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
import "util"
|
||||||
|
|
||||||
|
type gameState struct {
|
||||||
|
fpsLimit int
|
||||||
|
fpsTicker int
|
||||||
|
turnCount int
|
||||||
|
isWizard bool
|
||||||
|
//player Player
|
||||||
|
debugMode bool
|
||||||
|
debugAi bool
|
||||||
|
Level Level
|
||||||
|
}
|
||||||
|
|
||||||
|
var State gameState
|
||||||
|
|
||||||
|
func Init(config *util.Config) *gameState {
|
||||||
|
State := gameState{
|
||||||
|
fpsLimit: config.FpsLimit,
|
||||||
|
fpsTicker: 0,
|
||||||
|
turnCount: 0,
|
||||||
|
isWizard: false,
|
||||||
|
debugMode: true,
|
||||||
|
debugAi: true}
|
||||||
|
|
||||||
|
return &State
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetState() *gameState {
|
||||||
|
return &State
|
||||||
|
}
|
||||||
@@ -4,6 +4,12 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
FpsLimit int `json:"fpsLimit, omitempty" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func InArray(val interface{}, array interface{}) (exists bool, index int) {
|
func InArray(val interface{}, array interface{}) (exists bool, index int) {
|
||||||
exists = false
|
exists = false
|
||||||
index = -1
|
index = -1
|
||||||
|
|||||||
Reference in New Issue
Block a user