Skip to content

Commit 14d7069

Browse files
authored
Merge branch 'main' into feature/particle-fx
2 parents d9d3f07 + 91fc710 commit 14d7069

File tree

16 files changed

+162
-680
lines changed

16 files changed

+162
-680
lines changed

src/Camera.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using JulGame
22
using .Math
33
import JulGame: deprecated_get_property
4-
import JulGame.Component: get_position, get_scale
4+
import JulGame.Component
55

66
mutable struct Camera
77
dimensions::Vector2
@@ -48,9 +48,9 @@ function update(this::Camera, newPosition = C_NULL)
4848
SDL2.SDL_RenderFillRectF(Renderer, Ref(SDL2.SDL_FRect(this.windowPos.x, this.windowPos.y, this.dimensions.x, this.dimensions.y)))
4949

5050
if this.target != C_NULL && newPosition == C_NULL
51-
targetPos = get_position(this.target)
51+
targetPos = this.target.position
5252
center = Vector2f(this.dimensions.x/SCALE_UNITS/2, this.dimensions.y/SCALE_UNITS/2)
53-
targetScale = get_scale(this.target)
53+
targetScale = this.target.scale
5454
this.position = targetPos - center + 0.5 * targetScale + this.offset
5555
return
5656
end

src/Component/CircleCollider.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module CircleColliderModule
8383
if CheckIfResting(this, colliders[i])[1] == true && length(this.currentRests) > 0 && !(colliders[i] in this.currentRests)
8484
# if this collider isn't already in the list of current rests, check if it is on the same Y level and the same size as any of the current rests, if it is, then add it to current rests
8585
for j in eachindex(this.currentRests)
86-
if this.currentRests[j].getParent().transform.getPosition().y == colliders[i].getParent().transform.getPosition().y && this.currentRests[j].getSize().y == colliders[i].getSize().y
86+
if this.currentRests[j].getParent().transform.position.y == colliders[i].getParent().transform.position.y && this.currentRests[j].getSize().y == colliders[i].getSize().y
8787
push!(this.currentRests, colliders[i])
8888
break
8989
end
@@ -96,34 +96,34 @@ module CircleColliderModule
9696
# eventToCall()
9797
# end
9898
# #Begin to overlap, correct position
99-
# transform.setPosition(Math.Vector2f(transform.getPosition().x, transform.getPosition().y + collision[2]))
99+
# transform.setPosition(Math.Vector2f(transform.position.x, transform.position.y + collision[2]))
100100
# end
101101
# if collision[1] == Left::CollisionDirection
102102
# push!(this.currentCollisions, colliders[i])
103103
# for eventToCall in this.collisionEvents
104104
# eventToCall()
105105
# end
106106
# #Begin to overlap, correct position
107-
# transform.setPosition(Math.Vector2f(transform.getPosition().x + collision[2], transform.getPosition().y))
107+
# transform.setPosition(Math.Vector2f(transform.position.x + collision[2], transform.position.y))
108108
# end
109109
# if collision[1] == Right::CollisionDirection
110110
# push!(this.currentCollisions, colliders[i])
111111
# for eventToCall in this.collisionEvents
112112
# eventToCall()
113113
# end
114114
# #Begin to overlap, correct position
115-
# transform.setPosition(Math.Vector2f(transform.getPosition().x - collision[2], transform.getPosition().y))
115+
# transform.setPosition(Math.Vector2f(transform.position.x - collision[2], transform.position.y))
116116
# end
117117
# if collision[1] == Bottom::CollisionDirection
118118
#this.isGrounded = collision[1]
119119
if collision[1] == true
120-
println("Collided with: ", colliders[i].getParent().name, " at ", colliders[i].getParent().transform.getPosition())
120+
println("Collided with: ", colliders[i].getParent().name, " at ", colliders[i].getParent().transform.position)
121121
push!(this.currentRests, colliders[i])
122122
for eventToCall in this.collisionEvents
123123
eventToCall()
124124
end
125125
#Begin to overlap, correct position
126-
transform.setPosition(Math.Vector2f(transform.getPosition().x, transform.getPosition().y - collision[2]))
126+
transform.setPosition(Math.Vector2f(transform.position.x, transform.position.y - collision[2]))
127127
this.isGrounded = true
128128
end
129129
# end
@@ -178,8 +178,8 @@ module CircleColliderModule
178178
# Closest point on collision box
179179
cX, cY = 0, 0
180180

181-
posA = a.getParent().transform.getPosition() + a.offset
182-
posB = b.getParent().transform.getPosition() + b.offset
181+
posA = a.getParent().transform.position + a.offset
182+
posB = b.getParent().transform.position + b.offset
183183

184184
# Find closest x offset
185185
if posA.x < posB.x
@@ -214,8 +214,8 @@ module CircleColliderModule
214214
# Closest point on collision box
215215
cX = 0
216216

217-
posA = a.getParent().transform.getPosition() + a.offset
218-
posB = b.getParent().transform.getPosition() + b.offset
217+
posA = a.getParent().transform.position + a.offset
218+
posB = b.getParent().transform.position + b.offset
219219
radius = a.diameter / 2
220220

221221
# Find closest x offset

src/Component/Collider.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ module ColliderModule
109109
onGround = this.parent.rigidbody.grounded
110110
colliderSkipCount = 0
111111
colliderCheckedCount = 0
112-
112+
i = 0
113113
for collider in colliders
114+
i += 1
114115
#TODO: Skip any out of a certain range of this. This will prevent a bunch of unnecessary collision checks
115116
if !collider.getParent().isActive || !collider.enabled
116117
if this.parent.rigidbody.grounded && i == length(colliders)
@@ -121,7 +122,7 @@ module ColliderModule
121122

122123
if this != collider
123124
# check if other collider is within range of this collider, if it isn't then skip it
124-
if collider.getParent().transform.getPosition().x > this.getParent().transform.getPosition().x + this.getSize().x || collider.getParent().transform.getPosition().x + collider.getSize().x < this.getParent().transform.getPosition().x && MAIN.optimizeSpriteRendering
125+
if collider.getParent().transform.position.x > this.getParent().transform.position.x + this.getSize().x || collider.getParent().transform.position.x + collider.getSize().x < this.getParent().transform.position.x && MAIN.optimizeSpriteRendering
125126
colliderSkipCount += 1
126127
continue
127128
end
@@ -131,7 +132,7 @@ module ColliderModule
131132
if CheckIfResting(this, collider)[1] == true && length(this.currentRests) > 0 && !(collider in this.currentRests)
132133
# if this collider isn't already in the list of current rests, check if it is on the same Y level and the same size as any of the current rests, if it is, then add it to current rests
133134
for j in eachindex(this.currentRests)
134-
if this.currentRests[j].getParent().transform.getPosition().y == collider.getParent().transform.getPosition().y && this.currentRests[j].getSize().y == collider.getSize().y
135+
if this.currentRests[j].getParent().transform.position.y == collider.getParent().transform.position.y && this.currentRests[j].getSize().y == collider.getSize().y
135136
push!(this.currentRests, collider)
136137
break
137138
end
@@ -145,23 +146,23 @@ module ColliderModule
145146
eventToCall(collider)
146147
end
147148
#Begin to overlap, correct position
148-
transform.setPosition(Math.Vector2f(transform.getPosition().x, transform.getPosition().y + collision[2]))
149+
transform.setPosition(Math.Vector2f(transform.position.x, transform.position.y + collision[2]))
149150
end
150151
if collision[1] == Left::CollisionDirection
151152
push!(this.currentCollisions, collider)
152153
for eventToCall in this.collisionEvents
153154
eventToCall(collider)
154155
end
155156
#Begin to overlap, correct position
156-
transform.setPosition(Math.Vector2f(transform.getPosition().x + collision[2], transform.getPosition().y))
157+
transform.setPosition(Math.Vector2f(transform.position.x + collision[2], transform.position.y))
157158
end
158159
if collision[1] == Right::CollisionDirection
159160
push!(this.currentCollisions, collider)
160161
for eventToCall in this.collisionEvents
161162
eventToCall(collider)
162163
end
163164
#Begin to overlap, correct position
164-
transform.setPosition(Math.Vector2f(transform.getPosition().x - collision[2], transform.getPosition().y))
165+
transform.setPosition(Math.Vector2f(transform.position.x - collision[2], transform.position.y))
165166
end
166167
if collision[1] == Bottom::CollisionDirection && this.parent.rigidbody.getVelocity().y >= 0
167168
push!(this.currentCollisions, collider)
@@ -178,7 +179,7 @@ module ColliderModule
178179
end
179180
end
180181
#Begin to overlap, correct position
181-
transform.setPosition(Math.Vector2f(transform.getPosition().x, transform.getPosition().y - collision[2]))
182+
transform.setPosition(Math.Vector2f(transform.position.x, transform.position.y - collision[2]))
182183
if !collider.isTrigger
183184
onGround = true
184185
end
@@ -224,8 +225,8 @@ module ColliderModule
224225
function CheckCollision(colliderA::InternalCollider, colliderB::InternalCollider)
225226
# nameA = colliderA.getParent().name
226227
# nameB = colliderB.getParent().name
227-
posA = colliderA.getParent().transform.getPosition() * SCALE_UNITS - ((colliderA.getParent().transform.getScale() * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderA.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
228-
posB = colliderB.getParent().transform.getPosition() * SCALE_UNITS - ((colliderB.getParent().transform.getScale() * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderB.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
228+
posA = colliderA.getParent().transform.position * SCALE_UNITS - ((colliderA.getParent().transform.scale * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderA.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
229+
posB = colliderB.getParent().transform.position * SCALE_UNITS - ((colliderB.getParent().transform.scale * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderB.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
229230
offsetAX = colliderA.offset.x * SCALE_UNITS
230231
offsetAY = colliderA.offset.y * SCALE_UNITS
231232
offsetBX = colliderB.offset.x * SCALE_UNITS
@@ -311,8 +312,8 @@ module ColliderModule
311312
return (false, 0.0)
312313
end
313314

314-
posA = colliderA.getParent().transform.getPosition() * SCALE_UNITS - ((colliderA.getParent().transform.getScale() * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderA.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
315-
posB = colliderB.getParent().transform.getPosition() * SCALE_UNITS - ((colliderB.getParent().transform.getScale() * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderB.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
315+
posA = colliderA.getParent().transform.position * SCALE_UNITS - ((colliderA.getParent().transform.scale * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderA.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
316+
posB = colliderB.getParent().transform.position * SCALE_UNITS - ((colliderB.getParent().transform.scale * SCALE_UNITS - SCALE_UNITS) / 2) - ((colliderB.getSize() * SCALE_UNITS - SCALE_UNITS) / 2)
316317
offsetAX = colliderA.offset.x * SCALE_UNITS
317318
offsetBX = colliderB.offset.x * SCALE_UNITS
318319
colliderAXSize = colliderA.getSize().x * SCALE_UNITS

src/Component/Rigidbody.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
function Component.update(this::InternalRigidbody, dt)
5555
velocityMultiplier = Math.Vector2f(1.0, 1.0)
5656
transform = this.parent.transform
57-
currentPosition = transform.getPosition()
57+
currentPosition = transform.position
5858

59-
newPosition = transform.getPosition() + this.velocity*dt + this.acceleration*(dt*dt*0.5)
59+
newPosition = transform.position + this.velocity*dt + this.acceleration*(dt*dt*0.5)
6060
if this.grounded
6161
newPosition = Math.Vector2f(newPosition.x, currentPosition.y)
6262
velocityMultiplier = Math.Vector2f(1.0, 0.0)

src/Component/Shape.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ module ShapeModule
5858
Math.Vector2(MAIN.scene.camera.position.x * SCALE_UNITS, MAIN.scene.camera.position.y * SCALE_UNITS) :
5959
Math.Vector2(0,0)
6060
position = this.isWorldEntity ?
61-
parentTransform.getPosition() :
61+
parentTransform.position :
6262
this.position
6363

64-
outlineRect = Ref(SDL2.SDL_FRect(convert(Int32,round((position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.getScale().x * SCALE_UNITS - SCALE_UNITS) / 2)),
65-
convert(Int32,round((position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.getScale().y * SCALE_UNITS - SCALE_UNITS) / 2)),
66-
convert(Int32,round(1 * parentTransform.getScale().x * SCALE_UNITS)),
67-
convert(Int32,round(1 * parentTransform.getScale().y * SCALE_UNITS))))
64+
outlineRect = Ref(SDL2.SDL_FRect(convert(Int32,round((position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.scale.x * SCALE_UNITS - SCALE_UNITS) / 2)),
65+
convert(Int32,round((position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.scale.y * SCALE_UNITS - SCALE_UNITS) / 2)),
66+
convert(Int32,round(1 * parentTransform.scale.x * SCALE_UNITS)),
67+
convert(Int32,round(1 * parentTransform.scale.y * SCALE_UNITS))))
6868
SDL2.SDL_SetRenderDrawColor(JulGame.Renderer, this.color.x, this.color.y, this.color.z, SDL2.SDL_ALPHA_OPAQUE );
6969

7070
this.isFilled ? SDL2.SDL_RenderFillRectF( JulGame.Renderer, outlineRect) : SDL2.SDL_RenderDrawRectF( JulGame.Renderer, outlineRect);

src/Component/Sprite.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module SpriteModule
3737
size::Math.Vector2
3838
texture::Union{Ptr{Nothing}, Ptr{SDL2.LibSDL2.SDL_Texture}}
3939

40-
function InternalSprite(parent::Any, imagePath::String, crop::Union{Ptr{Nothing}, Math.Vector4}=C_NULL, isFlipped::Bool=false, color::Math.Vector3 = Math.Vector3(255,255,255), isCreatedInEditor::Bool=false; pixelsPerUnit::Int32=Int32(-1), isWorldEntity::Bool=true, position::Math.Vector2f = Math.Vector2f(), rotation::Float64 = 0.0, layer::Int32 = Int32(0), center::Math.Vector2 = Math.Vector2(0,0))
40+
function InternalSprite(parent::Any, imagePath::String, crop::Union{Ptr{Nothing}, Math.Vector4}=C_NULL, isFlipped::Bool=false, color::Math.Vector3 = Math.Vector3(255,255,255), isCreatedInEditor::Bool=false; pixelsPerUnit::Int32=Int32(-1), isWorldEntity::Bool=true, position::Math.Vector2f = Math.Vector2f(0,0), rotation::Float64 = 0.0, layer::Int32 = Int32(0), center::Math.Vector2 = Math.Vector2(0,0))
4141
this = new()
4242

4343
this.offset = Math.Vector2f()
@@ -110,13 +110,13 @@ module SpriteModule
110110
Math.Vector2(MAIN.scene.camera.position.x * SCALE_UNITS, MAIN.scene.camera.position.y * SCALE_UNITS) :
111111
Math.Vector2(0,0)
112112
position = this.isWorldEntity ?
113-
parentTransform.getPosition() :
113+
parentTransform.position :
114114
this.position
115115

116116
srcRect = (this.crop == Math.Vector4(0,0,0,0) || this.crop == C_NULL) ? C_NULL : Ref(SDL2.SDL_Rect(this.crop.x, this.crop.y, this.crop.z, this.crop.t))
117117
dstRect = Ref(SDL2.SDL_FRect(
118-
(position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.getScale().x * SCALE_UNITS - SCALE_UNITS) / 2, # TODO: Center the sprite within the entity
119-
(position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.getScale().y * SCALE_UNITS - SCALE_UNITS) / 2,
118+
(position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.scale.x * SCALE_UNITS - SCALE_UNITS) / 2, # TODO: Center the sprite within the entity
119+
(position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.scale.y * SCALE_UNITS - SCALE_UNITS) / 2,
120120
(this.crop == C_NULL ? this.size.x : this.crop.z) * SCALE_UNITS,
121121
(this.crop == C_NULL ? this.size.y : this.crop.t) * SCALE_UNITS
122122
))
@@ -133,8 +133,8 @@ module SpriteModule
133133

134134
srcRect = !this.isFloatPrecision ? (this.crop == Math.Vector4(0,0,0,0) || this.crop == C_NULL) ? C_NULL : Ref(SDL2.SDL_Rect(this.crop.x,this.crop.y,this.crop.z,this.crop.t)) : srcRect
135135
dstRect = !this.isFloatPrecision ? Ref(SDL2.SDL_Rect(
136-
convert(Int32, round((position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.getScale().x * SCALE_UNITS - SCALE_UNITS) / 2)), # TODO: Center the sprite within the entity
137-
convert(Int32, round((position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.getScale().y * SCALE_UNITS - SCALE_UNITS) / 2)),
136+
convert(Int32, round((position.x + this.offset.x) * SCALE_UNITS - cameraDiff.x - (parentTransform.scale.x * SCALE_UNITS - SCALE_UNITS) / 2)), # TODO: Center the sprite within the entity
137+
convert(Int32, round((position.y + this.offset.y) * SCALE_UNITS - cameraDiff.y - (parentTransform.scale.y * SCALE_UNITS - SCALE_UNITS) / 2)),
138138
convert(Int32, round(this.crop == C_NULL ? this.size.x : this.crop.z)),
139139
convert(Int32, round(this.crop == C_NULL ? this.size.y : this.crop.t))
140140
)) : dstRect

src/Component/Transform.jl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,17 @@ module TransformModule
2020

2121
function Base.getproperty(this::Transform, s::Symbol)
2222
method_props = (
23-
getPosition = Component.get_position,
2423
setPosition = Component.set_position,
25-
getScale = Component.get_scale,
26-
setScale = Component.set_scale,
2724
update = Component.update,
2825
setVector2fValue = Component.set_vector2f_value
2926
)
3027
deprecated_get_property(method_props, this, s)
3128
end
3229

33-
34-
function Component.get_position(this::Transform)
35-
return this.position
36-
end
37-
3830
function Component.set_position(this::Transform, position::Math.Vector2f)
3931
this.position = position
4032
end
4133

42-
function Component.get_scale(this::Transform)
43-
return this.scale
44-
end
45-
46-
function Component.set_scale(this::Transform, scale::Math.Vector2f)
47-
this.scale = scale
48-
end
49-
5034
function Component.update(this::Transform)
5135
#println(this.position)
5236
end

0 commit comments

Comments
 (0)