diff --git a/main.go b/main.go index f4ff10f..fea4040 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "ui" "util" "game" + "fmt" ) var version = "0.0.0" @@ -16,7 +17,58 @@ func main() { 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.Set("window: size=80x25, title="+config.Title+" v"+string(version)+"; font: ./fonts/Monaco-Linux.ttf, size=10") diff --git a/src/game/abilities.go b/src/game/abilities.go new file mode 100644 index 0000000..d1536f6 --- /dev/null +++ b/src/game/abilities.go @@ -0,0 +1,13 @@ +package game + +//spells, abilities etc +type Ability interface { + Use() +} + +//magic spellz +type Spell interface { + Ability + GetCooldown() int + ApplyCost() int +} \ No newline at end of file diff --git a/src/game/item.go b/src/game/item.go new file mode 100644 index 0000000..2f87f66 --- /dev/null +++ b/src/game/item.go @@ -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() +} diff --git a/src/game/level.go b/src/game/level.go index 75fca0c..c8f56f1 100644 --- a/src/game/level.go +++ b/src/game/level.go @@ -1,69 +1,7 @@ package game -type char byte -type MapColor [3]int - type Level struct { Branch string - Exits []string - Rooms []string - Map LevelMap - Mobs []*Mob + Map Map + Mobs map[Identifiable]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 -} \ No newline at end of file diff --git a/src/game/map.go b/src/game/map.go new file mode 100644 index 0000000..adb5f44 --- /dev/null +++ b/src/game/map.go @@ -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} +} \ No newline at end of file diff --git a/src/game/mob.go b/src/game/mob.go index 8a65cb4..00e8bcc 100644 --- a/src/game/mob.go +++ b/src/game/mob.go @@ -1,57 +1,31 @@ package game -type Identifiable struct { - id int - name string +//see https://stackoverflow.com/questions/32188653/golang-and-inheritance + +//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 { - return item.id +//something that must be ai-processed +type Sentient interface { + SetAi() + GetAi() + TakeTurn() } -func (item *Identifiable) getName() string { - return item.name +//Something that can fight +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) -} \ No newline at end of file diff --git a/src/game/state.go b/src/game/state.go index 227d72a..cde26fe 100644 --- a/src/game/state.go +++ b/src/game/state.go @@ -1,32 +1 @@ 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 -} \ No newline at end of file