summaryrefslogtreecommitdiff
path: root/engine/CoreObjects
diff options
context:
space:
mode:
Diffstat (limited to 'engine/CoreObjects')
-rw-r--r--engine/CoreObjects/DynamicObject.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/engine/CoreObjects/DynamicObject.go b/engine/CoreObjects/DynamicObject.go
index 0a10f0a..9b309dd 100644
--- a/engine/CoreObjects/DynamicObject.go
+++ b/engine/CoreObjects/DynamicObject.go
@@ -34,7 +34,35 @@ type DynamicObject struct {
// represents one of those parts
type TextureBlock struct {
Texture *rl.Texture2D
- Offset rl.Vector2
+ // The space occupied by the sprite in world relative to the base object position
+ Window *rl.Rectangle
+
+ // The base rectangle of the texture (calculated once in the initialization step)
+ baseRect *rl.Rectangle
+}
+
+// Inintializes the texture block for futher render
+func (base *TextureBlock) init() {
+ base.baseRect = &rl.Rectangle{
+ X: 0,
+ Y: 0,
+ Height: float32(base.Texture.Height),
+ Width: float32(base.Texture.Width),
+ }
+}
+
+func (base *TextureBlock) draw(objPos *rl.Vector2) {
+ var targetWindow = rl.Rectangle {
+ X: base.Window.X + objPos.X,
+ Y: base.Window.Y + objPos.Y,
+ Width: base.Window.Width,
+ Height: base.Window.Height,
+ }
+ rl.DrawTexturePro(*base.Texture,
+ *base.baseRect,
+ targetWindow,
+ rl.Vector2Zero(),
+ 0, rl.White)
}
type ColliderBlock struct {
@@ -47,6 +75,9 @@ func (base *DynamicObject) Init(manager *SceneManager) {
panic("Failed to initialize a dynamic object: the scene was not selected")
}
base.parentScene = manager.SelectedScene
+ for _, v := range base.Textures {
+ v.init()
+ }
}
func (base *DynamicObject) Destroy() {
@@ -88,10 +119,7 @@ func (base *DynamicObject) drawOverlay() {
func (base *DynamicObject) Draw() {
for _, v := range base.Textures {
- rl.DrawTexture(*v.Texture,
- int32(base.Position.X + v.Offset.X),
- int32(base.Position.Y + v.Offset.Y),
- rl.White)
+ v.draw(&base.Position)
}
if settings.State.DrawColliders {
for _, v := range base.Colliders {