當前位置: 首頁>>代碼示例>>Golang>>正文


Golang coords.MakeVec函數代碼示例

本文整理匯總了Golang中hearts/img/coords.MakeVec函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeVec函數的具體用法?Golang MakeVec怎麽用?Golang MakeVec使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MakeVec函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestThree

// Testing full image adjustment after screen resizing (assumes adjustImgs is scaling dimensions)
func TestThree(test *testing.T) {
	u = uistate.MakeUIState()
	u.Scene = &sprite.Node{}
	u.Eng = glsprite.Engine(nil)
	u.Eng.Register(u.Scene)
	u.Eng.SetTransform(u.Scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})
	imgPos := coords.MakeVec(5, 20)
	imgDimensions := coords.MakeVec(10, 10)
	newButton := texture.MakeImgWithoutAlt(subtex, imgPos, imgDimensions, u)
	u.Buttons["1"] = newButton
	oldWindow := u.WindowSize.DividedBy(2)
	resize.AdjustImgs(oldWindow, u)
	newPos := u.Buttons["1"].GetCurrent()
	newDimensions := u.Buttons["1"].GetDimensions()
	dimExpect := imgDimensions.Times(2)
	posExpect := imgPos.Times(2)
	if newDimensions.X != dimExpect.X {
		test.Errorf("Expected width %f, got %f", dimExpect.X, newDimensions.X)
	}
	if newDimensions.Y != dimExpect.Y {
		test.Errorf("Expected height %f, got %f", dimExpect.Y, newDimensions.Y)
	}
	if newPos.X != posExpect.X {
		test.Errorf("Expected x %f, got %f", posExpect.X, newPos.X)
	}
	if newPos.Y != posExpect.Y {
		test.Errorf("Expected y %f, got %f", posExpect.Y, newPos.Y)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:33,代碼來源:img_test.go

示例2: DetermineTablePassPosition

// Returns a vec containing a card's position after being passed to the player with index playerIndex
func DetermineTablePassPosition(c *card.Card, cardNum, playerIndex int, u *uistate.UIState) *coords.Vec {
	cardDim := u.TableCardDim
	dropTargetXY := u.DropTargets[playerIndex].GetCurrent()
	dropTargetDim := u.DropTargets[playerIndex].GetDimensions()
	targetCenter := dropTargetXY.PlusVec(dropTargetDim.DividedBy(2))
	xPlayerBlockSize := 2*u.PlayerIconDim.X + u.Padding
	yPlayerBlockSize := u.TopPadding + u.TableCardDim.Y + 3*u.Padding + u.PlayerIconDim.Y
	blockEdge := targetCenter.MinusVec(cardDim.Times(1.5).Plus(u.Padding))
	var destination *coords.Vec
	switch playerIndex {
	case 0:
		destination = coords.MakeVec(
			blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
			u.WindowSize.Y-yPlayerBlockSize-u.TableCardDim.Y)
	case 1:
		destination = coords.MakeVec(
			xPlayerBlockSize,
			blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
	case 2:
		destination = coords.MakeVec(
			blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
			yPlayerBlockSize+u.Padding)
	case 3:
		destination = coords.MakeVec(
			u.WindowSize.X-xPlayerBlockSize-u.TableCardDim.X,
			blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
	}
	return destination
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:30,代碼來源:reposition.go

示例3: TestFive

// Testing NewImgWithAlt
func TestFive(test *testing.T) {
	scene := &sprite.Node{}
	eng := glsprite.Engine(nil)
	u.Eng = eng
	u.Scene = scene
	pos := coords.MakeVec(5, 10)
	dimensions := coords.MakeVec(20, 10)
	i := texture.MakeImgWithAlt(subtex, subtex, pos, dimensions, true, u)
	if i.GetCurrent().X != pos.X {
		test.Errorf("Expected x %f, got %f", pos.X, i.GetCurrent().X)
	}
	if i.GetCurrent().Y != pos.Y {
		test.Errorf("Expected y %f, got %f", pos.Y, i.GetCurrent().Y)
	}
	if i.GetInitial().X != pos.X {
		test.Errorf("Expected inital x %f, got %f", pos.X, i.GetInitial().X)
	}
	if i.GetInitial().Y != pos.Y {
		test.Errorf("Expected initial y %f, got %f", pos.Y, i.GetInitial().Y)
	}
	if i.GetDimensions().X != dimensions.X {
		test.Errorf("Expected width %f, got %f", dimensions.X, i.GetDimensions().X)
	}
	if i.GetDimensions().Y != dimensions.Y {
		test.Errorf("Expected height %f, got %f", dimensions.Y, i.GetDimensions().Y)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:28,代碼來源:img_test.go

示例4: MakeStringImgLeftAlign

func MakeStringImgLeftAlign(input, color, altColor string,
	displayColor bool,
	start *coords.Vec,
	scaler, maxWidth float32,
	u *uistate.UIState) []*staticimg.StaticImg {
	textures := getStringImgs(input, color, u.Texs)
	var altTexs []sprite.SubTex
	if color != altColor {
		altTexs = getStringImgs(input, altColor, u.Texs)
	}
	// adjust scaler if string is too long
	totalWidth := float32(0)
	for _, img := range textures {
		totalWidth += float32(img.R.Max.X) / scaler
	}
	if totalWidth > maxWidth {
		scaler = totalWidth * scaler / maxWidth
	}
	allImgs := make([]*staticimg.StaticImg, 0)
	for i, img := range textures {
		subTexDims := coords.MakeVec(float32(img.R.Max.X), float32(img.R.Max.Y))
		dims := subTexDims.DividedBy(scaler)
		var textImg *staticimg.StaticImg
		if len(altTexs) == 0 {
			textImg = MakeImgWithoutAlt(img, start, dims, u)
		} else {
			textImg = MakeImgWithAlt(img, altTexs[i], start, dims, displayColor, u)
		}
		allImgs = append(allImgs, textImg)
		start = coords.MakeVec(start.X+dims.X, start.Y)
	}
	return allImgs
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:33,代碼來源:texture.go

示例5: TestSix

// Testing resetting card position
func TestSix(test *testing.T) {
	u = uistate.MakeUIState()
	u.Scene = &sprite.Node{}
	u.Eng = glsprite.Engine(nil)
	u.Eng.Register(u.Scene)
	u.Eng.SetTransform(u.Scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})
	u.EmptySuitImgs = []*staticimg.StaticImg{staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg()}
	u.WindowSize = windowSize
	n := texture.MakeNode(u)
	for _, e := range u.EmptySuitImgs {
		e.SetImage(subtex)
		e.SetAlt(subtex)
		e.SetNode(n)
	}
	c := card.NewCard(card.Two, card.Heart)
	c2 := card.NewCard(card.Four, card.Heart)
	n = texture.MakeNode(u)
	n2 := texture.MakeNode(u)
	initialXY := coords.MakeVec(10, 10)
	curXY := coords.MakeVec(100, 30)
	dimensions := coords.MakeVec(5, 5)
	c.SetNode(n)
	c2.SetNode(n2)
	c.SetInitial(initialXY)
	c2.SetInitial(initialXY)
	c.Move(curXY, dimensions, u.Eng)
	c2.Move(curXY, dimensions, u.Eng)
	u.Cards = append(u.Cards, c)
	u.Cards = append(u.Cards, c2)
	if c.GetCurrent().X != curXY.X {
		test.Errorf("Expected x %f, got %f", curXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != curXY.Y {
		test.Errorf("Expected y %f, got %f", curXY.Y, c.GetCurrent().Y)
	}
	reposition.ResetCardPosition(c, u.Eng)
	reposition.ResetCardPosition(c2, u.Eng)
	reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
	if c.GetCurrent().X != u.Padding {
		test.Errorf("Expected x %f, got %f", initialXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c.GetCurrent().Y)
	}
	if c2.GetCurrent().X != u.Padding+dimensions.X+u.Padding {
		test.Errorf("Expected x %f, got %f", u.Padding+dimensions.X+u.Padding, c2.GetCurrent().X)
	}
	if c2.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c2.GetCurrent().Y)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:55,代碼來源:img_test.go

示例6: determineDestination

func determineDestination(animCard *card.Card, dir direction.Direction, windowSize *coords.Vec) *coords.Vec {
	switch dir {
	case direction.Right:
		return coords.MakeVec(animCard.GetCurrent().X+windowSize.X, animCard.GetCurrent().Y)
	case direction.Left:
		return coords.MakeVec(animCard.GetCurrent().X-windowSize.X, animCard.GetCurrent().Y)
	case direction.Across:
		return coords.MakeVec(animCard.GetCurrent().X, animCard.GetCurrent().Y-windowSize.Y)
	case direction.Down:
		return coords.MakeVec(animCard.GetCurrent().X, animCard.GetCurrent().Y+windowSize.Y)
	// Should not occur
	default:
		return coords.MakeVec(-1, -1)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:15,代碼來源:reposition.go

示例7: RealignSuit

// Realigns the cards in suit suitNum which are at y index oldY
func RealignSuit(suitNum card.Suit, oldY float32, u *uistate.UIState) {
	cardsToAlign := make([]*card.Card, 0)
	for _, c := range u.Cards {
		if c.GetSuit() == suitNum && c.GetCurrent().Y == oldY {
			cardsToAlign = append(cardsToAlign, c)
		}
	}
	emptySuitImg := u.EmptySuitImgs[suitNum]
	if len(cardsToAlign) == 0 {
		u.Eng.SetSubTex(emptySuitImg.GetNode(), emptySuitImg.GetImage())
	} else {
		u.Eng.SetSubTex(emptySuitImg.GetNode(), emptySuitImg.GetAlt())
	}
	for i, c := range cardsToAlign {
		dimVec := c.GetDimensions()
		diff := float32(len(cardsToAlign))*(u.Padding+dimVec.X) - (u.WindowSize.X - u.Padding)
		x := u.Padding + float32(i)*(u.Padding+dimVec.X)
		if diff > 0 && i > 0 {
			x -= diff * float32(i) / float32(len(cardsToAlign)-1)
		}
		curVec := coords.MakeVec(x, oldY)
		c.Move(curVec, dimVec, u.Eng)
		c.SetInitial(curVec)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:26,代碼來源:reposition.go

示例8: AnimateSplitCardPlay

// Animate playing of a card in the split view
// Should not be called when the player whose hand is being displayed is the player of the card
func AnimateSplitCardPlay(c *card.Card, player int, quit chan bool, u *uistate.UIState) {
	dropTarget := u.DropTargets[(player-u.CurPlayerIndex+u.NumPlayers)%u.NumPlayers]
	toPos := dropTarget.GetCurrent()
	toDim := dropTarget.GetDimensions()
	texture.PopulateCardImage(c, u)
	switch player {
	case (u.CurPlayerIndex + 1) % u.NumPlayers:
		c.Move(coords.MakeVec(-toDim.X, 0), toDim, u.Eng)
	case (u.CurPlayerIndex + 2) % u.NumPlayers:
		c.Move(coords.MakeVec((u.WindowSize.X-toDim.X)/2, -toDim.Y), toDim, u.Eng)
	case (u.CurPlayerIndex + 3) % u.NumPlayers:
		c.Move(coords.MakeVec(u.WindowSize.X, 0), toDim, u.Eng)
	}
	ch := make(chan bool)
	animateCardMovement(ch, c, toPos, toDim, u)
	SwitchOnChan(ch, quit, func() {}, u)
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:19,代碼來源:reposition.go

示例9: AnimateInPlay

// Animation to bring in the play slot when app is in the hand view and it is the player's turn
func AnimateInPlay(u *uistate.UIState) {
	imgs := append(u.DropTargets, u.BackgroundImgs[0])
	for _, i := range imgs {
		dims := i.GetDimensions()
		to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y/3+u.TopPadding)
		AnimateImageNoChannel(i, to, dims, u)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:9,代碼來源:reposition.go

示例10: AnimateInPass

// Animation to bring in the pass slot
func AnimateInPass(u *uistate.UIState) {
	imgs := append(u.Other, u.DropTargets...)
	imgs = append(imgs, u.Buttons["pass"])
	for _, i := range imgs {
		dims := i.GetDimensions()
		to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y)
		AnimateImageNoChannel(i, to, dims, u)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:10,代碼來源:reposition.go

示例11: UpdateImgPositions

func UpdateImgPositions(sz size.Event, u *uistate.UIState) {
	// must copy u.WindowSize instead of creating a pointer to it
	oldWindowSize := coords.MakeVec(u.WindowSize.X, u.WindowSize.Y)
	updateWindowSize(sz, u)
	if windowExists(oldWindowSize) && windowExists(u.WindowSize) {
		u.Padding = scaleVar(u.Padding, oldWindowSize, u.WindowSize)
		AdjustImgs(oldWindowSize, u)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:9,代碼來源:resize.go

示例12: AnimateHandCardTake

// Animation for the 'take' action, when app is in the hand view
func AnimateHandCardTake(ch chan bool, animImages []*staticimg.StaticImg, u *uistate.UIState) {
	for i, image := range animImages {
		destination := coords.MakeVec(image.GetCurrent().X, image.GetCurrent().Y-u.WindowSize.Y)
		if i < len(animImages)-1 {
			AnimateImageNoChannel(image, destination, image.GetDimensions(), u)
		} else {
			animateImageMovement(ch, image, destination, image.GetDimensions(), u)
		}
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:11,代碼來源:reposition.go

示例13: AnimateHandCardPass

// Animation for the 'pass' action, when app is in the hand view
func AnimateHandCardPass(ch chan bool, animImages []*staticimg.StaticImg, u *uistate.UIState) {
	for counter, i := range animImages {
		dims := i.GetDimensions()
		to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
		if counter < len(animImages)-1 {
			AnimateImageNoChannel(i, to, dims, u)
		} else {
			animateImageMovement(ch, i, to, dims, u)
		}
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:12,代碼來源:reposition.go

示例14: DragImgs

// Drags all input cards and images together with the mouse
func DragImgs(t touch.Event, cards []*card.Card, imgs []*staticimg.StaticImg, u *uistate.UIState) {
	tVec := coords.MakeVec(t.X, t.Y)
	for _, i := range imgs {
		newVec := i.GetCurrent().PlusVec(tVec.MinusVec(u.LastMouseXY).DividedBy(u.PixelsPerPt))
		i.Move(newVec, i.GetDimensions(), u.Eng)
	}
	for _, c := range cards {
		newVec := c.GetCurrent().PlusVec(tVec.MinusVec(u.LastMouseXY).DividedBy(u.PixelsPerPt))
		c.Move(newVec, c.GetDimensions(), u.Eng)
	}
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:12,代碼來源:reposition.go

示例15: SetCardPositionHand

// Given a card object, populates it with its positioning values and sets its position on-screen for the player hand view
func SetCardPositionHand(c *card.Card, indexInSuit int, suitCounts []int, u *uistate.UIState) {
	suitCount := float32(suitCounts[c.GetSuit()])
	heightScaler := float32(4 - c.GetSuit())
	diff := suitCount*(u.Padding+u.CardDim.X) - (u.WindowSize.X - u.Padding)
	x := u.Padding + float32(indexInSuit)*(u.Padding+u.CardDim.X)
	if diff > 0 && indexInSuit > 0 {
		x -= diff * float32(indexInSuit) / (suitCount - 1)
	}
	y := u.WindowSize.Y - heightScaler*(u.CardDim.Y+u.Padding) - u.BottomPadding
	pos := coords.MakeVec(x, y)
	c.SetInitial(pos)
	c.Move(pos, u.CardDim, u.Eng)
}
開發者ID:vanadium,項目名稱:croupier,代碼行數:14,代碼來源:reposition.go


注:本文中的hearts/img/coords.MakeVec函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。