Merge "Removed Position struct Put vecs directly into card and staticimg"
diff --git a/go/src/hearts/img/coords/coords.go b/go/src/hearts/img/coords/coords.go
index 2aa0140..7298a2e 100644
--- a/go/src/hearts/img/coords/coords.go
+++ b/go/src/hearts/img/coords/coords.go
@@ -102,61 +102,3 @@
newVec := MakeVec(x, y)
return newVec
}
-
-// Position is a tuple storing visual information about an image's on-screen location
-// initial contains the XY coordinates of the initial placement of the image
-// current contains the current XY coordinates of the image
-// dimensions contains the current width and height of the image
-// NOTE: This will be renamed in a future CL
-type Position struct {
- initial *Vec
- current *Vec
- dimensions *Vec
-}
-
-// Returns a new position
-func MakePosition(i, c, d *Vec) *Position {
- return &Position{
- initial: i,
- current: c,
- dimensions: d,
- }
-}
-
-// Returns the initial Vec of p
-func (p *Position) GetInitial() *Vec {
- return p.initial
-}
-
-// Returns the current Vec of p
-func (p *Position) GetCurrent() *Vec {
- return p.current
-}
-
-// Returns the dimensions Vec of p
-func (p *Position) GetDimensions() *Vec {
- return p.dimensions
-}
-
-// Updates the initial Vec of p
-func (p *Position) SetInitial(v *Vec) {
- p.initial = v
-}
-
-// Updates the current Vec of p
-func (p *Position) SetCurrent(v *Vec) {
- p.current = v
-}
-
-// Updates the dimensions Vec of p
-func (p *Position) SetDimensions(v *Vec) {
- p.dimensions = v
-}
-
-// Rescales Position p relative to the window size
-func (p *Position) Rescale(oldWindow, newWindow *Vec) (*Vec, *Vec, *Vec) {
- i := p.initial.Rescale(oldWindow, newWindow)
- c := p.current.Rescale(oldWindow, newWindow)
- d := p.dimensions.Rescale(oldWindow, newWindow)
- return i, c, d
-}
diff --git a/go/src/hearts/img/img_test.go b/go/src/hearts/img/img_test.go
index 1d852f5..e3a49b8 100644
--- a/go/src/hearts/img/img_test.go
+++ b/go/src/hearts/img/img_test.go
@@ -26,11 +26,10 @@
// Testing AdjustScaleDimensions
func TestOne(test *testing.T) {
- imgXY := coords.MakeVec(5, 20)
+ imgPos := coords.MakeVec(5, 20)
imgDimensions := coords.MakeVec(10, 10)
oldWindow := coords.MakeVec(30, 60)
- pos := coords.MakePosition(imgXY, imgXY, imgDimensions)
- newXY, _, newDimensions := resize.AdjustScaleDimensions(pos, oldWindow, windowSize)
+ newPos, _, newDimensions := resize.AdjustScaleDimensions(imgPos, imgPos, imgDimensions, oldWindow, windowSize)
widthExpect := imgDimensions.X * 3
heightExpect := imgDimensions.Y * 3 / 2
xExpect := float32(15)
@@ -41,21 +40,20 @@
if newDimensions.Y != heightExpect {
test.Errorf("Expected height %f, got %f", heightExpect, newDimensions.Y)
}
- if newXY.X != xExpect {
- test.Errorf("Expected x %f, got %f", xExpect, newXY.X)
+ if newPos.X != xExpect {
+ test.Errorf("Expected x %f, got %f", xExpect, newPos.X)
}
- if newXY.Y != yExpect {
- test.Errorf("Expected y %f, got %f", yExpect, newXY.Y)
+ if newPos.Y != yExpect {
+ test.Errorf("Expected y %f, got %f", yExpect, newPos.Y)
}
}
// Testing AdjustKeepDimensions
func TestTwo(test *testing.T) {
- imgXY := coords.MakeVec(5, 20)
+ imgPos := coords.MakeVec(5, 20)
imgDimensions := coords.MakeVec(10, 10)
oldWindow := coords.MakeVec(30, 60)
- pos := coords.MakePosition(imgXY, imgXY, imgDimensions)
- newXY, _, newDimensions := resize.AdjustKeepDimensions(pos, oldWindow, windowSize)
+ newPos, _, newDimensions := resize.AdjustKeepDimensions(imgPos, imgPos, imgDimensions, oldWindow, windowSize)
widthExpect := imgDimensions.X
heightExpect := imgDimensions.Y
xExpect := float32(25)
@@ -66,11 +64,11 @@
if newDimensions.Y != heightExpect {
test.Errorf("Expected height %f, got %f", heightExpect, newDimensions.Y)
}
- if newXY.X != xExpect {
- test.Errorf("Expected x %f, got %f", xExpect, newXY.X)
+ if newPos.X != xExpect {
+ test.Errorf("Expected x %f, got %f", xExpect, newPos.X)
}
- if newXY.Y != yExpect {
- test.Errorf("Expected y %f, got %f", yExpect, newXY.Y)
+ if newPos.Y != yExpect {
+ test.Errorf("Expected y %f, got %f", yExpect, newPos.Y)
}
}
@@ -84,30 +82,27 @@
{1, 0, 0},
{0, 1, 0},
})
- imgXY := coords.MakeVec(5, 20)
+ imgPos := coords.MakeVec(5, 20)
imgDimensions := coords.MakeVec(10, 10)
- buttonPos := coords.MakePosition(imgXY, imgXY, imgDimensions)
- newButton := texture.MakeImgWithoutAlt(subtex, buttonPos, u.Eng, u.Scene)
+ newButton := texture.MakeImgWithoutAlt(subtex, imgPos, imgDimensions, u.Eng, u.Scene)
u.Buttons = append(u.Buttons, newButton)
- oldWindow := coords.MakeVec(u.WindowSize.X/2, u.WindowSize.Y/2)
+ oldWindow := u.WindowSize.DividedBy(2)
resize.AdjustImgs(oldWindow, u)
- newXY := u.Buttons[0].GetCurrent()
+ newPos := u.Buttons[0].GetCurrent()
newDimensions := u.Buttons[0].GetDimensions()
- widthExpect := imgDimensions.X * 2
- heightExpect := imgDimensions.Y * 2
- xExpect := imgXY.X * 2
- yExpect := imgXY.Y * 2
- if newDimensions.X != widthExpect {
- test.Errorf("Expected width %f, got %f", widthExpect, newDimensions.X)
+ 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 != heightExpect {
- test.Errorf("Expected height %f, got %f", heightExpect, newDimensions.Y)
+ if newDimensions.Y != dimExpect.Y {
+ test.Errorf("Expected height %f, got %f", dimExpect.Y, newDimensions.Y)
}
- if newXY.X != xExpect {
- test.Errorf("Expected x %f, got %f", xExpect, newXY.X)
+ if newPos.X != posExpect.X {
+ test.Errorf("Expected x %f, got %f", posExpect.X, newPos.X)
}
- if newXY.Y != yExpect {
- test.Errorf("Expected y %f, got %f", yExpect, newXY.Y)
+ if newPos.Y != posExpect.Y {
+ test.Errorf("Expected y %f, got %f", posExpect.Y, newPos.Y)
}
}
@@ -115,21 +110,20 @@
func TestFour(test *testing.T) {
scene := &sprite.Node{}
eng := glsprite.Engine(nil)
- xy := coords.MakeVec(5, 10)
+ pos := coords.MakeVec(5, 10)
dimensions := coords.MakeVec(20, 10)
- pos := coords.MakePosition(xy, xy, dimensions)
- i := texture.MakeImgWithoutAlt(subtex, pos, eng, scene)
- if i.GetCurrent().X != xy.X {
- test.Errorf("Expected x %f, got %f", xy.X, i.GetCurrent().X)
+ i := texture.MakeImgWithoutAlt(subtex, pos, dimensions, eng, scene)
+ if i.GetCurrent().X != pos.X {
+ test.Errorf("Expected x %f, got %f", pos.X, i.GetCurrent().X)
}
- if i.GetCurrent().Y != xy.Y {
- test.Errorf("Expected y %f, got %f", xy.Y, i.GetCurrent().Y)
+ if i.GetCurrent().Y != pos.Y {
+ test.Errorf("Expected y %f, got %f", pos.Y, i.GetCurrent().Y)
}
- if i.GetInitial().X != xy.X {
- test.Errorf("Expected inital x %f, got %f", xy.X, i.GetInitial().X)
+ if i.GetInitial().X != pos.X {
+ test.Errorf("Expected inital x %f, got %f", pos.X, i.GetInitial().X)
}
- if i.GetInitial().Y != xy.Y {
- test.Errorf("Expected initial y %f, got %f", xy.Y, i.GetInitial().Y)
+ 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)
@@ -143,21 +137,20 @@
func TestFive(test *testing.T) {
scene := &sprite.Node{}
eng := glsprite.Engine(nil)
- xy := coords.MakeVec(5, 10)
+ pos := coords.MakeVec(5, 10)
dimensions := coords.MakeVec(20, 10)
- pos := coords.MakePosition(xy, xy, dimensions)
- i := texture.MakeImgWithAlt(subtex, subtex, pos, true, eng, scene)
- if i.GetCurrent().X != xy.X {
- test.Errorf("Expected x %f, got %f", xy.X, i.GetCurrent().X)
+ i := texture.MakeImgWithAlt(subtex, subtex, pos, dimensions, true, eng, scene)
+ if i.GetCurrent().X != pos.X {
+ test.Errorf("Expected x %f, got %f", pos.X, i.GetCurrent().X)
}
- if i.GetCurrent().Y != xy.Y {
- test.Errorf("Expected y %f, got %f", xy.Y, i.GetCurrent().Y)
+ if i.GetCurrent().Y != pos.Y {
+ test.Errorf("Expected y %f, got %f", pos.Y, i.GetCurrent().Y)
}
- if i.GetInitial().X != xy.X {
- test.Errorf("Expected inital x %f, got %f", xy.X, i.GetInitial().X)
+ if i.GetInitial().X != pos.X {
+ test.Errorf("Expected inital x %f, got %f", pos.X, i.GetInitial().X)
}
- if i.GetInitial().Y != xy.Y {
- test.Errorf("Expected initial y %f, got %f", xy.Y, i.GetInitial().Y)
+ 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)
@@ -194,8 +187,6 @@
dimensions := coords.MakeVec(5, 5)
c.SetNode(n)
c2.SetNode(n2)
- c.InitializePosition()
- c2.InitializePosition()
c.SetInitial(initialXY)
c2.SetInitial(initialXY)
c.Move(curXY, dimensions, u.Eng)
diff --git a/go/src/hearts/img/reposition/reposition.go b/go/src/hearts/img/reposition/reposition.go
index 72908c5..8b8b26d 100644
--- a/go/src/hearts/img/reposition/reposition.go
+++ b/go/src/hearts/img/reposition/reposition.go
@@ -84,18 +84,15 @@
// Animation for the 'take' action, when app is in the table view
func AnimateTableCardTake(animCard *card.Card, cardNum int, p *player.Player) {
- initialPos := animCard.GetPosition()
- destinationXY := p.GetPassedFrom()[cardNum].GetInitial()
- destination := coords.MakePosition(destinationXY, destinationXY, initialPos.GetDimensions())
+ destinationPos := p.GetPassedFrom()[cardNum].GetInitial()
c := make(chan bool)
- animateCardMovement(c, animCard, initialPos, destination)
+ animateCardMovement(c, animCard, destinationPos, animCard.GetDimensions())
<-c
}
// Animation for the 'pass' action, when app is in the table view
func AnimateTableCardPass(animCard *card.Card, toPlayer, cardNum int, u *uistate.UIState) {
- initialPos := animCard.GetPosition()
- cardDim := initialPos.GetDimensions()
+ cardDim := animCard.GetDimensions()
dropTargetXY := u.DropTargets[toPlayer].GetCurrent()
dropTargetDim := u.DropTargets[toPlayer].GetDimensions()
targetCenter := dropTargetXY.PlusVec(dropTargetDim.DividedBy(2))
@@ -121,9 +118,8 @@
targetCenter.X+distFromTargetX-cardDim.X/2,
blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
}
- destinationPos := coords.MakePosition(destination, destination, cardDim)
c := make(chan bool)
- animateCardMovement(c, animCard, initialPos, destinationPos)
+ animateCardMovement(c, animCard, destination, cardDim)
<-c
}
@@ -131,16 +127,14 @@
func AnimateHandCardPass(ch chan bool, animImages []*staticimg.StaticImg, animCards []*card.Card, u *uistate.UIState) {
ch2 := make(chan bool)
for _, i := range animImages {
- initial := i.GetPosition()
- destination := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
- destinationPos := coords.MakePosition(destination, destination, i.GetDimensions())
- AnimateImageMovement(i, initial, destinationPos)
+ dims := i.GetDimensions()
+ to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
+ AnimateImageMovement(i, to, dims)
}
for _, c := range animCards {
- initial := c.GetPosition()
- destination := coords.MakeVec(c.GetCurrent().X, c.GetCurrent().Y-u.WindowSize.Y)
- destinationPos := coords.MakePosition(destination, destination, c.GetDimensions())
- animateCardMovement(ch2, c, initial, destinationPos)
+ dims := c.GetDimensions()
+ to := coords.MakeVec(c.GetCurrent().X, c.GetCurrent().Y-u.WindowSize.Y)
+ animateCardMovement(ch2, c, to, dims)
}
select {
case <-ch2:
@@ -154,10 +148,8 @@
func AnimateHandCardTake(ch chan bool, animImages []*staticimg.StaticImg, u *uistate.UIState) {
ch2 := make(chan bool)
for _, i := range animImages {
- initial := i.GetPosition()
destination := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
- destinationPos := coords.MakePosition(destination, destination, i.GetDimensions())
- AnimateImageMovement(i, initial, destinationPos)
+ AnimateImageMovement(i, destination, i.GetDimensions())
}
select {
case <-ch2:
@@ -169,11 +161,8 @@
// Animation for the 'play' action, when app is in the hand view
func AnimateHandCardPlay(c chan bool, animCard *card.Card, u *uistate.UIState) {
- initial := animCard.GetPosition()
- destinationXY := determineDestination(animCard, direction.Across, u.WindowSize)
- destinationSize := animCard.GetDimensions()
- destination := coords.MakePosition(destinationXY, destinationXY, destinationSize)
- animateCardMovement(c, animCard, initial, destination)
+ destination := determineDestination(animCard, direction.Across, u.WindowSize)
+ animateCardMovement(c, animCard, destination, animCard.GetDimensions())
<-c
c <- true
}
@@ -181,10 +170,10 @@
// Animation for the 'play' action, when app is in the table view
func AnimateTableCardPlay(c chan bool, animCard *card.Card, playerInt int, u *uistate.UIState) {
destination := u.DropTargets[playerInt]
- destinationPos := destination.GetPosition()
- initialPos := animCard.GetPosition()
+ destinationPos := destination.GetCurrent()
+ destinationDim := destination.GetDimensions()
ch := make(chan bool)
- animateCardMovement(ch, animCard, initialPos, destinationPos)
+ animateCardMovement(ch, animCard, destinationPos, destinationDim)
<-ch
animCard.SetFrontDisplay(u.Eng)
c <- true
@@ -208,57 +197,50 @@
// Animation for when a trick is taken, when app is in the table view
func AnimateTableCardTakeTrick(c chan bool, animCard *card.Card, dir direction.Direction, u *uistate.UIState) {
- initial := animCard.GetPosition()
destination := determineDestination(animCard, dir, u.WindowSize)
- destinationSize := animCard.GetDimensions()
- destinationPos := coords.MakePosition(destination, destination, destinationSize)
- animateCardMovement(c, animCard, initial, destinationPos)
+ animateCardMovement(c, animCard, destination, animCard.GetDimensions())
<-c
c <- true
}
-func AnimateImageMovement(animImage *staticimg.StaticImg, from, to *coords.Position) {
+func AnimateImageMovement(animImage *staticimg.StaticImg, endPos, endDim *coords.Vec) {
node := animImage.GetNode()
+ startPos := animImage.GetCurrent()
+ startDim := animImage.GetDimensions()
iteration := 0
- initial := from.GetCurrent()
- initialDim := from.GetDimensions()
- destination := to.GetCurrent()
- destinationSize := to.GetDimensions()
node.Arranger = arrangerFunc(func(eng sprite.Engine, node *sprite.Node, t clock.Time) {
iteration++
if float32(iteration) < animationFrameCounter {
curXY := animImage.GetCurrent()
curDim := animImage.GetDimensions()
- XYStep := destination.MinusVec(initial).DividedBy(animationFrameCounter)
- dimStep := destinationSize.MinusVec(initialDim).DividedBy(animationFrameCounter)
+ XYStep := endPos.MinusVec(startPos).DividedBy(animationFrameCounter)
+ dimStep := endDim.MinusVec(startDim).DividedBy(animationFrameCounter)
newVec := curXY.PlusVec(XYStep)
dimVec := curDim.PlusVec(dimStep)
animImage.Move(newVec, dimVec, eng)
} else if math.Abs(float64(animationFrameCounter)-float64(iteration)) < 0.0001 {
- animImage.Move(destination, destinationSize, eng)
+ animImage.Move(endPos, endDim, eng)
}
})
}
-func animateCardMovement(c chan bool, animCard *card.Card, from, to *coords.Position) {
+func animateCardMovement(c chan bool, animCard *card.Card, endPos, endDim *coords.Vec) {
node := animCard.GetNode()
+ startPos := animCard.GetCurrent()
+ startDim := animCard.GetDimensions()
iteration := 0
- initial := from.GetCurrent()
- initialDim := from.GetDimensions()
- destinationXY := to.GetCurrent()
- destinationSize := to.GetDimensions()
node.Arranger = arrangerFunc(func(eng sprite.Engine, node *sprite.Node, t clock.Time) {
iteration++
if float32(iteration) < animationFrameCounter {
curXY := animCard.GetCurrent()
curDim := animCard.GetDimensions()
- XYStep := destinationXY.MinusVec(initial).DividedBy(animationFrameCounter)
- dimStep := destinationSize.MinusVec(initialDim).DividedBy(animationFrameCounter)
+ XYStep := endPos.MinusVec(startPos).DividedBy(animationFrameCounter)
+ dimStep := endDim.MinusVec(startDim).DividedBy(animationFrameCounter)
newVec := curXY.PlusVec(XYStep)
dimVec := curDim.PlusVec(dimStep)
animCard.Move(newVec, dimVec, eng)
- } else if float32(iteration) == animationFrameCounter {
- animCard.Move(destinationXY, destinationSize, eng)
+ } else if math.Abs(float64(animationFrameCounter)-float64(iteration)) < 0.0001 {
+ animCard.Move(endPos, endDim, eng)
c <- true
}
})
@@ -273,10 +255,9 @@
// cardIndex has an X of the total number of cards in hand, and a Y of the position within the hand of the current card
// padding has an X of the padding along the top edge, and a Y of the padding along each other edge
func SetCardPositionTable(c *card.Card, playerIndex int, cardIndex *coords.Vec, u *uistate.UIState) {
- xyVec := cardPositionTable(playerIndex, cardIndex, u)
- pos := coords.MakePosition(xyVec, xyVec, u.TableCardDim)
- c.SetPos(pos)
- c.Move(xyVec, u.TableCardDim, u.Eng)
+ pos := cardPositionTable(playerIndex, cardIndex, u)
+ c.SetInitial(pos)
+ c.Move(pos, u.TableCardDim, u.Eng)
}
func cardPositionTable(playerIndex int, cardIndex *coords.Vec, u *uistate.UIState) *coords.Vec {
@@ -318,8 +299,7 @@
x -= diff * float32(indexInSuit) / (suitCount - 1)
}
y := u.WindowSize.Y - heightScaler*(u.CardDim.Y+u.Padding) - u.BottomPadding
- xyVec := coords.MakeVec(x, y)
- pos := coords.MakePosition(xyVec, xyVec, u.CardDim)
- c.SetPos(pos)
- c.Move(xyVec, u.CardDim, u.Eng)
+ pos := coords.MakeVec(x, y)
+ c.SetInitial(pos)
+ c.Move(pos, u.CardDim, u.Eng)
}
diff --git a/go/src/hearts/img/resize/resize.go b/go/src/hearts/img/resize/resize.go
index e0d0de8..d9e1272 100644
--- a/go/src/hearts/img/resize/resize.go
+++ b/go/src/hearts/img/resize/resize.go
@@ -18,13 +18,13 @@
func UpdateImgPositions(sz size.Event, u *uistate.UIState) {
// must copy u.WindowSize instead of creating a pointer to it
- oldWindow := coords.MakeVec(u.WindowSize.X, u.WindowSize.Y)
+ oldWindowSize := coords.MakeVec(u.WindowSize.X, u.WindowSize.Y)
updateWindowSize(sz, u)
- if windowExists(oldWindow) && windowExists(u.WindowSize) {
- u.Padding = scaleVar(u.Padding, oldWindow, u.WindowSize)
- u.CardDim = scaleVec(u.CardDim, oldWindow, u.WindowSize)
- u.TableCardDim = scaleVec(u.TableCardDim, oldWindow, u.WindowSize)
- AdjustImgs(oldWindow, u)
+ if windowExists(oldWindowSize) && windowExists(u.WindowSize) {
+ u.Padding = scaleVar(u.Padding, oldWindowSize, u.WindowSize)
+ u.CardDim = scaleVec(u.CardDim, oldWindowSize, u.WindowSize)
+ u.TableCardDim = scaleVec(u.TableCardDim, oldWindowSize, u.WindowSize)
+ AdjustImgs(oldWindowSize, u)
}
}
@@ -35,55 +35,46 @@
// Adjusts all images to accommodate a screen size change
// Public for testing, but could be made private
-func AdjustImgs(oldWindow *coords.Vec, u *uistate.UIState) {
- adjustCardArray(u.Cards, oldWindow, u.WindowSize, u.Eng)
- adjustCardArray(u.TableCards, oldWindow, u.WindowSize, u.Eng)
- adjustImgArray(u.DropTargets, oldWindow, u.WindowSize, u.Eng)
- adjustImgArray(u.BackgroundImgs, oldWindow, u.WindowSize, u.Eng)
- adjustImgArray(u.Buttons, oldWindow, u.WindowSize, u.Eng)
- adjustImgArray(u.EmptySuitImgs, oldWindow, u.WindowSize, u.Eng)
- adjustImgArray(u.Other, oldWindow, u.WindowSize, u.Eng)
+func AdjustImgs(oldWindowSize *coords.Vec, u *uistate.UIState) {
+ adjustCardArray(u.Cards, oldWindowSize, u.WindowSize, u.Eng)
+ adjustCardArray(u.TableCards, oldWindowSize, u.WindowSize, u.Eng)
+ adjustImgArray(u.DropTargets, oldWindowSize, u.WindowSize, u.Eng)
+ adjustImgArray(u.BackgroundImgs, oldWindowSize, u.WindowSize, u.Eng)
+ adjustImgArray(u.Buttons, oldWindowSize, u.WindowSize, u.Eng)
+ adjustImgArray(u.EmptySuitImgs, oldWindowSize, u.WindowSize, u.Eng)
+ adjustImgArray(u.Other, oldWindowSize, u.WindowSize, u.Eng)
}
// Returns coordinates for images with same width and height but in new positions proportional to the screen
// Public for testing, but could be made private
-func AdjustKeepDimensions(oldPos *coords.Position, oldWindow, windowSize *coords.Vec) (*coords.Vec, *coords.Vec, *coords.Vec) {
- oldXY := oldPos.GetCurrent()
- oldInitialXY := oldPos.GetInitial()
- oldDimensions := oldPos.GetDimensions()
- newXY := oldXY.PlusVec(oldDimensions.DividedBy(2)).DividedByVec(oldWindow).TimesVec(windowSize).MinusVec(oldDimensions.DividedBy(2))
- newInitialXY := oldInitialXY.PlusVec(oldDimensions.DividedBy(2)).DividedByVec(oldWindow).TimesVec(windowSize).MinusVec(oldDimensions.DividedBy(2))
- return newXY, newInitialXY, oldDimensions
+func AdjustKeepDimensions(oldInitial, oldPos, oldDimensions, oldWindowSize, newWindowSize *coords.Vec) (*coords.Vec, *coords.Vec, *coords.Vec) {
+ newPos := oldPos.PlusVec(oldDimensions.DividedBy(2)).DividedByVec(oldWindowSize).TimesVec(newWindowSize).MinusVec(oldDimensions.DividedBy(2))
+ newInitial := oldInitial.PlusVec(oldDimensions.DividedBy(2)).DividedByVec(oldWindowSize).TimesVec(newWindowSize).MinusVec(oldDimensions.DividedBy(2))
+ return newInitial, newPos, oldDimensions
}
// Returns coordinates for images with position, width and height scaled proportional to the screen
// Public for testing, but could be made private
-func AdjustScaleDimensions(oldPos *coords.Position, oldWindow, windowSize *coords.Vec) (*coords.Vec, *coords.Vec, *coords.Vec) {
- return oldPos.Rescale(oldWindow, windowSize)
+func AdjustScaleDimensions(oldInitial, oldPos, oldDimensions, oldWindowSize, newWindowSize *coords.Vec) (*coords.Vec, *coords.Vec, *coords.Vec) {
+ return oldInitial.Rescale(oldWindowSize, newWindowSize),
+ oldPos.Rescale(oldWindowSize, newWindowSize),
+ oldDimensions.Rescale(oldWindowSize, newWindowSize)
}
// Adjusts the positioning of an individual array of images
-func adjustImgArray(imgs []*staticimg.StaticImg, oldWindow, windowSize *coords.Vec, eng sprite.Engine) {
+func adjustImgArray(imgs []*staticimg.StaticImg, oldWindowSize, newWindowSize *coords.Vec, eng sprite.Engine) {
for _, s := range imgs {
- oldDimensions := s.GetDimensions()
- oldXY := s.GetCurrent()
- oldInitial := s.GetInitial()
- oldPos := coords.MakePosition(oldInitial, oldXY, oldDimensions)
- newInitialXY, newXY, newDimensions := AdjustScaleDimensions(oldPos, oldWindow, windowSize)
- s.Move(newXY, newDimensions, eng)
- s.SetInitial(newInitialXY)
+ newInitial, newPos, newDimensions := AdjustScaleDimensions(s.GetInitial(), s.GetCurrent(), s.GetDimensions(), oldWindowSize, newWindowSize)
+ s.Move(newPos, newDimensions, eng)
+ s.SetInitial(newInitial)
}
}
// Adjusts the positioning of an individual array of cards
-func adjustCardArray(cards []*card.Card, oldWindow, windowSize *coords.Vec, eng sprite.Engine) {
+func adjustCardArray(cards []*card.Card, oldWindowSize, newWindowSize *coords.Vec, eng sprite.Engine) {
for _, c := range cards {
- oldDimensions := c.GetDimensions()
- oldLocation := c.GetCurrent()
- oldInitial := c.GetInitial()
- oldPos := coords.MakePosition(oldInitial, oldLocation, oldDimensions)
- newInitial, newLocation, newDimensions := AdjustScaleDimensions(oldPos, oldWindow, windowSize)
- c.Move(newLocation, newDimensions, eng)
+ newInitial, newPos, newDimensions := AdjustScaleDimensions(c.GetInitial(), c.GetCurrent(), c.GetDimensions(), oldWindowSize, newWindowSize)
+ c.Move(newPos, newDimensions, eng)
c.SetInitial(newInitial)
}
}
diff --git a/go/src/hearts/img/staticimg/staticimg.go b/go/src/hearts/img/staticimg/staticimg.go
index 0e12abb..c090390 100644
--- a/go/src/hearts/img/staticimg/staticimg.go
+++ b/go/src/hearts/img/staticimg/staticimg.go
@@ -29,7 +29,12 @@
alt sprite.SubTex
// displayingImage is true is image is currently being displayed, and false if alt is currently being displayed
displayingImage bool
- pos *coords.Position
+ // XY coordinates of the initial placement of the image
+ initial *coords.Vec
+ // current XY coordinates of the image
+ current *coords.Vec
+ // current width and height of the image
+ dimensions *coords.Vec
// cardHere is used if the StaticImg instance is a drop target
cardHere *card.Card
}
@@ -53,23 +58,19 @@
return s.displayingImage
}
-func (s *StaticImg) GetPosition() *coords.Position {
- return s.pos
-}
-
// Returns a vector containing the current x- and y-coordinate of the upper left corner of s
func (s *StaticImg) GetCurrent() *coords.Vec {
- return s.pos.GetCurrent()
+ return s.current
}
// Returns a vector containing the initial x- and y-coordinate of the upper left corner of s
func (s *StaticImg) GetInitial() *coords.Vec {
- return s.pos.GetInitial()
+ return s.initial
}
// Returns a vector containing the width and height of s
func (s *StaticImg) GetDimensions() *coords.Vec {
- return s.pos.GetDimensions()
+ return s.dimensions
}
// Returns the card currently pinned to s
@@ -102,17 +103,12 @@
{newDimensions.X, 0, newXY.X},
{0, newDimensions.Y, newXY.Y},
})
- s.pos.SetCurrent(newXY)
- s.pos.SetDimensions(newDimensions)
-}
-
-// Sets the initial x and y coordinates of the upper left corner of s
-func (s *StaticImg) SetPos(newPos *coords.Position) {
- s.pos = newPos
+ s.current = newXY
+ s.dimensions = newDimensions
}
func (s *StaticImg) SetInitial(initial *coords.Vec) {
- s.pos.SetInitial(initial)
+ s.initial = initial
}
// Pins card c to s
diff --git a/go/src/hearts/img/texture/texture.go b/go/src/hearts/img/texture/texture.go
index 5d66e90..f661ad2 100644
--- a/go/src/hearts/img/texture/texture.go
+++ b/go/src/hearts/img/texture/texture.go
@@ -91,8 +91,11 @@
return imgs
}
-func MakeStringImgLeftAlign(
- input, color, altColor string, displayColor bool, start *coords.Vec, scaler, maxWidth float32, u *uistate.UIState) []*staticimg.StaticImg {
+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 {
@@ -106,26 +109,27 @@
if totalWidth > maxWidth {
scaler = totalWidth * scaler / maxWidth
}
- XY := start
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)
- pos := coords.MakePosition(XY, XY, dims)
var textImg *staticimg.StaticImg
if len(altTexs) == 0 {
- textImg = MakeImgWithoutAlt(img, pos, u.Eng, u.Scene)
+ textImg = MakeImgWithoutAlt(img, start, dims, u.Eng, u.Scene)
} else {
- textImg = MakeImgWithAlt(img, altTexs[i], pos, displayColor, u.Eng, u.Scene)
+ textImg = MakeImgWithAlt(img, altTexs[i], start, dims, displayColor, u.Eng, u.Scene)
}
allImgs = append(allImgs, textImg)
- XY = coords.MakeVec(XY.X+dims.X, XY.Y)
+ start = coords.MakeVec(start.X+dims.X, start.Y)
}
return allImgs
}
-func MakeStringImgRightAlign(
- input, color, altColor string, displayColor bool, end *coords.Vec, scaler, maxWidth float32, u *uistate.UIState) []*staticimg.StaticImg {
+func MakeStringImgRightAlign(input, color, altColor string,
+ displayColor bool,
+ end *coords.Vec,
+ scaler, maxWidth float32,
+ u *uistate.UIState) []*staticimg.StaticImg {
textures := getStringImgs(input, color, u.Texs)
var altTexs []sprite.SubTex
if color != altColor {
@@ -143,27 +147,27 @@
for i, j := 0, len(textures)-1; i < j; i, j = i+1, j-1 {
textures[i], textures[j] = textures[j], textures[i]
}
- XY := end
allImgs := make([]*staticimg.StaticImg, 0)
for i, img := range textures {
- width := float32(img.R.Max.X) / scaler
- height := float32(img.R.Max.Y) / scaler
- dims := coords.MakeVec(width, height)
- XY = coords.MakeVec(XY.X-width, XY.Y)
- pos := coords.MakePosition(XY, XY, dims)
+ subTexDims := coords.MakeVec(float32(img.R.Max.X), float32(img.R.Max.Y))
+ dims := subTexDims.DividedBy(scaler)
+ end = coords.MakeVec(end.X-dims.X, end.Y)
var textImg *staticimg.StaticImg
if len(altTexs) == 0 {
- textImg = MakeImgWithoutAlt(img, pos, u.Eng, u.Scene)
+ textImg = MakeImgWithoutAlt(img, end, dims, u.Eng, u.Scene)
} else {
- textImg = MakeImgWithAlt(img, altTexs[i], pos, displayColor, u.Eng, u.Scene)
+ textImg = MakeImgWithAlt(img, altTexs[i], end, dims, displayColor, u.Eng, u.Scene)
}
allImgs = append(allImgs, textImg)
}
return allImgs
}
-func MakeStringImgCenterAlign(
- input, color, altColor string, displayColor bool, center *coords.Vec, scaler, maxWidth float32, u *uistate.UIState) []*staticimg.StaticImg {
+func MakeStringImgCenterAlign(input, color, altColor string,
+ displayColor bool,
+ center *coords.Vec,
+ scaler, maxWidth float32,
+ u *uistate.UIState) []*staticimg.StaticImg {
textures := getStringImgs(input, color, u.Texs)
totalWidth := float32(0)
for _, img := range textures {
@@ -179,23 +183,28 @@
}
// Returns a new StaticImg instance with desired image and dimensions
-func MakeImgWithoutAlt(t sprite.SubTex, pos *coords.Position, eng sprite.Engine, scene *sprite.Node) *staticimg.StaticImg {
- currentVec := pos.GetCurrent()
- dimVec := pos.GetDimensions()
+func MakeImgWithoutAlt(t sprite.SubTex,
+ current, dim *coords.Vec,
+ eng sprite.Engine,
+ scene *sprite.Node) *staticimg.StaticImg {
n := MakeNode(eng, scene)
eng.SetSubTex(n, t)
s := staticimg.MakeStaticImg()
s.SetNode(n)
s.SetImage(t)
- s.SetPos(pos)
- s.Move(currentVec, dimVec, eng)
+ s.SetInitial(current)
+ s.Move(current, dim, eng)
return s
}
// Returns a new StaticImg instance with desired image and dimensions
// Also includes an alternate image. If displayImage is true, image will be displayed. Else, alt will be displayed.
-func MakeImgWithAlt(t sprite.SubTex, alt sprite.SubTex, pos *coords.Position, displayImage bool, eng sprite.Engine, scene *sprite.Node) *staticimg.StaticImg {
- s := MakeImgWithoutAlt(t, pos, eng, scene)
+func MakeImgWithAlt(t, alt sprite.SubTex,
+ current, dim *coords.Vec,
+ displayImage bool,
+ eng sprite.Engine,
+ scene *sprite.Node) *staticimg.StaticImg {
+ s := MakeImgWithoutAlt(t, current, dim, eng, scene)
s.SetAlt(alt)
if !displayImage {
eng.SetSubTex(s.GetNode(), alt)
diff --git a/go/src/hearts/img/view/view.go b/go/src/hearts/img/view/view.go
index 79c3f13..d45e5c4 100644
--- a/go/src/hearts/img/view/view.go
+++ b/go/src/hearts/img/view/view.go
@@ -31,16 +31,12 @@
buttonX := (u.WindowSize.X - u.CardDim.X) / 2
tableButtonY := (u.WindowSize.Y - 2*u.CardDim.Y - u.Padding) / 2
passButtonY := tableButtonY + u.CardDim.Y + u.Padding
- tableButtonXY := coords.MakeVec(buttonX, tableButtonY)
- passButtonXY := coords.MakeVec(buttonX, passButtonY)
- tableButtonPos := coords.MakePosition(tableButtonXY, tableButtonXY, u.CardDim)
- passButtonPos := coords.MakePosition(passButtonXY, passButtonXY, u.CardDim)
+ tableButtonPos := coords.MakeVec(buttonX, tableButtonY)
+ passButtonPos := coords.MakeVec(buttonX, passButtonY)
tableButtonImage := u.Texs["BakuSquare.png"]
passButtonImage := u.Texs["Clubs-2.png"]
- tableButton := texture.MakeImgWithAlt(tableButtonImage, tableButtonImage, tableButtonPos, true, u.Eng, u.Scene)
- passButton := texture.MakeImgWithAlt(passButtonImage, passButtonImage, passButtonPos, true, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, tableButton)
- u.Buttons = append(u.Buttons, passButton)
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(tableButtonImage, tableButtonPos, u.CardDim, u.Eng, u.Scene))
+ u.Buttons = append(u.Buttons, texture.MakeImgWithoutAlt(passButtonImage, passButtonPos, u.CardDim, u.Eng, u.Scene))
}
// Table View: Displays the table. Intended for public devices
@@ -60,15 +56,14 @@
} else {
dropTargetY = u.WindowSize.Y/2 + u.Padding
}
- dropTargetXY := coords.MakeVec(dropTargetX, dropTargetY)
- dropTargetPos := coords.MakePosition(dropTargetXY, dropTargetXY, dropTargetDimensions)
- dropTarget := texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.Eng, u.Scene)
- u.DropTargets = append(u.DropTargets, dropTarget)
+ dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
+ u.DropTargets = append(u.DropTargets,
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
// card on top of first drop target
dropCard := u.CurTable.GetTrick()[0]
if dropCard != nil {
texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
- dropCard.Move(dropTargetXY, dropTargetDimensions, u.Eng)
+ dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
// second drop target
@@ -78,15 +73,14 @@
} else {
dropTargetX = u.WindowSize.X/2 - 3*u.CardDim.X/2 - u.Padding
}
- dropTargetXY = coords.MakeVec(dropTargetX, dropTargetY)
- dropTargetPos = coords.MakePosition(dropTargetXY, dropTargetXY, dropTargetDimensions)
- dropTarget = texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.Eng, u.Scene)
- u.DropTargets = append(u.DropTargets, dropTarget)
+ dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
+ u.DropTargets = append(u.DropTargets,
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
// card on top of second drop target
dropCard = u.CurTable.GetTrick()[1]
if dropCard != nil {
texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
- dropCard.Move(dropTargetXY, dropTargetDimensions, u.Eng)
+ dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
// third drop target
@@ -96,15 +90,14 @@
} else {
dropTargetY = u.WindowSize.Y/2 - u.Padding - u.CardDim.Y
}
- dropTargetXY = coords.MakeVec(dropTargetX, dropTargetY)
- dropTargetPos = coords.MakePosition(dropTargetXY, dropTargetXY, dropTargetDimensions)
- dropTarget = texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.Eng, u.Scene)
- u.DropTargets = append(u.DropTargets, dropTarget)
+ dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
+ u.DropTargets = append(u.DropTargets,
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
// card on top of third drop target
dropCard = u.CurTable.GetTrick()[2]
if dropCard != nil {
texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
- dropCard.Move(dropTargetXY, dropTargetDimensions, u.Eng)
+ dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
// fourth drop target
@@ -114,28 +107,27 @@
} else {
dropTargetX = u.WindowSize.X/2 + u.CardDim.X/2 + u.Padding
}
- dropTargetXY = coords.MakeVec(dropTargetX, dropTargetY)
- dropTargetPos = coords.MakePosition(dropTargetXY, dropTargetXY, dropTargetDimensions)
- dropTarget = texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.Eng, u.Scene)
- u.DropTargets = append(u.DropTargets, dropTarget)
+ dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
+ u.DropTargets = append(u.DropTargets,
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
// card on top of fourth drop target
dropCard = u.CurTable.GetTrick()[3]
if dropCard != nil {
texture.PopulateCardImage(dropCard, u.Texs, u.Eng, u.Scene)
- dropCard.Move(dropTargetXY, dropTargetDimensions, u.Eng)
+ dropCard.Move(dropTargetPos, dropTargetDimensions, u.Eng)
u.Cards = append(u.Cards, dropCard)
}
// adding 4 player icons, text, and device icons
playerIconImage := u.CurTable.GetPlayers()[0].GetImage()
playerIconX := (u.WindowSize.X - u.PlayerIconDim.X) / 2
playerIconY := u.WindowSize.Y - u.TableCardDim.Y - u.BottomPadding - u.Padding - u.PlayerIconDim.Y
- playerIconXY := coords.MakeVec(playerIconX, playerIconY)
- playerIconPos := coords.MakePosition(playerIconXY, playerIconXY, u.PlayerIconDim)
- playerIcon := texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.Eng, u.Scene)
+ playerIconPos := coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
- u.Buttons = append(u.Buttons, playerIcon)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
} else {
- u.BackgroundImgs = append(u.BackgroundImgs, playerIcon)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
}
// player 0's name
center := coords.MakeVec(playerIconX+u.PlayerIconDim.X/2, playerIconY-30)
@@ -145,24 +137,24 @@
}
// player 0's device icon
deviceIconImage := u.Texs["phoneIcon.png"]
- deviceIconDim := coords.MakeVec(u.PlayerIconDim.X/2, u.PlayerIconDim.Y/2)
- deviceIconX := playerIconXY.X + u.PlayerIconDim.X
- deviceIconY := playerIconXY.Y
- deviceIconXY := coords.MakeVec(deviceIconX, deviceIconY)
- deviceIconPos := coords.MakePosition(deviceIconXY, deviceIconXY, deviceIconDim)
- deviceIcon := texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, deviceIcon)
+ deviceIconDim := u.PlayerIconDim.DividedBy(2)
+ deviceIconPos := coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
// player 1's icon
playerIconImage = u.CurTable.GetPlayers()[1].GetImage()
playerIconX = u.BottomPadding
- playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-(float32(len(u.CurTable.GetPlayers()[1].GetHand()))*(u.TableCardDim.Y-u.Overlap.Y)+u.TableCardDim.Y))/2 - u.PlayerIconDim.Y - u.Padding
- playerIconXY = coords.MakeVec(playerIconX, playerIconY)
- playerIconPos = coords.MakePosition(playerIconXY, playerIconXY, u.PlayerIconDim)
- playerIcon = texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.Eng, u.Scene)
+ playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-
+ (float32(len(u.CurTable.GetPlayers()[1].GetHand()))*
+ (u.TableCardDim.Y-u.Overlap.Y)+u.TableCardDim.Y))/2 -
+ u.PlayerIconDim.Y - u.Padding
+ playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
- u.Buttons = append(u.Buttons, playerIcon)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
} else {
- u.BackgroundImgs = append(u.BackgroundImgs, playerIcon)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
}
// player 1's name
start := coords.MakeVec(playerIconX, playerIconY-30)
@@ -172,25 +164,22 @@
}
// player 1's device icon
deviceIconImage = u.Texs["tabletIcon.png"]
- deviceIconX = playerIconXY.X + u.PlayerIconDim.X
- deviceIconY = playerIconXY.Y + u.PlayerIconDim.Y - deviceIconDim.Y
- deviceIconXY = coords.MakeVec(deviceIconX, deviceIconY)
- deviceIconPos = coords.MakePosition(deviceIconXY, deviceIconXY, deviceIconDim)
- deviceIcon = texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, deviceIcon)
+ deviceIconPos = coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
// player 2's icon
playerIconImage = u.CurTable.GetPlayers()[2].GetImage()
playerIconX = (u.WindowSize.X - u.PlayerIconDim.X) / 2
playerIconY = u.TopPadding + u.TableCardDim.Y + u.Padding
- playerIconXY = coords.MakeVec(playerIconX, playerIconY)
- playerIconPos = coords.MakePosition(playerIconXY, playerIconXY, u.PlayerIconDim)
- playerIcon = texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.Eng, u.Scene)
+ playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
- u.Buttons = append(u.Buttons, playerIcon)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
} else {
- u.BackgroundImgs = append(u.BackgroundImgs, playerIcon)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
}
- // player 3's name
+ // player 2's name
center = coords.MakeVec(playerIconX+u.PlayerIconDim.X/2, playerIconY+u.PlayerIconDim.Y+5)
textImgs = texture.MakeStringImgCenterAlign(u.CurTable.GetPlayers()[2].GetName(), "", "", true, center, scaler, maxWidth, u)
for _, img := range textImgs {
@@ -198,23 +187,23 @@
}
// player 2's device icon
deviceIconImage = u.Texs["watchIcon.png"]
- deviceIconX = playerIconXY.X + u.PlayerIconDim.X
- deviceIconY = playerIconXY.Y + u.PlayerIconDim.Y - deviceIconDim.Y
- deviceIconXY = coords.MakeVec(deviceIconX, deviceIconY)
- deviceIconPos = coords.MakePosition(deviceIconXY, deviceIconXY, deviceIconDim)
- deviceIcon = texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, deviceIcon)
+ deviceIconPos = coords.MakeVec(playerIconPos.X+u.PlayerIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
// player 3's icon
playerIconImage = u.CurTable.GetPlayers()[3].GetImage()
playerIconX = u.WindowSize.X - u.BottomPadding - u.PlayerIconDim.X
- playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-(float32(len(u.CurTable.GetPlayers()[3].GetHand()))*(u.TableCardDim.Y-u.Overlap.Y)+u.TableCardDim.Y))/2 - u.PlayerIconDim.Y - u.Padding
- playerIconXY = coords.MakeVec(playerIconX, playerIconY)
- playerIconPos = coords.MakePosition(playerIconXY, playerIconXY, u.PlayerIconDim)
- playerIcon = texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.Eng, u.Scene)
+ playerIconY = (u.WindowSize.Y+2*u.BottomPadding+u.PlayerIconDim.Y-
+ (float32(len(u.CurTable.GetPlayers()[3].GetHand()))*
+ (u.TableCardDim.Y-u.Overlap.Y)+u.TableCardDim.Y))/2 -
+ u.PlayerIconDim.Y - u.Padding
+ playerIconPos = coords.MakeVec(playerIconX, playerIconY)
if u.Debug {
- u.Buttons = append(u.Buttons, playerIcon)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
} else {
- u.BackgroundImgs = append(u.BackgroundImgs, playerIcon)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, u.PlayerIconDim, u.Eng, u.Scene))
}
// player 3's name
end := coords.MakeVec(playerIconX+u.PlayerIconDim.X, playerIconY-30)
@@ -224,12 +213,9 @@
}
// player 3's device icon
deviceIconImage = u.Texs["laptopIcon.png"]
- deviceIconX = playerIconXY.X - deviceIconDim.X
- deviceIconY = playerIconXY.Y + u.PlayerIconDim.Y - deviceIconDim.Y
- deviceIconXY = coords.MakeVec(deviceIconX, deviceIconY)
- deviceIconPos = coords.MakePosition(deviceIconXY, deviceIconXY, deviceIconDim)
- deviceIcon = texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, deviceIcon)
+ deviceIconPos = coords.MakeVec(playerIconPos.X-deviceIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
// adding cards
for _, p := range u.CurTable.GetPlayers() {
hand := p.GetHand()
@@ -293,12 +279,9 @@
pressedImg := u.Texs["playPressed.png"]
unpressedImg := u.Texs["playUnpressed.png"]
buttonDim := coords.MakeVec(2*u.CardDim.X, u.CardDim.Y)
- buttonX := (u.WindowSize.X - u.CardDim.X) / 2
- buttonY := u.WindowSize.Y - u.CardDim.Y - u.BottomPadding
- buttonXY := coords.MakeVec(buttonX, buttonY)
- buttonPos := coords.MakePosition(buttonXY, buttonXY, buttonDim)
- button := texture.MakeImgWithAlt(unpressedImg, pressedImg, buttonPos, true, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, button)
+ buttonPos := coords.MakeVec((u.WindowSize.X-u.CardDim.X)/2, u.WindowSize.Y-u.CardDim.Y-u.BottomPadding)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithAlt(unpressedImg, pressedImg, buttonPos, buttonDim, true, u.Eng, u.Scene))
}
// Pass View: Shows player's hand and allows them to pass cards
@@ -344,20 +327,19 @@
func addHeader(u *uistate.UIState) {
// adding blue banner
headerImage := u.Texs["RoundedRectangle-DBlue.png"]
- headerXY := coords.MakeVec(0, -10)
+ headerPos := coords.MakeVec(0, -10)
headerWidth := u.WindowSize.X
headerHeight := float32(20)
headerDimensions := coords.MakeVec(headerWidth, headerHeight)
- headerPos := coords.MakePosition(headerXY, headerXY, headerDimensions)
- header := texture.MakeImgWithoutAlt(headerImage, headerPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, header)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u.Eng, u.Scene))
}
func addHeaderButton(u *uistate.UIState) {
// adding blue banner for croupier header
headerUnpressed := u.Texs["blue.png"]
headerPressed := u.Texs["bluePressed.png"]
- headerXY := coords.MakeVec(0, 0)
+ headerPos := coords.MakeVec(0, 0)
headerWidth := u.WindowSize.X
var headerHeight float32
if 2*u.CardDim.Y < headerWidth/4 {
@@ -366,18 +348,14 @@
headerHeight = headerWidth / 4
}
headerDimensions := coords.MakeVec(headerWidth, headerHeight)
- headerPos := coords.MakePosition(headerXY, headerXY, headerDimensions)
- header := texture.MakeImgWithAlt(headerUnpressed, headerPressed, headerPos, true, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, header)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithAlt(headerUnpressed, headerPressed, headerPos, headerDimensions, true, u.Eng, u.Scene))
// adding play button
playUnpressed := u.Texs["playUnpressed.png"]
playPressed := u.Texs["playPressed.png"]
playDim := coords.MakeVec(headerHeight, headerHeight/2)
- playX := (u.WindowSize.X - playDim.X) / 2
- playY := (u.TopPadding + playDim.Y) / 2
- playXY := coords.MakeVec(playX, playY)
- playPos := coords.MakePosition(playXY, playXY, playDim)
- play := texture.MakeImgWithAlt(playUnpressed, playPressed, playPos, true, u.Eng, u.Scene)
+ playPos := coords.MakeVec((u.WindowSize.X-playDim.X)/2, (u.TopPadding+playDim.Y)/2)
+ play := texture.MakeImgWithAlt(playUnpressed, playPressed, playPos, playDim, true, u.Eng, u.Scene)
u.Buttons = append(u.Buttons, play)
}
@@ -385,11 +363,10 @@
// adding gray bar
grayBarImg := u.Texs["RoundedRectangle-Gray.png"]
blueBarImg := u.Texs["RoundedRectangle-LBlue.png"]
- grayBarXY := coords.MakeVec(2*u.BottomPadding, 40-u.WindowSize.Y+4*u.BottomPadding)
+ grayBarPos := coords.MakeVec(2*u.BottomPadding, 40-u.WindowSize.Y+4*u.BottomPadding)
grayBarDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, u.WindowSize.Y-4*u.BottomPadding)
- grayBarPos := coords.MakePosition(grayBarXY, grayBarXY, grayBarDim)
- grayBar := texture.MakeImgWithAlt(grayBarImg, blueBarImg, grayBarPos, true, u.Eng, u.Scene)
- u.Other = append(u.Other, grayBar)
+ u.Other = append(u.Other,
+ texture.MakeImgWithAlt(grayBarImg, blueBarImg, grayBarPos, grayBarDim, true, u.Eng, u.Scene))
// adding name
var receivingPlayer int
switch u.CurTable.GetDir() {
@@ -416,7 +393,7 @@
// adding gray bar
grayBarImg := u.Texs["RoundedRectangle-Gray.png"]
grayBarAlt := u.Texs["RoundedRectangle-LBlue.png"]
- grayBarXY := coords.MakeVec(2*u.BottomPadding, -30)
+ grayBarPos := coords.MakeVec(2*u.BottomPadding, -30)
topOfHand := u.WindowSize.Y - 5*(u.CardDim.Y+u.Padding) - (2 * u.Padding / 5) - u.BottomPadding
var grayBarHeight float32
if display {
@@ -425,9 +402,8 @@
grayBarHeight = topOfHand - u.CardDim.Y
}
grayBarDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, grayBarHeight)
- grayBarPos := coords.MakePosition(grayBarXY, grayBarXY, grayBarDim)
- grayBar := texture.MakeImgWithAlt(grayBarImg, grayBarAlt, grayBarPos, display, u.Eng, u.Scene)
- u.Other = append(u.Other, grayBar)
+ u.Other = append(u.Other,
+ texture.MakeImgWithAlt(grayBarImg, grayBarAlt, grayBarPos, grayBarDim, display, u.Eng, u.Scene))
// adding name
var passingPlayer int
switch u.CurTable.GetDir() {
@@ -466,13 +442,12 @@
cardXStart := (u.WindowSize.X - (numCards*u.CardDim.X + (numCards-1)*u.Padding)) / 2
for i, c := range passedCards {
cardX := cardXStart + float32(i)*(u.Padding+u.CardDim.X)
- cardXY := coords.MakeVec(cardX, cardY)
- c.Move(cardXY, u.CardDim, u.Eng)
+ cardPos := coords.MakeVec(cardX, cardY)
+ c.Move(cardPos, u.CardDim, u.Eng)
reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
// invisible drop target holding card
var emptyTex sprite.SubTex
- dropPos := coords.MakePosition(cardXY, cardXY, u.CardDim)
- d := texture.MakeImgWithoutAlt(emptyTex, dropPos, u.Eng, u.Scene)
+ d := texture.MakeImgWithoutAlt(emptyTex, cardPos, u.CardDim, u.Eng, u.Scene)
d.SetCardHere(c)
u.DropTargets = append(u.DropTargets, d)
}
@@ -483,45 +458,33 @@
// adding blue background banner for drop targets
topOfHand := u.WindowSize.Y - 5*(u.CardDim.Y+u.Padding) - (2 * u.Padding / 5) - u.BottomPadding
passBannerImage := u.Texs["Rectangle-LBlue.png"]
- passBannerX := 6 * u.BottomPadding
- passBannerY := topOfHand - (2 * u.Padding)
- passBannerWidth := u.WindowSize.X - 8*u.BottomPadding
- passBannerHeight := u.CardDim.Y + 2*u.Padding
- passBannerXY := coords.MakeVec(passBannerX, passBannerY)
- passBannerDimensions := coords.MakeVec(passBannerWidth, passBannerHeight)
- passBannerPos := coords.MakePosition(passBannerXY, passBannerXY, passBannerDimensions)
- passBanner := texture.MakeImgWithoutAlt(passBannerImage, passBannerPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, passBanner)
+ passBannerPos := coords.MakeVec(6*u.BottomPadding, topOfHand-(2*u.Padding))
+ passBannerDim := coords.MakeVec(u.WindowSize.X-8*u.BottomPadding, u.CardDim.Y+2*u.Padding)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(passBannerImage, passBannerPos, passBannerDim, u.Eng, u.Scene))
// adding undisplayed pull tab
pullTabSpotImage := u.Texs["Rectangle-LBlue.png"]
pullTabImage := u.Texs["VerticalPullTab.png"]
- pullTabSpotX := 2 * u.BottomPadding
- pullTabSpotY := passBannerY
- pullTabSpotWidth := 4 * u.BottomPadding
- pullTabSpotHeight := u.CardDim.Y + 2*u.Padding
- pullTabSpotXY := coords.MakeVec(pullTabSpotX, pullTabSpotY)
- pullTabSpotDimensions := coords.MakeVec(pullTabSpotWidth, pullTabSpotHeight)
- pullTabSpotPos := coords.MakePosition(pullTabSpotXY, pullTabSpotXY, pullTabSpotDimensions)
- pullTabSpot := texture.MakeImgWithAlt(pullTabImage, pullTabSpotImage, pullTabSpotPos, false, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, pullTabSpot)
+ pullTabSpotPos := coords.MakeVec(2*u.BottomPadding, passBannerPos.Y)
+ pullTabSpotDim := coords.MakeVec(4*u.BottomPadding, u.CardDim.Y+2*u.Padding)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithAlt(pullTabImage, pullTabSpotImage, pullTabSpotPos, pullTabSpotDim, false, u.Eng, u.Scene))
// adding text
- textLeft := coords.MakeVec(pullTabSpotX+pullTabSpotWidth/2, passBannerY-20)
+ textLeft := coords.MakeVec(pullTabSpotPos.X+pullTabSpotDim.X/2, passBannerPos.Y-20)
scaler := float32(5)
- maxWidth := passBannerWidth
+ maxWidth := passBannerDim.X
text := texture.MakeStringImgLeftAlign("Pass:", "", "None", true, textLeft, scaler, maxWidth, u)
u.BackgroundImgs = append(u.BackgroundImgs, text...)
// adding drop targets
dropTargetImage := u.Texs["trickDrop.png"]
- dropTargetDimensions := u.CardDim
- dropTargetY := passBannerY + u.Padding
+ dropTargetY := passBannerPos.Y + u.Padding
numDropTargets := float32(3)
- dropTargetXStart := (u.WindowSize.X - (numDropTargets*dropTargetDimensions.X + (numDropTargets-1)*u.Padding)) / 2
+ dropTargetXStart := (u.WindowSize.X - (numDropTargets*u.CardDim.X + (numDropTargets-1)*u.Padding)) / 2
for i := 0; i < int(numDropTargets); i++ {
- dropTargetX := dropTargetXStart + float32(i)*(u.Padding+dropTargetDimensions.X)
- dropTargetXY := coords.MakeVec(dropTargetX, dropTargetY)
- dropTargetPos := coords.MakePosition(dropTargetXY, dropTargetXY, dropTargetDimensions)
- newTarget := texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.Eng, u.Scene)
- u.DropTargets = append(u.DropTargets, newTarget)
+ dropTargetX := dropTargetXStart + float32(i)*(u.Padding+u.CardDim.X)
+ dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
+ u.DropTargets = append(u.DropTargets,
+ texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, u.CardDim, u.Eng, u.Scene))
}
}
@@ -554,10 +517,9 @@
suitBannerDim := coords.MakeVec(suitBannerWidth, suitBannerHeight)
for i := 0; i < u.NumSuits; i++ {
suitBannerY := u.WindowSize.Y - float32(i+1)*(u.CardDim.Y+u.Padding) - (2 * u.Padding / 5) - u.BottomPadding
- suitBannerXY := coords.MakeVec(suitBannerX, suitBannerY)
- suitBannerPos := coords.MakePosition(suitBannerXY, suitBannerXY, suitBannerDim)
- suitBanner := texture.MakeImgWithoutAlt(suitBannerImage, suitBannerPos, u.Eng, u.Scene)
- u.BackgroundImgs = append(u.BackgroundImgs, suitBanner)
+ suitBannerPos := coords.MakeVec(suitBannerX, suitBannerY)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(suitBannerImage, suitBannerPos, suitBannerDim, u.Eng, u.Scene))
}
// adding suit image to any empty suit in hand
for i, c := range suitCounts {
@@ -576,14 +538,11 @@
suitIconAlt := u.Texs["gray.png"]
suitIconX := u.WindowSize.X/2 - u.CardDim.X/3
suitIconY := u.WindowSize.Y - float32(4-i)*(u.CardDim.Y+u.Padding) + u.CardDim.Y/6 - u.BottomPadding
- suitIconWidth := 2 * u.CardDim.X / 3
- suitIconHeight := 2 * u.CardDim.Y / 3
display := c == 0
- suitIconXY := coords.MakeVec(suitIconX, suitIconY)
- suitIconDim := coords.MakeVec(suitIconWidth, suitIconHeight)
- suitIconPos := coords.MakePosition(suitIconXY, suitIconXY, suitIconDim)
- suitIcon := texture.MakeImgWithAlt(suitIconImage, suitIconAlt, suitIconPos, display, u.Eng, u.Scene)
- u.EmptySuitImgs = append(u.EmptySuitImgs, suitIcon)
+ suitIconPos := coords.MakeVec(suitIconX, suitIconY)
+ suitIconDim := u.CardDim.Times(2).DividedBy(3)
+ u.EmptySuitImgs = append(u.EmptySuitImgs,
+ texture.MakeImgWithAlt(suitIconImage, suitIconAlt, suitIconPos, suitIconDim, display, u.Eng, u.Scene))
}
// adding clubs
for i := 0; i < clubCount; i++ {
@@ -633,17 +592,11 @@
func addDebugBar(u *uistate.UIState) {
buttonDim := u.CardDim
debugTableImage := u.Texs["BakuSquare.png"]
- debugTableX := u.WindowSize.X - buttonDim.X
- debugTableY := u.WindowSize.Y - buttonDim.Y
- debugTableXY := coords.MakeVec(debugTableX, debugTableY)
- debugTablePos := coords.MakePosition(debugTableXY, debugTableXY, buttonDim)
- debugTable := texture.MakeImgWithoutAlt(debugTableImage, debugTablePos, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, debugTable)
+ debugTablePos := u.WindowSize.MinusVec(buttonDim)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(debugTableImage, debugTablePos, buttonDim, u.Eng, u.Scene))
debugPassImage := u.Texs["Clubs-2.png"]
- debugPassX := u.WindowSize.X - 2*buttonDim.X
- debugPassY := u.WindowSize.Y - buttonDim.Y
- debugPassXY := coords.MakeVec(debugPassX, debugPassY)
- debugPassPos := coords.MakePosition(debugPassXY, debugPassXY, buttonDim)
- debugPass := texture.MakeImgWithoutAlt(debugPassImage, debugPassPos, u.Eng, u.Scene)
- u.Buttons = append(u.Buttons, debugPass)
+ debugPassPos := coords.MakeVec(u.WindowSize.X-2*buttonDim.X, u.WindowSize.Y-buttonDim.Y)
+ u.Buttons = append(u.Buttons,
+ texture.MakeImgWithoutAlt(debugPassImage, debugPassPos, buttonDim, u.Eng, u.Scene))
}
diff --git a/go/src/hearts/logic/card/card.go b/go/src/hearts/logic/card/card.go
index fa8a56a..7e1c76b 100644
--- a/go/src/hearts/logic/card/card.go
+++ b/go/src/hearts/logic/card/card.go
@@ -159,7 +159,12 @@
node *sprite.Node
image sprite.SubTex
back sprite.SubTex
- pos *coords.Position
+ // XY coordinates of the initial placement of the card
+ initial *coords.Vec
+ // current XY coordinates of the card
+ current *coords.Vec
+ // current width and height of the card
+ dimensions *coords.Vec
}
// Returns the suit of c
@@ -187,23 +192,19 @@
return c.back
}
-func (c *Card) GetPosition() *coords.Position {
- return c.pos
-}
-
// Returns a vector containing the current x- and y-coordinate of the upper left corner of c
func (c *Card) GetCurrent() *coords.Vec {
- return c.pos.GetCurrent()
+ return c.current
}
// Returns a vector containing the initial x- and y-coordinate of the upper left corner of c
func (c *Card) GetInitial() *coords.Vec {
- return c.pos.GetInitial()
+ return c.initial
}
// Returns a vector containing the width and height of c
func (c *Card) GetDimensions() *coords.Vec {
- return c.pos.GetDimensions()
+ return c.dimensions
}
// Sets the node of c to n
@@ -237,24 +238,13 @@
{newDimensions.X, 0, newXY.X},
{0, newDimensions.Y, newXY.Y},
})
- pos := coords.MakePosition(c.GetInitial(), newXY, newDimensions)
- c.SetPos(pos)
-}
-
-// Sets the variables of c to a new position and size, but does not actually update the image on-screen
-func (c *Card) SetPos(pos *coords.Position) {
- c.pos = pos
+ c.current = newXY
+ c.dimensions = newDimensions
}
// Sets the initial x and y coordinates of c
func (c *Card) SetInitial(newInitial *coords.Vec) {
- c.pos.SetInitial(newInitial)
-}
-
-func (c *Card) InitializePosition() {
- zero := coords.MakeVec(0, 0)
- pos := coords.MakePosition(zero, zero, zero)
- c.SetPos(pos)
+ c.initial = newInitial
}
// Returns true if c is worth any points (all Hearts cards, and the Queen of Spades)
diff --git a/go/src/hearts/touchhandler/touchhandler.go b/go/src/hearts/touchhandler/touchhandler.go
index b759658..ccc1d9f 100644
--- a/go/src/hearts/touchhandler/touchhandler.go
+++ b/go/src/hearts/touchhandler/touchhandler.go
@@ -119,12 +119,10 @@
}
blueBanner := u.Other[0]
if blueBanner.GetNode().Arranger == nil {
- startingPosition := coords.MakePosition(blueBanner.GetInitial(), blueBanner.GetInitial(), blueBanner.GetDimensions())
finalX := blueBanner.GetInitial().X
finalY := pullTab.GetInitial().Y + pullTab.GetDimensions().Y - blueBanner.GetDimensions().Y
- finalVec := coords.MakeVec(finalX, finalY)
- finalPosition := coords.MakePosition(finalVec, finalVec, blueBanner.GetDimensions())
- reposition.AnimateImageMovement(blueBanner, startingPosition, finalPosition)
+ finalPos := coords.MakeVec(finalX, finalY)
+ reposition.AnimateImageMovement(blueBanner, finalPos, blueBanner.GetDimensions())
}
}
} else if u.Buttons[1] == buttonList[0] {