Example #1
0
func (em *EntityManager) NewEntity(x, y float64, entType EntityType) uint64 {

	em.lastEntityID += 1

	// copy the properties from the data file
	props := &EntityProperty{}
	*props = *entityProperties[entType]

	entity := &Entity{
		Id:         em.lastEntityID,
		Type:       entType,
		inputs:     make([]*InputRequest, 0),
		Properties: props,
	}

	em.entities[entity.Id] = entity
	data := structs.NewData()
	data.Position.X = x
	data.Position.Y = y
	data.Orientation = 3.14 * 2
	data.InvMass = props.invMass
	data.Width = props.Width
	data.Height = props.Height
	em.physics[entity.Id] = NewPhysics(data)
	em.physics[entity.Id].Data.Damping = 0.99

	//	em.forceRegistry.Add(em.physics[entity.Id], gravity)
	if props.ai {
		em.controllers[entity.Id] = NewBasicAI(entity.Id)
	}
	em.updated[entity.Id] = true
	return entity.Id
}
Example #2
0
func NewPhysics(data *structs.Data) *Physics {

	data.MaxVelocity = 300
	data.MaxAcceleration = 100

	p := &Physics{
		Data:     data,
		PrevData: structs.NewData(),
		CollisionGeometry: &Circle{
			Position: data.Position,
		},
	}

	p.PrevData.Copy(p.Data)
	if data.Width > data.Height {
		p.CollisionGeometry.(*Circle).Radius = data.Width / 2
	} else {
		p.CollisionGeometry.(*Circle).Radius = data.Height / 2
	}
	return p
}