39 lines
891 B
Go
39 lines
891 B
Go
//go:build example
|
|
// +build example
|
|
|
|
package entity
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
|
|
"code.rocketnine.space/tslocum/gohan/examples/twinstick/world"
|
|
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"code.rocketnine.space/tslocum/gohan/examples/twinstick/component"
|
|
)
|
|
|
|
func NewPlayer() gohan.Entity {
|
|
player := world.World.NewEntity()
|
|
|
|
// Set position to -1,-1 to indicate the player has not been assigned a
|
|
// position yet. We will place the player in the center of the screen when
|
|
// we receive the screen dimensions for the first time.
|
|
world.World.AddComponent(player, &component.PositionComponent{
|
|
X: -1,
|
|
Y: -1,
|
|
})
|
|
|
|
world.World.AddComponent(player, &component.VelocityComponent{})
|
|
|
|
weapon := &component.WeaponComponent{
|
|
Ammo: math.MaxInt64,
|
|
Damage: 1,
|
|
FireRate: 100 * time.Millisecond,
|
|
BulletSpeed: 15,
|
|
}
|
|
world.World.AddComponent(player, weapon)
|
|
|
|
return player
|
|
}
|