fuck engo

This commit is contained in:
David Alasow 2017-12-28 12:25:14 +01:00
parent 12eccc3fae
commit 38a9438713
3 changed files with 133 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,86 @@
package systems
import (
"engo.io/ecs"
"engo.io/engo"
"engo.io/engo/common"
"fmt"
"log"
)
type System interface {
// Update is ran every frame, with `dt` being the time
// in seconds since the last frame
Update(dt float32)
// Remove removes an Entity from the System
Remove(ecs.BasicEntity)
}
type City struct {
ecs.BasicEntity
common.RenderComponent
common.SpaceComponent
}
type MouseTracker struct {
ecs.BasicEntity
common.MouseComponent
}
type CityBuildingSystem struct {
mouseTracker MouseTracker
world *ecs.World
}
// Remove is called whenever an Entity is removed from the World, in order to remove it from this sytem as well
func (*CityBuildingSystem) Remove(ecs.BasicEntity) {}
// Update is ran every frame, with `dt` being the time
// in seconds since the last frame
func (cb *CityBuildingSystem) Update(dt float32) {
if engo.Input.Button("AddCity").JustPressed() {
fmt.Println("The gamer pressed F1")
city := City{BasicEntity: ecs.NewBasic()}
city.SpaceComponent = common.SpaceComponent{
Position: engo.Point{cb.mouseTracker.MouseX, cb.mouseTracker.MouseY},
Width: 30,
Height: 64,
}
texture, err := common.LoadedSprite("textures/city.png")
if err != nil {
log.Println("Unable to load texture: " + err.Error())
}
city.RenderComponent = common.RenderComponent{
Drawable: texture,
Scale: engo.Point{X: 0.1, Y: 0.1},
}
for _, system := range cb.world.Systems() {
switch sys := system.(type) {
case *common.RenderSystem:
sys.Add(&city.BasicEntity, &city.RenderComponent, &city.SpaceComponent)
}
}
}
}
func (cb *CityBuildingSystem) New(w *ecs.World) {
cb.world = w
fmt.Println("CityBuildingSystem was added to the Scene")
cb.mouseTracker.BasicEntity = ecs.NewBasic()
cb.mouseTracker.MouseComponent = common.MouseComponent{Track: true}
for _, system := range w.Systems() {
switch sys := system.(type) {
case *common.MouseSystem:
sys.Add(&cb.mouseTracker.BasicEntity, &cb.mouseTracker.MouseComponent, nil, nil)
}
}
}

View File

@ -0,0 +1,47 @@
package main
import (
"engo.io/engo"
"engo.io/engo/common"
"engo.io/ecs"
"image/color"
"./systems"
)
type myScene struct {}
type City struct {
ecs.BasicEntity
common.RenderComponent
common.SpaceComponent
}
// Type uniquely defines your game type
func (*myScene) Type() string { return "myGame" }
// Preload is called before loading any assets from the disk,
// to allow you to register / queue them
func (*myScene) Preload() {
engo.Files.Load("city.png")
}
// Setup is called before the main loop starts. It allows you
// to add entities and systems to your Scene.
func (*myScene) Setup(world *ecs.World) {
engo.Input.RegisterButton("AddCity", engo.F1)
common.SetBackground(color.White)
world.AddSystem(&common.RenderSystem{})
world.AddSystem(&common.MouseSystem{})
world.AddSystem(&systems.CityBuildingSystem{})
}
func main() {
opts := engo.RunOptions{
Title: "Hello World",
Width: 400,
Height: 400,
}
engo.Run(opts, &myScene{})
}