working prototype with ecs
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
package mob
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"reflect"
|
||||
)
|
||||
@ -13,26 +11,10 @@ type Mob struct {
|
||||
BlocksPass bool
|
||||
}
|
||||
|
||||
func (m *Mob) Walk(level *gamemap.Level, dx, dy int) {
|
||||
newCoords := types.Coords{m.X + dx, m.Y + dy}
|
||||
if level.GetTile(newCoords).BlocksPass {
|
||||
return
|
||||
}
|
||||
//fixme
|
||||
//if level.Objects.At(newCoords).HasComponent("block_pass") {
|
||||
//
|
||||
//}
|
||||
fmt.Printf("new coords: %d, %d\n", m.Coords.X, m.Coords.Y)
|
||||
}
|
||||
|
||||
func (m *Mob) Render() {
|
||||
|
||||
}
|
||||
|
||||
func (m *Mob) MoveToCoords(c types.Coords) {
|
||||
|
||||
}
|
||||
|
||||
func (mob Mob) TypeOf() reflect.Type {
|
||||
return reflect.TypeOf(mob)
|
||||
}
|
50
engine/mob/movement/movement.go
Normal file
50
engine/mob/movement/movement.go
Normal file
@ -0,0 +1,50 @@
|
||||
package movement
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/mob"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Moveable struct {
|
||||
Controller *ecs.Controller
|
||||
Level *gamemap.Level
|
||||
}
|
||||
|
||||
|
||||
func (mov Moveable) Walk() {
|
||||
|
||||
}
|
||||
|
||||
func (mov Moveable) IsBlocked(c types.Coords) bool {
|
||||
if mov.Level.GetTile(c).BlocksPass == true {
|
||||
return true
|
||||
}
|
||||
list := mov.Controller.GetEntitiesWithComponent(mob.Mob{}.TypeOf())
|
||||
for idx, _ := range list {
|
||||
coords := mov.Controller.GetComponent(list[idx], types.Coords{}.TypeOf())
|
||||
if coords == nil {
|
||||
continue
|
||||
}
|
||||
coords = coords.(types.Coords)
|
||||
if coords != c {
|
||||
continue
|
||||
}
|
||||
m := mov.Controller.GetComponent(list[idx], mob.Mob{}.TypeOf())
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
if m.(mob.Mob).BlocksPass {
|
||||
return true
|
||||
}
|
||||
}
|
||||
fmt.Printf("\nCoords %v do not block pass!", c)
|
||||
return false
|
||||
}
|
||||
|
||||
func (mov Moveable) TypeOf() reflect.Type {
|
||||
return reflect.TypeOf(mov)
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package mob
|
||||
|
||||
type Player struct {
|
||||
Mob
|
||||
}
|
Reference in New Issue
Block a user