Example #1
0
func main() {
	db := engine.NewEntityDB()
	base.RegisterTypes(db)

	entity := db.New("health", "attack")

	health := db.Get(entity, "health").(*base.Health)
	attack := db.Get(entity, "attack").(*base.Attack)

	health.SetMax(10)
	health.SetCurrent(5)
	health.Mod(-9)
	attack.Damage = 5

	fmt.Println(db.Get(entity, "health"))
	fmt.Println(db.Get(entity, "attack"))
}
Example #2
0
func NewGameState(numbats int64) *GameState {
	// Game Data Initialization
	db := engine.NewEntityDB()
	base.RegisterTypes(db)

	tilemap := CreateMap(db)

	player := db.New("movement")
	db.Set(player, "ai", base.NewAI(NewPlayerAI()))
	db.Set(player, "art", base.NewArt('@', 1, 0, 0, 0, 0, 0))
	base.HelperPlace(db, player, tilemap, 0, 0, 1)

	bat := db.New("movement")
	db.Set(bat, "ai", base.NewAI(NewFollowAI(player)))
	db.Set(bat, "art", base.NewArt('b', 0, 0, 1, 0, 0, 0))

	// Create bats from the template entity
	for i := int64(0); i < numbats; i++ {
		newBat := db.Instance(bat)
		base.HelperPlace(db, newBat, tilemap, rand.Int63n(numbats)-numbats/2, rand.Int63n(numbats)-numbats/2, 2)
	}

	return &GameState{DB: db}
}