mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 14:52:35 +00:00
Added GAME_ROOT_PATH and ASSETS_PATH constants, make boot and closing use ASSETS_PATH, simplified Camera#mouse_pick and Camera#center
This commit is contained in:
@@ -18,4 +18,4 @@ require_relative "lib/zorder"
|
|||||||
require_relative "lib/entity"
|
require_relative "lib/entity"
|
||||||
# require_relative "lib/entities/"
|
# require_relative "lib/entities/"
|
||||||
|
|
||||||
IMICRTS::Window.new(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true).show
|
IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show
|
||||||
@@ -37,25 +37,20 @@ class IMICRTS
|
|||||||
def mouse_pick(x, y)
|
def mouse_pick(x, y)
|
||||||
mouse = CyberarmEngine::Vector.new(x, y) / @zoom
|
mouse = CyberarmEngine::Vector.new(x, y) / @zoom
|
||||||
|
|
||||||
normalized = (mouse / @zoom - @position / @zoom) * @zoom
|
worldspace = (mouse - @position)
|
||||||
normalized.x = normalized.x.floor
|
worldspace.x = worldspace.x.floor
|
||||||
normalized.y = normalized.y.floor
|
worldspace.y = worldspace.y.floor
|
||||||
|
|
||||||
return normalized
|
return worldspace
|
||||||
end
|
end
|
||||||
|
|
||||||
def center
|
def center
|
||||||
(CyberarmEngine::Vector.new(window.width / 2, window.height / 2) / @zoom - @position / @zoom) * @zoom
|
(CyberarmEngine::Vector.new(window.width / 2, window.height / 2) - @position)
|
||||||
end
|
end
|
||||||
|
|
||||||
def center_around(vector, factor)
|
def center_around(vector, factor)
|
||||||
@velocity *= 0
|
@velocity *= 0
|
||||||
delta = lerp(self.center, vector, factor)
|
@position += center.lerp(vector, factor) * window.dt
|
||||||
@position += delta * window.dt
|
|
||||||
end
|
|
||||||
|
|
||||||
def lerp(vec1, vec2, factor)
|
|
||||||
(vec1 - vec2) * factor.clamp(0.0, 1.0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspect_ratio
|
def aspect_ratio
|
||||||
@@ -70,7 +65,7 @@ class IMICRTS
|
|||||||
|
|
||||||
if @drag_start
|
if @drag_start
|
||||||
@velocity *= 0.0
|
@velocity *= 0.0
|
||||||
@position = lerp(@position, CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @drag_start, @grab_drag)
|
@position = @position.lerp(@drag_start - CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y), @grab_drag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -84,15 +79,13 @@ class IMICRTS
|
|||||||
when Gosu::MS_WHEEL_DOWN
|
when Gosu::MS_WHEEL_DOWN
|
||||||
@zoom = (@zoom - 0.25).clamp(@min_zoom, @max_zoom)
|
@zoom = (@zoom - 0.25).clamp(@min_zoom, @max_zoom)
|
||||||
when Gosu::MS_MIDDLE
|
when Gosu::MS_MIDDLE
|
||||||
@position_start = @position.clone
|
@drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @position
|
||||||
@drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
case id
|
case id
|
||||||
when Gosu::MS_MIDDLE
|
when Gosu::MS_MIDDLE
|
||||||
@position_start = nil
|
|
||||||
@drag_start = nil
|
@drag_start = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class IMICRTS
|
|||||||
@title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true)
|
@title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true)
|
||||||
@text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true)
|
@text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true)
|
||||||
@name = IMICRTS::NAME
|
@name = IMICRTS::NAME
|
||||||
@logo = Gosu::Image.new("assets/logo.png")
|
@logo = Gosu::Image.new("#{ASSETS_PATH}/logo.png")
|
||||||
|
|
||||||
@messages = ["Loading", "Compiling Protons", "Launching Warhead", "git push origin --force"]
|
@messages = ["Loading", "Compiling Protons", "Launching Warhead", "git push origin --force"]
|
||||||
@messages_index = 0
|
@messages_index = 0
|
||||||
@@ -30,39 +30,35 @@ class IMICRTS
|
|||||||
|
|
||||||
@background = Gosu::Color.new(0x007a0d71)
|
@background = Gosu::Color.new(0x007a0d71)
|
||||||
@background_two = Gosu::Color.new(0x007b6ead)
|
@background_two = Gosu::Color.new(0x007b6ead)
|
||||||
|
|
||||||
$window.width = Gosu.screen_width
|
|
||||||
$window.height = Gosu.screen_height
|
|
||||||
$window.fullscreen = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
Gosu.draw_quad(
|
Gosu.draw_quad(
|
||||||
0, 0, @background_two,
|
0, 0, @background_two,
|
||||||
$window.width, 0, @background,
|
window.width, 0, @background,
|
||||||
0, $window.height, @background,
|
0, window.height, @background,
|
||||||
$window.width, $window.height, @background_two
|
window.width, window.height, @background_two
|
||||||
)
|
)
|
||||||
|
|
||||||
Gosu.draw_rect(
|
Gosu.draw_rect(
|
||||||
0, $window.height/2 - 35,
|
0, window.height/2 - 35,
|
||||||
$window.width, 71,
|
window.width, 71,
|
||||||
Gosu::Color.new(0xff949dad)
|
Gosu::Color.new(0xff949dad)
|
||||||
)
|
)
|
||||||
|
|
||||||
c = Gosu::Color.new(0xff55dae1)
|
c = Gosu::Color.new(0xff55dae1)
|
||||||
c2 = Gosu::Color.new(0xff3c9ec5)
|
c2 = Gosu::Color.new(0xff3c9ec5)
|
||||||
Gosu.draw_quad(
|
Gosu.draw_quad(
|
||||||
0, $window.height/2 - 30, c,
|
0, window.height/2 - 30, c,
|
||||||
$window.width, $window.height/2 - 30, c2,
|
window.width, window.height/2 - 30, c2,
|
||||||
0, $window.height/2 + 30, c,
|
0, window.height/2 + 30, c,
|
||||||
$window.width, $window.height/2 + 30, c2
|
window.width, window.height/2 + 30, c2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@logo.draw($window.width/2 - @logo.width/2, $window.height/2 - (@logo.height/3 + 14), 0)
|
@logo.draw(window.width/2 - @logo.width/2, window.height/2 - (@logo.height/3 + 14), 0)
|
||||||
|
|
||||||
@text.draw_text(@status, $window.width - (@text.text_width(@status.gsub(".", "")) + @text.text_width("...")), $window.height - @text.height, 0)
|
@text.draw_text(@status, window.width - (@text.text_width(@status.gsub(".", "")) + @text.text_width("...")), window.height - @text.height, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Closing < CyberarmEngine::GuiState
|
class Closing < CyberarmEngine::GuiState
|
||||||
def setup
|
def setup
|
||||||
@logo = Gosu::Image.new("assets/logo.png")
|
@logo = Gosu::Image.new("#{ASSETS_PATH}/logo.png")
|
||||||
@color = Gosu::Color.new(0xffffffff)
|
@color = Gosu::Color.new(0xffffffff)
|
||||||
|
|
||||||
@started_at = Gosu.milliseconds
|
@started_at = Gosu.milliseconds
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ class IMICRTS
|
|||||||
|
|
||||||
@h = button("Harvester", width: 1.0) do
|
@h = button("Harvester", width: 1.0) do
|
||||||
@units << Entity.new(
|
@units << Entity.new(
|
||||||
images: Gosu::Image.new("assets/vehicles/harvester/images/harvester.png", retro: true),
|
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/harvester/images/harvester.png", retro: true),
|
||||||
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
||||||
angle: rand(360)
|
angle: rand(360)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@c = button("Construction Worker", width: 1.0) do
|
@c = button("Construction Worker", width: 1.0) do
|
||||||
@units << Entity.new(
|
@units << Entity.new(
|
||||||
images: Gosu::Image.new("assets/vehicles/construction_worker/images/construction_worker.png", retro: true),
|
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/construction_worker/images/construction_worker.png", retro: true),
|
||||||
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
||||||
angle: rand(360)
|
angle: rand(360)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,4 +2,7 @@ class IMICRTS
|
|||||||
NAME = "I-MIC RTS"
|
NAME = "I-MIC RTS"
|
||||||
VERSION = "0.0.1"
|
VERSION = "0.0.1"
|
||||||
VERSION_NAME = "InDev"
|
VERSION_NAME = "InDev"
|
||||||
|
|
||||||
|
GAME_ROOT_PATH = File.expand_path("../../", __FILE__)
|
||||||
|
ASSETS_PATH = "#{GAME_ROOT_PATH}/assets"
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user