示例#1
0
func (nm *networkManager) Give(ctx *context.T, call rpc.ServerCall, t spec.Triangle) error {
	if ctx.V(3) {
		blessings, rejected := security.RemoteBlessingNames(ctx, call.Security())
		ctx.Infof("Took a triangle from %v@%v (rejected blessings: %v)", blessings, call.RemoteEndpoint().Name(), rejected)
	}
	// Transform from sender's coordinates to our coordinates.
	// The assumption is that if the triangle was to the left of the
	// sender's coordinate system, then it will appear on our right and
	// vice-versa.
	switch {
	case t.X < -1:
		t.X += 2
	case t.X > 1:
		t.X -= 2
	}
	nm.myScreen <- &t
	return nil
}
示例#2
0
func moveTriangle(t *spec.Triangle) {
	t.Dy = t.Dy - gravity
	t.X = t.X + t.Dx*timeBetweenPaints
	t.Y = t.Y + t.Dy*timeBetweenPaints
	if t.Y <= -1 {
		t.Dy = -1 * t.Dy
		t.Y = -1
	} else if maxY := 1 - triangleCenterHeight; t.Y >= maxY {
		t.Dy = -1 * t.Dy
		t.Y = maxY
	}
}
示例#3
0
func returnTriangle(t *spec.Triangle, myScreen chan<- *spec.Triangle) {
	t.Dx = -1 * t.Dx
	moveTriangle(t)
	myScreen <- t
}