Exemplo n.º 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,
		)
	}
}
Exemplo n.º 2
0
func MakeSurface(surf *sdl.Surface) *Surface {
	surf.Lock() // Get Lock before creating the surface slice.
	surface := &Surface{surf, nil}
	sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&surface.pixels)))
	sliceHeader.Cap = int(surf.H * surf.W)
	sliceHeader.Len = int(surf.H * surf.W)
	sliceHeader.Data = uintptr(unsafe.Pointer(surf.Pixels))
	surf.Unlock()
	return surface
}
Exemplo n.º 3
0
// 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()
}
Exemplo n.º 4
0
Arquivo: ttf.go Projeto: neagix/Go-SDL
func wrap(cSurface *C.SDL_Surface) *sdl.Surface {
	var s *sdl.Surface

	if cSurface != nil {
		var surface sdl.Surface
		surface.SetCSurface(unsafe.Pointer(cSurface))
		s = &surface
	} else {
		s = nil
	}

	return s
}
Exemplo n.º 5
0
func (g *stageLayer) Render(target *sdl.Surface) {

	target.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
			W: uint16(g.size_x),
			H: uint16(g.size_y),
		},
		g.surface,
		nil,
	)

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

}
Exemplo n.º 6
0
func (g *buildLayer) Render(target *sdl.Surface) {
	x_off, y_off := g.GetXYOffsets()
	square_x, square_y := util.GetMouse(g.square_size, x_off, y_off, false)

	var build_colour uint32
	if g.controls.GetPlayer().Buildable(square_y/g.square_size, square_x/g.square_size) {
		build_colour = 0x00ff00
	} else {
		build_colour = 0xff0000
	}

	g.buildSurface.FillRect(
		&sdl.Rect{
			X: 0,
			Y: 0,
			H: 128,
			W: 128,
		},
		build_colour,
	)

	g.buildSurface.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
		},
		g.texture_map.GetName("turret_basic").Surface,
		nil,
	)

	target.Blit(
		&sdl.Rect{
			X: int16(square_x),
			Y: int16(square_y),
		},
		g.buildSurface,
		nil,
	)

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

}
Exemplo n.º 7
0
func (m *MainMenu) Draw(screen *sdl.Surface, top bool) {
	w := uint16(m.titleText.W)
	h := uint16(m.titleText.H)
	screen.Blit(
		&sdl.Rect{
			X: int16(screen.W - m.titleText.W - 50),
			Y: 15,
			W: w,
			H: h,
		},
		m.titleText,
		&sdl.Rect{X: 0, Y: 0, W: w, H: h},
	)

	m.menuItemSelected = ""
	y := int16(screen.H - menuItemYOffset)
	for _, label := range m.itemLabels {
		item := m.menuItems[label]
		mx := int16(m.mouseX)
		my := int16(m.mouseY)
		w = uint16(item.W)
		h = uint16(item.H)
		y -= int16(item.H)
		if ui.Overlaps(mx, my, menuItemXOffset, y, w, h) {
			if top {
				item = m.hoverItems[label]
			}
			m.menuItemSelected = label
		}

		screen.Blit(
			&sdl.Rect{
				X: menuItemXOffset,
				Y: int16(y),
				W: w,
				H: h,
			},
			item,
			&sdl.Rect{X: 0, Y: 0, W: w, H: h},
		)
	}
}
Exemplo n.º 8
0
func (g *panLayer) Render(target *sdl.Surface) {
	g.child.Render(g.surface)
	g.surface.Flip()

	parent_x, parent_y := g.parent.GetSize()

	target.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
			W: parent_x,
			H: parent_y,
		},
		g.surface,
		&sdl.Rect{
			X: int16(g.view_x),
			Y: int16(g.view_y),
			W: parent_x,
			H: parent_y,
		},
	)
}
Exemplo n.º 9
0
func (t *TextBox) Draw(screen *sdl.Surface) {
	y := t.Y
	lineSpacing := 0
	for _, line := range t.lines {
		if line == nil {
			y += int16(lineSpacing)
			continue
		} else {
			lineSpacing = int(line.H) / 2
		}

		if uint16(y)+uint16(line.H)-uint16(t.Y) > t.H {
			continue
		}

		x := int16(t.X)
		switch t.FontAlignment {
		case Left:
			x += 0
		case Center:
			x += (int16(t.W) - int16(line.W)) / 2
		case Right:
			x += int16(t.W) - int16(line.W)
		}

		screen.Blit(
			&sdl.Rect{
				X: x,
				Y: y,
				W: uint16(line.W),
				H: uint16(line.H),
			},
			line,
			&sdl.Rect{W: uint16(line.W), H: uint16(line.H)},
		)
		y += int16(line.H)
	}
}
Exemplo n.º 10
0
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)
	}
}
Exemplo n.º 11
0
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)},
	)
}
Exemplo n.º 12
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)
	}

}