From d62e3506f25a7eba7662c814ce83467124703323 Mon Sep 17 00:00:00 2001 From: Kyle Conel Date: Tue, 21 Nov 2023 19:25:44 -0500 Subject: [PATCH 1/3] Files added --- src/Particle/Dot.jl | 0 src/Particle/Particle.jl | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Particle/Dot.jl create mode 100644 src/Particle/Particle.jl diff --git a/src/Particle/Dot.jl b/src/Particle/Dot.jl new file mode 100644 index 00000000..e69de29b diff --git a/src/Particle/Particle.jl b/src/Particle/Particle.jl new file mode 100644 index 00000000..e69de29b From 2ac7bea95aab8ea7005053dba1522d10701eaf1d Mon Sep 17 00:00:00 2001 From: Kyle Conel Date: Wed, 29 Nov 2023 22:12:01 -0500 Subject: [PATCH 2/3] Cleanup and adding boilerplate for particle and dot --- src/Component/Collider.jl | 1 - src/Component/Rigidbody.jl | 1 - src/Component/Sprite.jl | 2 -- src/Particle/Dot.jl | 34 ++++++++++++++++++++++++++++++++++ src/Particle/Particle.jl | 31 +++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/Component/Collider.jl b/src/Component/Collider.jl index 06a49127..5958bf50 100644 --- a/src/Component/Collider.jl +++ b/src/Component/Collider.jl @@ -1,7 +1,6 @@ module ColliderModule include("../Enums.jl") using ..Component.JulGame -global const SCALE_UNITS = Ref{Float64}(64.0)[] global const GRAVITY = Ref{Float64}(9.81)[] export Collider diff --git a/src/Component/Rigidbody.jl b/src/Component/Rigidbody.jl index 118acb32..e76abff8 100644 --- a/src/Component/Rigidbody.jl +++ b/src/Component/Rigidbody.jl @@ -1,6 +1,5 @@ module RigidbodyModule using ..Component.JulGame -const SCALE_UNITS = Ref{Float64}(64.0)[] const GRAVITY = Ref{Float64}(9.81)[] export Rigidbody diff --git a/src/Component/Sprite.jl b/src/Component/Sprite.jl index 1bd01fb4..3d768f0b 100644 --- a/src/Component/Sprite.jl +++ b/src/Component/Sprite.jl @@ -1,8 +1,6 @@ module SpriteModule using ..Component.JulGame - const SCALE_UNITS = Ref{Float64}(64.0)[] - export Sprite mutable struct Sprite color::Math.Vector3 diff --git a/src/Particle/Dot.jl b/src/Particle/Dot.jl index e69de29b..a46f148f 100644 --- a/src/Particle/Dot.jl +++ b/src/Particle/Dot.jl @@ -0,0 +1,34 @@ +module DotModule + using ..JulGame + + export Dot + mutable struct Dot + dimensions::Math.Vector2f + offset::Math.Vector2f + maximumVelocity::Union{Ptr{Nothing}, Ptr{SDL2.LibSDL2.SDL_Texture}} + + function Dot() + this = new() + + return this + end + end + + function Base.getproperty(this::Dot, s::Symbol) + if s == :draw + function() + + end + elseif s == :draw + function() + + end + else + try + getfield(this, s) + catch e + println(e) + end + end + end +end \ No newline at end of file diff --git a/src/Particle/Particle.jl b/src/Particle/Particle.jl index e69de29b..9b2aa938 100644 --- a/src/Particle/Particle.jl +++ b/src/Particle/Particle.jl @@ -0,0 +1,31 @@ +module ParticleModule + using ..JulGame + + export Particle + mutable struct Particle + currentFrame::Integer + position::Math.Vector2f + texture::Union{Ptr{Nothing}, Ptr{SDL2.LibSDL2.SDL_Texture}} + + function Particle() + this = new() + + + return this + end + end + + function Base.getproperty(this::Particle, s::Symbol) + if s == :draw + function() + + end + else + try + getfield(this, s) + catch e + println(e) + end + end + end +end From 5def58542162d484ca41159b6cced21913f39f66 Mon Sep 17 00:00:00 2001 From: Kyle Conel Date: Wed, 13 Dec 2023 06:29:48 -0500 Subject: [PATCH 3/3] Progress on loading and rendering dot --- src/JulGame.jl | 11 +++++++++++ src/Main.jl | 6 ++++++ src/Particle/Dot.jl | 39 +++++++++++++++++++++++++++++++++------ src/Particle/Particle.jl | 34 +++++++++++++++++++++++++++++++--- src/Particle/blue.bmp | Bin 0 -> 134 bytes src/Particle/dot.bmp | Bin 0 -> 1254 bytes src/Particle/green.bmp | Bin 0 -> 134 bytes src/Particle/red.bmp | Bin 0 -> 134 bytes src/Particle/shimmer.bmp | Bin 0 -> 134 bytes 9 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/Particle/blue.bmp create mode 100644 src/Particle/dot.bmp create mode 100644 src/Particle/green.bmp create mode 100644 src/Particle/red.bmp create mode 100644 src/Particle/shimmer.bmp diff --git a/src/JulGame.jl b/src/JulGame.jl index d892ab7a..610bed9e 100644 --- a/src/JulGame.jl +++ b/src/JulGame.jl @@ -8,6 +8,9 @@ module JulGame BasePath = "" export BasePath + + Renderer = Ptr{SDL2.LibSDL2.SDL_Renderer}(C_NULL) + export Renderer include("Macros.jl") using .Macros: @event @@ -24,11 +27,19 @@ module JulGame include("UI/UI.jl") using .UI export ScreenButtonModule, TextBoxModule + + include("Particle/Particle.jl") + using .ParticleModule + export ParticleModule include("Main.jl") using .MainLoop: Main const MAIN = Main(Float64(1.0)) export MAIN + + include("Particle/Dot.jl") + using .DotModule + export DotModule include("Component/Component.jl") using .Component diff --git a/src/Main.jl b/src/Main.jl index eaa83c5f..dd571c28 100644 --- a/src/Main.jl +++ b/src/Main.jl @@ -39,6 +39,7 @@ module MainLoop window windowName::String zoom::Float64 + dot function Main(zoom::Float64) this = new() @@ -88,6 +89,9 @@ module MainLoop this.window = SDL2.SDL_CreateWindow(this.windowName, SDL2.SDL_WINDOWPOS_CENTERED, SDL2.SDL_WINDOWPOS_CENTERED, this.screenDimensions.x, this.screenDimensions.y, flags) this.renderer = SDL2.SDL_CreateRenderer(this.window, -1, SDL2.SDL_RENDERER_ACCELERATED) + JulGame.Renderer = this.renderer + + this.dot = DotModule.Dot() this.scene.camera.startingCoordinates = Math.Vector2f(round(dimensions.x/2) - round(this.scene.camera.dimensions.x/2*this.zoom), round(dimensions.y/2) - round(this.scene.camera.dimensions.y/2*this.zoom)) SDL2.SDL_RenderSetViewport(this.renderer, Ref(SDL2.SDL_Rect(this.scene.camera.startingCoordinates.x, this.scene.camera.startingCoordinates.y, round(this.scene.camera.dimensions.x*this.zoom), round(this.scene.camera.dimensions.y*this.zoom)))) @@ -467,6 +471,8 @@ module MainLoop for textBox in this.textBoxes textBox.render(DEBUG) end + + this.dot.draw() #endregion ============= UI SDL2.SDL_SetRenderDrawColor(this.renderer, 255, 0, 0, SDL2.SDL_ALPHA_OPAQUE) diff --git a/src/Particle/Dot.jl b/src/Particle/Dot.jl index a46f148f..65364766 100644 --- a/src/Particle/Dot.jl +++ b/src/Particle/Dot.jl @@ -3,13 +3,23 @@ module DotModule export Dot mutable struct Dot - dimensions::Math.Vector2f - offset::Math.Vector2f - maximumVelocity::Union{Ptr{Nothing}, Ptr{SDL2.LibSDL2.SDL_Texture}} + dimensions::Math.Vector2 + offset::Math.Vector2 + maximumVelocity::Integer + particles::Array{Any} + texture::Ptr{SDL2.LibSDL2.SDL_Texture} + velocity::Math.Vector2 function Dot() this = new() - + + this.particles = [] + for i in 1:10 + push!(this.particles, ParticleModule.Particle(Math.Vector2(0, 0), "red.bmp")) + end + fullPath = joinpath(@__DIR__, "dot.bmp") + this.texture = SDL2.SDL_CreateTextureFromSurface(MAIN.renderer, SDL2.IMG_Load(fullPath)) + return this end end @@ -17,12 +27,29 @@ module DotModule function Base.getproperty(this::Dot, s::Symbol) if s == :draw function() - + SDL2.SDL_SetTextureAlphaMod(this.texture, 255) + SDL2.SDL_RenderCopy(Renderer, this.texture, C_NULL, Ref(SDL2.SDL_Rect(0, 0, 10, 10))) end - elseif s == :draw + elseif s == :move function() end + elseif s == :drawParticles + function() + # Go through particles + for i in 1:10 + # Delete and replace dead particles + if particles[i].isDead() + delete!(particles, i) + #particles[i] = Particle(mPosX, mPosY) + end + end + + # Show particles + for i in 1:10 + this.draw(particles[i]) + end + end else try getfield(this, s) diff --git a/src/Particle/Particle.jl b/src/Particle/Particle.jl index 9b2aa938..48f85998 100644 --- a/src/Particle/Particle.jl +++ b/src/Particle/Particle.jl @@ -4,12 +4,29 @@ module ParticleModule export Particle mutable struct Particle currentFrame::Integer - position::Math.Vector2f - texture::Union{Ptr{Nothing}, Ptr{SDL2.LibSDL2.SDL_Texture}} + offset::Math.Vector2 + position::Math.Vector2 + texture::Ptr{SDL2.LibSDL2.SDL_Texture} + renderer::Ptr{SDL2.LibSDL2.SDL_Renderer} - function Particle() + function Particle(position::Math.Vector2, image::String) this = new() + this.currentFrame = rand(1:5) + this.offset = Math.Vector2(position.x - 5 + ( rand() % 25 ), position.y - 5 + ( rand() % 25 )) + + fullPath = joinpath(@__DIR__, image) + + this.texture = SDL2.SDL_CreateTextureFromSurface(this.renderer, SDL2.IMG_Load(fullPath)) + + # Set type + # if rand() % 3 == 0 + # mTexture = gRedTexture + # elseif rand() % 3 == 1 + # mTexture = gGreenTexture + # else + # mTexture = gBlueTexture + # end return this end @@ -18,7 +35,18 @@ module ParticleModule function Base.getproperty(this::Particle, s::Symbol) if s == :draw function() + if this.isDead() + return + end + SDL2.SDL_SetTextureAlphaMod(this.texture, 255) + SDL2.SDL_RenderCopy(MAIN.renderer, this.texture, C_NULL, SDL2.SDL_Rect(this.offset.x, this.offset.y, 10, 10)) + + #this.currentFrame += 1 + end + elseif s == :isDead + function() + return this.currentFrame > 10 end else try diff --git a/src/Particle/blue.bmp b/src/Particle/blue.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6c9c7a79dbaedd493d01227244c4729f3c8b1adb GIT binary patch literal 134 zcmZ?rZDW7{Ga#h_#H>)v$RGih2mq6)#Q*;cK-9nhB7q1@F@X7CHi!k11d~7phCI4{ E07Sn9CW)Z2Dnk=QsK&-ZQw--~ zQ;S^;t_8xtt_Zg%vUc36u*<;pVwWZ)N}huurULbj0{Vmi*+ETV{F0{~qKk69Kof`u T$d)3r@tc6G5*HiO1gt6nQEjWq literal 0 HcmV?d00001 diff --git a/src/Particle/green.bmp b/src/Particle/green.bmp new file mode 100644 index 0000000000000000000000000000000000000000..799062bc8452bae09e2fef193e2afcbb414cee61 GIT binary patch literal 134 zcmZ?rZDW7{Ga#h_#H>)v$RGih2mq6)#Q*;cK*Z1hB0&r=2Jsmnd=LxFfiXa8kmRA- G;Q9eO%p%GF literal 0 HcmV?d00001 diff --git a/src/Particle/red.bmp b/src/Particle/red.bmp new file mode 100644 index 0000000000000000000000000000000000000000..93f20b363583a44a8944ee44edf53100ad597898 GIT binary patch literal 134 zcmZ?rZDW7{Ga#h_#H>)v$RGih2mq6)#Q*;cK*Ye%0A+wVK!FAZpg2eZ!~$`k40L&@ HHn@HOGSMQ+ literal 0 HcmV?d00001 diff --git a/src/Particle/shimmer.bmp b/src/Particle/shimmer.bmp new file mode 100644 index 0000000000000000000000000000000000000000..17ba2b48a9322420470cf7eaf8750b7ea0acae97 GIT binary patch literal 134 zcmZ?rZDW7{Ga#h_#H>)v$RGih2mq6)#Q*;cVDultfOCL+kPwiM0