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:
2019-10-01 12:44:47 -05:00
parent a3a2e2a2ac
commit b945255849
6 changed files with 27 additions and 35 deletions

View File

@@ -18,4 +18,4 @@ require_relative "lib/zorder"
require_relative "lib/entity"
# 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

View File

@@ -37,25 +37,20 @@ class IMICRTS
def mouse_pick(x, y)
mouse = CyberarmEngine::Vector.new(x, y) / @zoom
normalized = (mouse / @zoom - @position / @zoom) * @zoom
normalized.x = normalized.x.floor
normalized.y = normalized.y.floor
worldspace = (mouse - @position)
worldspace.x = worldspace.x.floor
worldspace.y = worldspace.y.floor
return normalized
return worldspace
end
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
def center_around(vector, factor)
@velocity *= 0
delta = lerp(self.center, vector, factor)
@position += delta * window.dt
end
def lerp(vec1, vec2, factor)
(vec1 - vec2) * factor.clamp(0.0, 1.0)
@position += center.lerp(vector, factor) * window.dt
end
def aspect_ratio
@@ -70,7 +65,7 @@ class IMICRTS
if @drag_start
@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
@@ -84,15 +79,13 @@ class IMICRTS
when Gosu::MS_WHEEL_DOWN
@zoom = (@zoom - 0.25).clamp(@min_zoom, @max_zoom)
when Gosu::MS_MIDDLE
@position_start = @position.clone
@drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y)
@drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @position
end
end
def button_up(id)
case id
when Gosu::MS_MIDDLE
@position_start = nil
@drag_start = nil
end
end

View File

@@ -4,7 +4,7 @@ class IMICRTS
@title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true)
@text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true)
@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_index = 0
@@ -30,39 +30,35 @@ class IMICRTS
@background = Gosu::Color.new(0x007a0d71)
@background_two = Gosu::Color.new(0x007b6ead)
$window.width = Gosu.screen_width
$window.height = Gosu.screen_height
$window.fullscreen = true
end
def draw
Gosu.draw_quad(
0, 0, @background_two,
$window.width, 0, @background,
0, $window.height, @background,
$window.width, $window.height, @background_two
window.width, 0, @background,
0, window.height, @background,
window.width, window.height, @background_two
)
Gosu.draw_rect(
0, $window.height/2 - 35,
$window.width, 71,
0, window.height/2 - 35,
window.width, 71,
Gosu::Color.new(0xff949dad)
)
c = Gosu::Color.new(0xff55dae1)
c2 = Gosu::Color.new(0xff3c9ec5)
Gosu.draw_quad(
0, $window.height/2 - 30, c,
$window.width, $window.height/2 - 30, c2,
0, $window.height/2 + 30, c,
$window.width, $window.height/2 + 30, c2
0, window.height/2 - 30, c,
window.width, window.height/2 - 30, c2,
0, window.height/2 + 30, c,
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
def update

View File

@@ -1,7 +1,7 @@
class IMICRTS
class Closing < CyberarmEngine::GuiState
def setup
@logo = Gosu::Image.new("assets/logo.png")
@logo = Gosu::Image.new("#{ASSETS_PATH}/logo.png")
@color = Gosu::Color.new(0xffffffff)
@started_at = Gosu.milliseconds

View File

@@ -12,14 +12,14 @@ class IMICRTS
@h = button("Harvester", width: 1.0) do
@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),
angle: rand(360)
)
end
@c = button("Construction Worker", width: 1.0) do
@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),
angle: rand(360)
)

View File

@@ -2,4 +2,7 @@ class IMICRTS
NAME = "I-MIC RTS"
VERSION = "0.0.1"
VERSION_NAME = "InDev"
GAME_ROOT_PATH = File.expand_path("../../", __FILE__)
ASSETS_PATH = "#{GAME_ROOT_PATH}/assets"
end