Add dialouge boxes/tooltips (#10)
- [x] Update objects so they know when the mouse is on them - [x] Remove testing code - [x] Add into the producers - [x] Add into the consumer - [x] Standardize fonts --------- Co-authored-by: leah <leah@hintonclan.org> Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
+23
-2
@@ -1,9 +1,17 @@
|
||||
## Nathan Hinton
|
||||
## A number consumer that will create numbers when an extractor is placed on it.
|
||||
|
||||
require './dialouge_box.rb'
|
||||
|
||||
CONSUMER_DEBUG = false
|
||||
BORDER = 2
|
||||
SIZE = 3
|
||||
HOVER_TIME = 500 # ms
|
||||
|
||||
# This actually should be stored somewhere else. This is the goals/quests for the game
|
||||
TASKS = [
|
||||
"Collect 10 1's"
|
||||
]
|
||||
|
||||
class Consumer
|
||||
attr_reader :draw_x, :draw_y
|
||||
@@ -19,6 +27,9 @@ class Consumer
|
||||
@image = Gosu.render((SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER)) {
|
||||
Gosu.draw_rect(0, 0, (SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER), Gosu::Color::GREEN, 0)
|
||||
}
|
||||
@task_index = 0
|
||||
@tooltip_timer = 0
|
||||
@tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, TASKS[@task_index])
|
||||
end
|
||||
|
||||
# Consumes numbers created
|
||||
@@ -26,11 +37,20 @@ class Consumer
|
||||
# @param camera_x [Integer] The camera X position
|
||||
# @param camera_y [Integer] The camera Y position
|
||||
# @param camera_zoom [Float] The camera zoom
|
||||
def update(delta_mult, camera_x, camera_y, camera_zoom)
|
||||
def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y)
|
||||
@draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom)
|
||||
@draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom)
|
||||
@camera_zoom = camera_zoom
|
||||
|
||||
if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (SIZE * @box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (SIZE * @box_size * @camera_zoom)
|
||||
@tooltip_timer += 60.0 * delta_mult
|
||||
if @tooltip_timer > HOVER_TIME
|
||||
@tooltip.show = true
|
||||
@tooltip.update(@draw_x, @draw_y, @camera_zoom)
|
||||
end
|
||||
else
|
||||
@tooltip_timer = 0
|
||||
@tooltip.show = false
|
||||
end
|
||||
end
|
||||
|
||||
# Draw the consumer. Uses the camera x and y to shift where it should draw
|
||||
@@ -39,5 +59,6 @@ class Consumer
|
||||
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
|
||||
end
|
||||
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
|
||||
@tooltip.draw()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user