コード例 #1
0
ファイル: main.go プロジェクト: gonutz/go8
func drawScreen(window *draw.Window, screen chip8.Screen) {
	window.FillRect(0, 0, 640, 480, draw.Black)
	w, h := screen.Size()
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if screen.IsSet(x, y) {
				window.FillRect(x*10, y*10, 10, 10, draw.White)
			}
		}
	}
}
コード例 #2
0
ファイル: main_prototype.go プロジェクト: gonutz/settlers
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
		}
	}
}
コード例 #3
0
ファイル: main_prototype.go プロジェクト: gonutz/settlers
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)
		}
	}
}