Exemple #1
0
// generateBackground creates a background of green tiles - might not be the most efficient way to do this
func generateBackground() *ecs.Entity {
	rect := image.Rect(0, 0, int(worldWidth), int(worldHeight))
	img := image.NewNRGBA(rect)
	c1 := color.RGBA{102, 153, 0, 255}
	c2 := color.RGBA{102, 173, 0, 255}
	for i := rect.Min.X; i < rect.Max.X; i++ {
		for j := rect.Min.Y; j < rect.Max.Y; j++ {
			if i%40 > 20 {
				if j%40 > 20 {
					img.Set(i, j, c1)
				} else {
					img.Set(i, j, c2)
				}
			} else {
				if j%40 > 20 {
					img.Set(i, j, c2)
				} else {
					img.Set(i, j, c1)
				}
			}
		}
	}
	bgTexture := engi.NewImageObject(img)
	field := ecs.NewEntity([]string{"RenderSystem"})
	fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "Background1")
	fieldRender.SetPriority(engi.Background)
	fieldSpace := &engi.SpaceComponent{engi.Point{0, 0}, worldWidth, worldHeight}
	field.AddComponent(fieldRender)
	field.AddComponent(fieldSpace)
	return field
}
Exemple #2
0
// generateBackground creates a background of green tiles - might not be the most efficient way to do this
func generateBackground() *engi.RenderComponent {
	rect := image.Rect(0, 0, int(boxWidth), int(boxHeight))
	img := image.NewNRGBA(rect)
	c1 := color.RGBA{102, 153, 0, 255}
	for i := rect.Min.X; i < rect.Max.X; i++ {
		for j := rect.Min.Y; j < rect.Max.Y; j++ {
			img.Set(i, j, c1)
		}
	}
	bgTexture := engi.NewImageObject(img)
	fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "Background1")
	fieldRender.SetPriority(engi.Background)
	return fieldRender
}
Exemple #3
0
// generateHUDBackground creates a violet HUD on the left side of the screen - might be inefficient
func generateHUDBackground(width, height float32) *ecs.Entity {
	rect := image.Rect(0, 0, int(width), int(height))
	img := image.NewNRGBA(rect)
	c1 := color.RGBA{255, 0, 255, 180}
	for i := rect.Min.X; i < rect.Max.X; i++ {
		for j := rect.Min.Y; j < rect.Max.Y; j++ {
			img.Set(i, j, c1)
		}
	}
	bgTexture := engi.NewImageObject(img)
	field := ecs.NewEntity([]string{"RenderSystem"})
	fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "HUDBackground1")
	fieldRender.SetPriority(hudBackgroundPriority)
	fieldSpace := &engi.SpaceComponent{engi.Point{-1, -1}, width, height}
	field.AddComponent(fieldRender)
	field.AddComponent(fieldSpace)
	return field
}
Exemple #4
0
// GenerateSquareComonent creates a square, alternating two colors, with given size and priority levl
func GenerateSquareComonent(c1, c2 color.NRGBA, w, h float32, priority engi.PriorityLevel) *engi.RenderComponent {
	rect := image.Rect(0, 0, int(w), int(h))
	img := image.NewNRGBA(rect)
	if c1 == c2 {
		// Solid color
		for i := 0; i < len(img.Pix); i += 4 {
			img.Pix[i] = c1.R
			img.Pix[i+1] = c1.G
			img.Pix[i+2] = c1.B
			img.Pix[i+3] = c1.A
		}
	} else {
		// TODO: we can optimize this as well
		for i := rect.Min.X; i < rect.Max.X; i++ {
			for j := rect.Min.Y; j < rect.Max.Y; j++ {
				if i%40 > 20 {
					if j%40 > 20 {
						img.Set(i, j, c1)
					} else {
						img.Set(i, j, c2)
					}
				} else {
					if j%40 > 20 {
						img.Set(i, j, c2)
					} else {
						img.Set(i, j, c1)
					}
				}
			}
		}
	}

	bgTexture := engi.NewImageObject(img)
	fieldRender := engi.NewRenderComponent(engi.NewRegion(engi.NewTexture(bgTexture), 0, 0, int(w), int(h)), engi.Point{1, 1}, "")
	fieldRender.SetPriority(priority)

	return fieldRender
}