Example #1
0
func (g *stageLayer) Setup() (err error) {
	g.surface, err = util.CreateSurface(true, true, g.size_x, g.size_y)
	if err != nil {
		return err
	}

	var row uint16
	var col uint16
	var y_tile uint16
	var x_tile uint16
	var y_tiles uint16
	var x_tiles uint16

	stage := g.game.GetStage()
	for row = 0; row < uint16(len(stage.Tiles[0])); row++ {
		for col = 0; col < uint16(len(stage.Tiles)); col++ {
			texture := g.terrain_textures[stage.Tiles[col][row]]

			x_tiles = g.square_size / texture.Width
			y_tiles = g.square_size / texture.Height

			if x_tiles == 0 || y_tiles == 0 {
				panic(fmt.Errorf("terrain (%s) texture is larger than square_size (%d, %d) > %d", texture.Name, texture.Width, texture.Height, g.square_size))
			}

			for y_tile = 0; y_tile < y_tiles; y_tile++ {
				for x_tile = 0; x_tile < x_tiles; x_tile++ {
					errno := g.surface.Blit(
						&sdl.Rect{
							X: int16(col*g.square_size + x_tile*texture.Width),
							Y: int16(row*g.square_size + y_tile*texture.Height),
							W: texture.Width,
							H: texture.Height,
						},
						texture.Surface,
						&sdl.Rect{
							X: 0,
							Y: 0,
							W: texture.Width,
							H: texture.Height,
						},
					)

					if errno != 0 {
						return fmt.Errorf("Blit failed: %s", sdl.GetError())
					}
				}
			}
		}
	}

	if g.child != nil {
		return g.child.Setup()
	}

	return nil
}
Example #2
0
func (g *panLayer) Setup() (err error) {
	g.child_x, g.child_y = g.child.GetSize()

	g.surface, err = util.CreateSurface(true, true, g.child_x, g.child_y)
	if err != nil {
		return err
	}

	return g.child.Setup()
}
Example #3
0
func (g *buildLayer) Setup() (err error) {
	// TODO: make tower size come in properly
	g.buildSurface, err = util.CreateSurface(true, true, 1*g.square_size, 1*g.square_size)
	if err != nil {
		return err
	}

	g.buildSurface.SetAlpha(sdl.SRCALPHA, 128)
	if g.child != nil {
		return g.child.Setup()
	}

	return nil
}