update to interfaces
This commit is contained in:
parent
503af72b47
commit
6ca54b61c4
54
main.go
54
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"ui"
|
"ui"
|
||||||
"util"
|
"util"
|
||||||
"game"
|
"game"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "0.0.0"
|
var version = "0.0.0"
|
||||||
@ -16,7 +17,58 @@ func main() {
|
|||||||
|
|
||||||
config := util.LoadConfig()
|
config := util.LoadConfig()
|
||||||
|
|
||||||
game.Init(config)
|
var testState = game.Init(config)
|
||||||
|
|
||||||
|
var test = game.Item{
|
||||||
|
&game.Mob{
|
||||||
|
game.Identifiable{
|
||||||
|
1,
|
||||||
|
"testitem1",
|
||||||
|
},
|
||||||
|
'!',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
"test potion",
|
||||||
|
game.MapColor{1,254,254, 254},
|
||||||
|
game.MapColor{1, 0, 0, 0},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
12}
|
||||||
|
|
||||||
|
testState.Level.Mobs = append(testState.Level.Mobs, test.Mob)
|
||||||
|
|
||||||
|
var actor = game.Monster{
|
||||||
|
&game.Mob{
|
||||||
|
game.Identifiable{
|
||||||
|
2,
|
||||||
|
"testactor2",
|
||||||
|
},
|
||||||
|
'A',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
"Actor for testing",
|
||||||
|
game.MapColor{1, 233, 254,254},
|
||||||
|
game.MapColor{1, 0, 0, 0},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
[]*game.Coords{},
|
||||||
|
game.MonsterInventory{
|
||||||
|
1,
|
||||||
|
100,
|
||||||
|
[]*game.Item{},
|
||||||
|
},
|
||||||
|
1,
|
||||||
|
500,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%v", testState)
|
||||||
|
|
||||||
|
test.Pickup(&actor)
|
||||||
|
fmt.Printf("%v", testState)
|
||||||
|
fmt.Printf("%v", actor)
|
||||||
|
fmt.Printf("%v", test)
|
||||||
|
|
||||||
|
test.Drop(&actor)
|
||||||
|
|
||||||
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=80x25, title="+config.Title+" v"+string(version)+"; font: ./fonts/Monaco-Linux.ttf, size=10")
|
||||||
|
13
src/game/abilities.go
Normal file
13
src/game/abilities.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
//spells, abilities etc
|
||||||
|
type Ability interface {
|
||||||
|
Use()
|
||||||
|
}
|
||||||
|
|
||||||
|
//magic spellz
|
||||||
|
type Spell interface {
|
||||||
|
Ability
|
||||||
|
GetCooldown() int
|
||||||
|
ApplyCost() int
|
||||||
|
}
|
26
src/game/item.go
Normal file
26
src/game/item.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
//something that could be carried and dropped
|
||||||
|
type Luggage interface {
|
||||||
|
Mob
|
||||||
|
Drop(carrier Monster) bool
|
||||||
|
Pickup(carrier Monster) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
//something that could be used from inventory
|
||||||
|
type Usable interface {
|
||||||
|
GetUsageVariants() //not Use() cause you could do many things with a potion - drink and throw for instance
|
||||||
|
Use(variant string)
|
||||||
|
}
|
||||||
|
//Item that could be carried and used
|
||||||
|
type Item interface {
|
||||||
|
Luggage
|
||||||
|
Usable
|
||||||
|
}
|
||||||
|
|
||||||
|
//something you can wear
|
||||||
|
type Wearable interface {
|
||||||
|
Luggage
|
||||||
|
Wear()
|
||||||
|
Takeoff()
|
||||||
|
}
|
@ -1,69 +1,7 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
type char byte
|
|
||||||
type MapColor [3]int
|
|
||||||
|
|
||||||
type Level struct {
|
type Level struct {
|
||||||
Branch string
|
Branch string
|
||||||
Exits []string
|
Map Map
|
||||||
Rooms []string
|
Mobs map[Identifiable]Mob
|
||||||
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
|
|
||||||
}
|
|
36
src/game/map.go
Normal file
36
src/game/map.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
type Map struct {
|
||||||
|
SizeX int
|
||||||
|
SizeY int
|
||||||
|
Geometry [][]Tile
|
||||||
|
}
|
||||||
|
|
||||||
|
//just coordinates
|
||||||
|
type Coords struct {
|
||||||
|
X, Y int
|
||||||
|
}
|
||||||
|
|
||||||
|
type color struct {
|
||||||
|
alpha int
|
||||||
|
red int
|
||||||
|
green int
|
||||||
|
blue int
|
||||||
|
}
|
||||||
|
|
||||||
|
//packed char, fgColor, bgColor and render settings
|
||||||
|
type Drawable struct {
|
||||||
|
Char string
|
||||||
|
fgColor color
|
||||||
|
bgColor color
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tile struct {
|
||||||
|
Drawable
|
||||||
|
BlocksPass bool
|
||||||
|
BlocksSight bool
|
||||||
|
//colordance and other stuff later
|
||||||
|
}
|
||||||
|
func (tile *Tile) NewTile (char string, fgColor color, bgColor color) Tile {
|
||||||
|
return Tile{Drawable{char, fgColor, bgColor}, false, false}
|
||||||
|
}
|
@ -1,57 +1,31 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
type Identifiable struct {
|
//see https://stackoverflow.com/questions/32188653/golang-and-inheritance
|
||||||
id int
|
|
||||||
name string
|
//something that could be placed on map - MapObject
|
||||||
|
type Mob interface {
|
||||||
|
Drawable
|
||||||
|
GetCoords() Coords
|
||||||
|
SetCoords(x, y int)
|
||||||
|
SetX(x int)
|
||||||
|
SetY(y int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (item *Identifiable) getId() int {
|
//something that must be ai-processed
|
||||||
return item.id
|
type Sentient interface {
|
||||||
|
SetAi()
|
||||||
|
GetAi()
|
||||||
|
TakeTurn()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (item *Identifiable) getName() string {
|
//Something that can fight
|
||||||
return item.name
|
type Fighter interface {
|
||||||
|
Mob
|
||||||
|
Spawn()
|
||||||
|
Die()
|
||||||
|
Attack()
|
||||||
|
Move()
|
||||||
|
GetBuffs()
|
||||||
|
SetBuffs()
|
||||||
}
|
}
|
||||||
|
|
||||||
//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)
|
|
||||||
}
|
|
@ -1,32 +1 @@
|
|||||||
package game
|
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
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user