Пример #1
0
func (o *GameObject) ActByTime(world *World, t time.Time) go4game.IDList {
	defer func() {
		o.lastMoveTime = t
	}()

	envInfo := ActionFnEnvInfo{
		frameTime: t,
		world:     world,
		o:         o,
		clist:     make(go4game.IDList, 0),
	}
	// check expire
	if !o.endTime.IsZero() && o.endTime.Before(t) {
		if o.expireActionFn != nil {
			ok := o.expireActionFn(o, &envInfo)
			if ok != true {
				return envInfo.clist
			}
		}
	}

	var isCollision bool
	hr := go4game.NewHyperRectByCR(o.PosVector, GameConst.Radius[o.ObjType]+GameConst.MaxObjectRadius)
	if o.ObjType == GameObjMain {
		envInfo.world.octree.QueryByHyperRect(envInfo.doPartMainObj, hr)
	} else {
		isCollision = envInfo.world.octree.QueryByHyperRect(envInfo.doPartOtherObj, hr)
	}

	if isCollision || len(envInfo.clist) > 0 {
		if o.collisionActionFn != nil {
			ok := o.collisionActionFn(o, &envInfo)
			if ok != true {
				return envInfo.clist
			}
		}
	}
	if o.moveByTimeFn != nil {
		// change PosVector by movevector
		ok := o.moveByTimeFn(o, &envInfo)
		if ok != true {
			return envInfo.clist
		}
	}
	if o.borderActionFn != nil {
		// check wall action ( wrap, bounce )
		ok := o.borderActionFn(o, &envInfo)
		if ok != true {
			return envInfo.clist
		}
	}
	return envInfo.clist
}
Пример #2
0
func (o *Sphere) Vol() *go4game.HyperRect {
	return go4game.NewHyperRectByCR(o.center, o.Radius)
}