Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Aug 6, 2024
2 parents e11d438 + 50f0728 commit eb465db
Show file tree
Hide file tree
Showing 86 changed files with 4,825 additions and 3,671 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ src/editor/EditorBuild/
test/projects/ProfilingTest/Platformer/.vscode/settings.json

.vscode/settings.json

playground.jl
15 changes: 6 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
name = "JulGame"
uuid = "4850f9bb-d191-4a1e-9f97-ee64062927c3"
authors = ["Kyjor <kyjordev@gmail.com>"]
repo = "https://github.com/Kyjor/JulGame.jl.git"
version = "0.1.0"

[deps]
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
ImGuiGLFWBackend = "623d79b3-9695-4e60-bd7e-2a5aabaa6933"
ImGuiOpenGLBackend = "9d0819b4-44e7-43a2-ad03-8fb999128168"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
SimpleDirectMediaLayer = "98e33af6-2ee5-5afd-9e75-cbc738b767c4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
NativeFileDialog = "e1fe445b-aa65-4df4-81c1-2041507f0fd4"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

[compat]
CImGui = "~1.89"
ImGuiGLFWBackend = "0.2"
ImGuiOpenGLBackend = "0.2"
JSON3 = "1"
SimpleDirectMediaLayer = "0.3, 0.4"
SimpleDirectMediaLayer = "0.5"
CImGui = "~2.0"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
6 changes: 3 additions & 3 deletions docs/.astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ declare module 'astro:content' {
collection: "docs";
data: InferEntrySchema<"docs">
} & { render(): Render[".md"] };
"reference/Shape/properties/dimensions.md": {
id: "reference/Shape/properties/dimensions.md";
slug: "reference/shape/properties/dimensions";
"reference/Shape/properties/size.md": {
id: "reference/Shape/properties/size.md";
slug: "reference/shape/properties/size";
body: string;
collection: "docs";
data: InferEntrySchema<"docs">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Shape.dimensions
description: An xy value for the dimensions of the shape (only square right now).
title: Shape.size
description: An xy value for the size of the shape (only square right now).
---

An xy value for the dimensions of the shape (only square right now).
An xy value for the size of the shape (only square right now).

Example:
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/Shape/shape.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar:
| Property | Description |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [color](/JulGame.jl/reference/shape/properties/color/) | An rgb value for the color of the given shape. |
| [dimensions](/JulGame.jl/reference/shape/properties/dimensions/) | An xy value for the dimensions of the shape (only square right now). |
| [size](/JulGame.jl/reference/shape/properties/size/) | An xy value for the size of the shape (only square right now). |
| [isFilled](/JulGame.jl/reference/shape/properties/isFilled/) | A flag that determines whether or not the shape is filled or not. |
| [offset](/JulGame.jl/reference/shape/properties/offset/) | An xy value for the difference in position between the shape and its parent transform. |
| [parent](/JulGame.jl/reference/shape/properties/parent/) | The parent entity of the shape. |
Expand Down
Binary file removed examples/.DS_Store
Binary file not shown.
58 changes: 0 additions & 58 deletions src/Camera.jl

This file was deleted.

53 changes: 53 additions & 0 deletions src/Camera/Camera.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module CameraModule
using JulGame
using .Math

export Camera
mutable struct Camera
size::Vector2
offset::Vector2f
position::Vector2f
startingCoordinates::Vector2f

target::Union{
Ptr{Nothing},
JulGame.TransformModule.Transform
}
windowPos::Vector2

function Camera(size::Vector2, initialPosition::Vector2f, offset::Vector2f, target)
this = new()

this.size = size
this.position = initialPosition
this.offset = Vector2f(offset.x, offset.y)
this.target = target
this.startingCoordinates = Vector2f()
this.windowPos = Vector2(0,0)

return this
end
end

function update(this::Camera, newPosition)
SDL2.SDL_SetRenderDrawColor(Renderer, MAIN.cameraBackgroundColor[1], MAIN.cameraBackgroundColor[2], MAIN.cameraBackgroundColor[3], SDL2.SDL_ALPHA_OPAQUE);
SDL2.SDL_RenderFillRectF(Renderer, Ref(SDL2.SDL_FRect(this.windowPos.x, this.windowPos.y, this.size.x, this.size.y)))

if this.target != C_NULL && newPosition == C_NULL
targetPos = this.target.position
center = Vector2f(this.size.x/SCALE_UNITS/2, this.size.y/SCALE_UNITS/2)
targetScale = this.target.scale
this.position = targetPos - center + 0.5 * targetScale + this.offset
return
end
if newPosition == C_NULL
return
end
this.position = newPosition
end

function set_target(this::Camera, target)
this.target = target
end

end
52 changes: 52 additions & 0 deletions src/CommonFunctions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function add_animator end
function add_circle_collider end
function add_click_event end
function add_collider end
function add_collision_event end
function add_rigidbody end
function add_script end
function add_shape end
function add_sound_source end
function add_sprite end
function append_array end
function apply_forces end
function center_text end
function check_collisions end
function create_sound_source end
function destroy end
function draw end
function flip end
function get_last_update end
function get_offset end
function get_parent end
function get_position end
function get_rotation end
function get_scale end
function get_size end
function get_tag end
function get_type end
function get_velocity end
function handle_event end
function initialize end
function load_button_sprite_editor end
function load_font end
function load_image end
function load_sound end
function render end
function set_color end
function set_last_update end
function set_offset end
function set_parent end
function set_position end
function set_rotation end
function set_scale end
function set_size end
function set_sprite end
function set_tag end
function stop_music end
function toggle_sound end
function unload_sound end
function update end
function update_array_value end
function update_font_size end
function update_text end
41 changes: 15 additions & 26 deletions src/Component/Animation.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module AnimationModule
using ..Component.JulGame

import ..Component
export Animation
mutable struct Animation
animatedFPS::Int32
Expand All @@ -16,30 +16,19 @@ module AnimationModule
end
end

function Base.getproperty(this::Animation, s::Symbol)
if s == :updateArrayValue
function(value, field, index::Int32)
fieldToUpdate = getfield(this, field)
if this.getType(value) == "_Vector4"
fieldToUpdate[index] = Math.Vector4(value.x, value.y, value.z, value.t)
end
end
elseif s == :appendArray
function()
push!(this.frames, Math.Vector4(0,0,0,0))
end
elseif s == :getType
function(item)
componentFieldType = "$(typeof(item).name.wrapper)"
return String(split(componentFieldType, '.')[length(split(componentFieldType, '.'))])
end
else
try
getfield(this, s)
catch e
println(e)
Base.show_backtrace(stdout, catch_backtrace())
end
function Component.update_array_value(this::Animation, value, field, index::Int32)
fieldToUpdate = getfield(this, field)
if get_type(this, value) == "_Vector4"
fieldToUpdate[index] = Math.Vector4(value.x, value.y, value.z, value.t)
end
end
end

function Component.append_array(this::Animation)
push!(this.frames, Math.Vector4(0,0,0,0))
end

function Component.get_type(this::Animation, item)
componentFieldType = "$(typeof(item).name.wrapper)"
return String(split(componentFieldType, '.')[length(split(componentFieldType, '.'))])
end
end
63 changes: 26 additions & 37 deletions src/Component/Animator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ..Component.JulGame
using ..Component.JulGame.Math
using ..Component.SpriteModule

import ..Component
export Animator
struct Animator
animations::Vector{Animation}
Expand Down Expand Up @@ -32,41 +32,30 @@
end
end

function Base.getproperty(this::InternalAnimator, s::Symbol)
if s == :getLastUpdate
function()
return this.lastUpdate
end
elseif s == :setLastUpdate
function(value)
this.lastUpdate = value
end
elseif s == :update
function(currentRenderTime, deltaTime)
Update(this, currentRenderTime, deltaTime)
end
elseif s == :setSprite
function(sprite)
this.sprite = sprite
end
elseif s == :setParent
function(parent)
this.parent = parent
end
elseif s == :appendArray
function()
push!(this.animations, Animation([Math.Vector4(0,0,0,0)], Int32(60)))
end
else
try
getfield(this, s)
catch e
println(e)
Base.show_backtrace(stdout, catch_backtrace())
end
end
function Component.get_last_update(this::InternalAnimator)
return this.lastUpdate
end

function Component.set_last_update(this::InternalAnimator, value)
this.lastUpdate = value
end

function Component.update(this::InternalAnimator, currentRenderTime, deltaTime)
Update(this, currentRenderTime, deltaTime)
end

function Component.set_sprite(this::InternalAnimator, sprite)
this.sprite = sprite
end

function Component.set_parent(this::InternalAnimator, parent)
this.parent = parent
end

function Component.append_array(this::InternalAnimator)
push!(this.animations, Animation([Math.Vector4(0,0,0,0)], Int32(60)))
end


"""
ForceFrameUpdate(this::InternalAnimator, frameIndex::Int32)
Expand Down Expand Up @@ -108,13 +97,13 @@
if this.currentAnimation.animatedFPS < 1
return
end
deltaTime = (currentRenderTime - this.getLastUpdate()) / 1000.0
deltaTime = (currentRenderTime - Component.get_last_update(this)) / 1000.0
framesToUpdate = floor(deltaTime / (1.0 / this.currentAnimation.animatedFPS))
if framesToUpdate > 0
this.lastFrame = this.lastFrame + framesToUpdate
this.setLastUpdate(currentRenderTime)
Component.set_last_update(this, currentRenderTime)
end
this.sprite.crop = this.currentAnimation.frames[this.lastFrame > length(this.currentAnimation.frames) ? (1; this.lastFrame = 1) : this.lastFrame]
end

end
end
Loading

0 comments on commit eb465db

Please sign in to comment.