Skip to content

Commit

Permalink
18/8/21 9:23 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
eboatwright committed Aug 19, 2021
1 parent a43569e commit 95e703d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
38 changes: 38 additions & 0 deletions builtInComponentsAndSystems/rectangleRenderer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package builtInComponentsAndSystems


import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"

"github.com/eboatwright/pearl"

"image/color"
)


type RectangleRenderer struct {
Color color.RGBA
}
func (rr *RectangleRenderer) ID() string { return "rectangleRenderer" }


type RectangleRendererSystem struct {}

func (rrs *RectangleRendererSystem) Update(entity *pearl.Entity, scene *pearl.Scene) {}

func (rrs *RectangleRendererSystem) Draw(entity *pearl.Entity, scene *pearl.Scene, screen *ebiten.Image, options *ebiten.DrawImageOptions) {
t := entity.GetComponent("transform").(*Transform)
rr := entity.GetComponent("rectangleRenderer").(*RectangleRenderer)

ebitenutil.DrawRect(
screen,
t.Position.X, t.Position.Y,
t.Scale.X, t.Scale.Y,
rr.Color,
)
}

func (rrs *RectangleRendererSystem) GetRequirements() []string {
return []string { "transform", "rectangleRenderer" }
}
34 changes: 34 additions & 0 deletions examples/2-rectangle/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main


import (
"github.com/eboatwright/pearl"
bicas "github.com/eboatwright/pearl/builtInComponentsAndSystems"
)


func main() {
pearl.Start(960, 600, 3, "Rectangle Rendering", pearl.RGBA(0, 0, 0, 255), func() {
gameScene := &pearl.Scene { ID: "game" }
pearl.LoadScene(gameScene)

rect := &pearl.Entity { ID: "rect" }
rect.AddComponents([]pearl.IComponent {
&bicas.Transform {
Position: pearl.Vector2 { 5, 5 },
Scale: pearl.Vector2 { 10, 10 },
},
&bicas.RectangleRenderer {
Color: pearl.RGBA(255, 255, 255, 255),
},
})

gameScene.AddEntities([]*pearl.Entity {
rect,
})

gameScene.AddSystems([]pearl.ISystem {
&bicas.RectangleRendererSystem { },
})
})
}
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.

0 comments on commit 95e703d

Please sign in to comment.