Exemplo n.º 1
0
func highlightCorner(game *game.Game, window draw.Window) {
	mx, my := window.MousePosition()
	w, h := window.Size()
	var position point
	const radius = 40
	const squareRadius = radius * radius

	yOffset := 0
	for y := 0; y < h; y += tileH - tileSlopeHeight {
		for x := 0; x < w; x += tileW / 2 {
			if squareDist(x, y+yOffset, mx, my) < squareRadius {
				position = point{x, y + yOffset}
			}
			yOffset = tileSlopeHeight - yOffset
		}
		yOffset = tileSlopeHeight - yOffset
	}

	if position.x != 0 || position.y != 0 {
		window.FillEllipse(
			position.x-radius, position.y-radius,
			2*radius, 2*radius,
			draw.RGBA(1, 0, 0.5, 0.75))
	}
}
Exemplo n.º 2
0
func highlightEdge(game *game.Game, window draw.Window) {
	mx, my := window.MousePosition()
	for _, tile := range game.GetTiles() {
		hex := hexagonAtTile(tile.Position.X, tile.Position.Y)

		r := rect{hex[1].x - tileSlopeHeight/2, hex[1].y, tileSlopeHeight, hex[2].y - hex[1].y}
		if r.contains(mx, my) {
			window.FillRect(r.x, r.y, r.w, r.h, draw.RGBA(1.0, 0, 0.5, 0.75))
			return
		}

		r = rect{hex[3].x, hex[2].y, hex[2].x - hex[3].x, hex[3].y - hex[2].y}
		if r.contains(mx, my) {
			window.FillRect(r.x, r.y, r.w, r.h, draw.RGBA(1.0, 0, 0.5, 0.75))
			return
		}

		r = rect{hex[4].x, hex[4].y, hex[3].x - hex[4].x, hex[3].y - hex[4].y}
		if r.contains(mx, my) {
			window.FillRect(r.x, r.y, r.w, r.h, draw.RGBA(1.0, 0, 0.5, 0.75))
			return
		}
	}
}
Exemplo n.º 3
0
func drawGame(g *game.Game, window draw.Window) {
	// draw tiles and numbers
	w, h := window.Size()
	window.FillRect(0, 0, w, h, draw.DarkBlue)
	for _, tile := range g.GetTiles() {
		x := tile.Position.X * tileW / 2
		y := tile.Position.Y * tileYOffset
		var file string
		switch tile.Terrain {
		case game.Forest:
			file = "./forest.png"
		case game.Field:
			file = "./field.png"
		case game.Mountains:
			file = "./mountains.png"
		case game.Pasture:
			file = "./pasture.png"
		case game.Desert:
			file = "./desert.png"
		case game.Hills:
			file = "./hills.png"
		case game.Water:
			file = "./water.png"
		}
		window.DrawImageFile(file, x, y)
		if tile.Number != 0 || tile.Terrain == game.Desert {
			number := strconv.Itoa(tile.Number)
			const scale = 4
			w, h := window.GetScaledTextSize(number, scale)
			x, y := x+(tileW-w)/2, y+(tileH-h)/2
			plateSize := max(w, h) + 10
			window.FillEllipse(x+w/2-plateSize/2, y+h/2-plateSize/2,
				plateSize, plateSize, draw.RGBA(1, 1, 1, 0.5))
			numberColor := draw.Black
			if tile.Number == 6 || tile.Number == 8 {
				numberColor = draw.Red
			}
			window.DrawScaledText(number, x+3, y+3, scale, numberColor)
			if tile.HasRobber {
				window.FillEllipse(x+w/2-plateSize/2, y+h/2-plateSize/2,
					plateSize, plateSize, draw.DarkGray)
			}
		}
	}

	// draw buildings
	for _, player := range g.GetPlayers() {
		for _, s := range player.GetBuiltSettlements() {
			var file string
			switch player.Color {
			case game.Red:
				file = "./settlement_red.png"
			case game.Blue:
				file = "./settlement_blue.png"
			case game.White:
				file = "./settlement_white.png"
			case game.Orange:
				file = "./settlement_orange.png"
			}
			x, y := cornerToScreen(game.Point(s.Position))
			window.DrawImageFile(file, x-30/2, y-42/2)
		}
		for _, s := range player.GetBuiltCities() {
			var file string
			switch player.Color {
			case game.Red:
				file = "./city_red.png"
			case game.Blue:
				file = "./city_blue.png"
			case game.White:
				file = "./city_white.png"
			case game.Orange:
				file = "./city_orange.png"
			}
			x, y := cornerToScreen(game.Point(s.Position))
			window.DrawImageFile(file, x-65/2, y-42/2)
		}
		for _, s := range player.GetBuiltRoads() {
			var color draw.Color
			switch player.Color {
			case game.Red:
				color = draw.Red
			case game.Blue:
				color = draw.Blue
			case game.White:
				color = draw.White
			case game.Orange:
				color = draw.LightBrown // TODO have orange in prototype/draw
			}
			x, y := edgeToScreen(s.Position)
			window.FillRect(x-20, y-20, 40, 40, color)
		}
	}
}