示例#1
0
func (g *guiLayer) Render(target *sdl.Surface) {
	if g.child != nil {
		g.child.Render(target)
	}

	target.FillRect(
		&sdl.Rect{
			X: 20,
			Y: 300,
			H: uint16(30 + (30 * g.game.NumPlayers)),
			W: 200,
		},
		0xffffff,
	)

	for i := 0; i < g.game.NumPlayers; i++ {
		p := g.game.GetPlayer(i)
		str := fmt.Sprintf("Player %d: %d - %d - %d", i, p.Money.Get(), p.Money.GetIncome(), p.GetLives())

		txt_surface := ttf.RenderText_Solid(g.font, str, sdl.Color{})
		if txt_surface == nil {
			fmt.Printf("RenderText Solid failed: %s", sdl.GetError())
		}

		target.Blit(
			&sdl.Rect{
				X: 50,
				Y: int16(320 + (i * 30)),
			},
			txt_surface,
			nil,
		)
	}
}
示例#2
0
文件: layer.go 项目: bieber/drones
// Draw directs each layer, starting from the bottom, to draw to the
// screen, and then updates the necessary parts of the screen.
func (stack LayerStack) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{X: 0, Y: 0, W: uint16(screen.W), H: uint16(screen.H)},
		0,
	)
	for i, layer := range stack {
		top := i == len(stack)-1
		layer.Draw(screen, top)
	}
	screen.Flip()
}
示例#3
0
文件: button.go 项目: bieber/drones
func (b *Button) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: b.X,
			Y: b.Y,
			W: b.W,
			H: b.H,
		},
		ui.ColorToInt(b.BorderColor),
	)
	var fillColor sdl.Color
	if b.hovered {
		fillColor = b.HoverColor
	} else {
		fillColor = b.BGColor
	}
	screen.FillRect(
		&sdl.Rect{
			X: b.X + int16(b.BorderWidth),
			Y: b.Y + int16(b.BorderWidth),
			W: b.W - 2*uint16(b.BorderWidth),
			H: b.H - 2*uint16(b.BorderWidth),
		},
		ui.ColorToInt(fillColor),
	)
	screen.Blit(
		&sdl.Rect{
			X: b.X + int16((int32(b.W)-b.labelText.W)/2),
			Y: b.Y + int16((int32(b.H)-b.labelText.H)/2),
			W: uint16(b.labelText.W),
			H: uint16(b.labelText.H),
		},
		b.labelText,
		&sdl.Rect{W: uint16(b.labelText.W), H: uint16(b.labelText.H)},
	)
}
示例#4
0
文件: window.go 项目: bieber/drones
func (w *Window) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: w.X,
			Y: w.Y,
			W: w.W,
			H: w.H,
		},
		ui.ColorToInt(w.BorderColor),
	)
	screen.FillRect(
		&sdl.Rect{
			X: w.X + int16(w.BorderWidth),
			Y: w.Y + int16(w.BorderWidth),
			W: w.W - w.BorderWidth*2,
			H: w.H - w.BorderWidth*2,
		},
		ui.ColorToInt(w.BGColor),
	)

	for _, child := range w.children {
		child.Draw(screen)
	}
}
示例#5
0
func (g *entityLayer) Render(target *sdl.Surface) {

	var units = make(map[string]*sdl.Surface)

	turret_texture := g.texture_map.GetName("turret_basic").Surface

	for i := 0; i < g.game.NumPlayers; i++ {
		player := g.game.GetPlayer(i)

		for loc, _ := range player.Towers {
			target.Blit(
				&sdl.Rect{
					X: int16(loc.Col * g.square_size),
					Y: int16(loc.Row * g.square_size),
				},
				turret_texture,
				nil,
			)
		}

		for _, u := range player.Units {
			unit_name := u.Type.Name
			_, ok := units[unit_name]
			if !ok {
				units[unit_name] = g.texture_map.GetName(unit_name).Surface
			}

			loc := u.Loc
			target.Blit(
				&sdl.Rect{
					X: int16(loc.Col*float64(g.square_size)) - 32,
					Y: int16(loc.Row*float64(g.square_size)) - 32,
				},
				units[unit_name],
				nil,
			)

			health := 64 * (float64(u.Health) / float64(u.Type.Health))

			target.FillRect(
				&sdl.Rect{
					X: int16(loc.Col*float64(g.square_size)) - 32,
					Y: int16(loc.Row*float64(g.square_size)) - 32,
					W: 5,
					H: 64,
				},
				0x000000,
			)

			if health > 0 {
				target.FillRect(
					&sdl.Rect{
						X: int16(loc.Col*float64(g.square_size)) - 32,
						Y: int16(loc.Row*float64(g.square_size)) - 32,
						W: 5,
						H: uint16(health),
					},
					0x00ff00,
				)
			}

		}
	}

	if g.child != nil {
		g.child.Render(target)
	}

}