forked from bionickatana/number_factory
Compare commits
4 Commits
52f3ad0d48
...
aa10e033fc
| Author | SHA1 | Date | |
|---|---|---|---|
| aa10e033fc | |||
| 3d8ce73b20 | |||
| 96fa6d3c62 | |||
| 8bf6b14446 |
+23
-2
@@ -1,9 +1,17 @@
|
|||||||
## Nathan Hinton
|
## Nathan Hinton
|
||||||
## A number consumer that will create numbers when an extractor is placed on it.
|
## A number consumer that will create numbers when an extractor is placed on it.
|
||||||
|
|
||||||
|
require './dialouge_box.rb'
|
||||||
|
|
||||||
CONSUMER_DEBUG = false
|
CONSUMER_DEBUG = false
|
||||||
BORDER = 2
|
BORDER = 2
|
||||||
SIZE = 3
|
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
|
class Consumer
|
||||||
attr_reader :draw_x, :draw_y
|
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)) {
|
@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)
|
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
|
end
|
||||||
|
|
||||||
# Consumes numbers created
|
# Consumes numbers created
|
||||||
@@ -26,11 +37,20 @@ class Consumer
|
|||||||
# @param camera_x [Integer] The camera X position
|
# @param camera_x [Integer] The camera X position
|
||||||
# @param camera_y [Integer] The camera Y position
|
# @param camera_y [Integer] The camera Y position
|
||||||
# @param camera_zoom [Float] The camera zoom
|
# @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_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)
|
@draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom)
|
||||||
@camera_zoom = 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
|
end
|
||||||
|
|
||||||
# Draw the consumer. Uses the camera x and y to shift where it should draw
|
# 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}"
|
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
|
||||||
end
|
end
|
||||||
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
|
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
|
||||||
|
@tooltip.draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class DialougeBox
|
|||||||
|
|
||||||
def draw()
|
def draw()
|
||||||
if @show
|
if @show
|
||||||
puts "Drawing tooltip at #{@x}, #{@y}"
|
|
||||||
@image.draw(@x, @y, 0, @camera_zoom, @camera_zoom)
|
@image.draw(@x, @y, 0, @camera_zoom, @camera_zoom)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class NumFactory < Gosu::Window
|
|||||||
end
|
end
|
||||||
|
|
||||||
@consumers.each do |consumer|
|
@consumers.each do |consumer|
|
||||||
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom)
|
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y)
|
||||||
end
|
end
|
||||||
@dialouges.each do |dialouge|
|
@dialouges.each do |dialouge|
|
||||||
dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}")
|
dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}")
|
||||||
@@ -244,7 +244,7 @@ class NumFactory < Gosu::Window
|
|||||||
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20, font: FONT_PATH).draw(1600, 100, 1)
|
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20, font: FONT_PATH).draw(1600, 100, 1)
|
||||||
Gosu::Image.from_text("Tick time: #{((Time.now() - @tick_time).to_f * 1000).to_i}", 20, font: FONT_PATH).draw(1600, 25, 1)
|
Gosu::Image.from_text("Tick time: #{((Time.now() - @tick_time).to_f * 1000).to_i}", 20, font: FONT_PATH).draw(1600, 25, 1)
|
||||||
Gosu::Image.from_text("FPS: #{Gosu.fps}", 20, font: FONT_PATH).draw(1600, 50, 1)
|
Gosu::Image.from_text("FPS: #{Gosu.fps}", 20, font: FONT_PATH).draw(1600, 50, 1)
|
||||||
Gosu::Image.from_text("items on screen: #{onscreen_items}", 20).draw(1600, 75, 1)
|
Gosu::Image.from_text("items on screen: #{onscreen_items}", 20, font: FONT_PATH).draw(1600, 75, 1)
|
||||||
Gosu::Image.from_text("Camera boxes: #{@camera_boxes}", 20, font: FONT_PATH).draw(1600, 175, 1)
|
Gosu::Image.from_text("Camera boxes: #{@camera_boxes}", 20, font: FONT_PATH).draw(1600, 175, 1)
|
||||||
Gosu::Image.from_text("Camera location: #{@camera_x}, #{@camera_y}", 20, font: FONT_PATH).draw(1600, 200, 1)
|
Gosu::Image.from_text("Camera location: #{@camera_x}, #{@camera_y}", 20, font: FONT_PATH).draw(1600, 200, 1)
|
||||||
Gosu::Image.from_text("Camera zoom: #{@camera_zoom}, #{@camera_x_zoom_offset}", 20, font: FONT_PATH).draw(1600, 225, 1)
|
Gosu::Image.from_text("Camera zoom: #{@camera_zoom}, #{@camera_x_zoom_offset}", 20, font: FONT_PATH).draw(1600, 225, 1)
|
||||||
|
|||||||
+1
-4
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
require './dialouge_box.rb'
|
require './dialouge_box.rb'
|
||||||
|
|
||||||
|
|
||||||
PRODUCER_DEBUG = false
|
PRODUCER_DEBUG = false
|
||||||
BORDER = 2
|
BORDER = 2
|
||||||
HOVER_TIME = 500 # ms
|
HOVER_TIME = 500 # ms
|
||||||
@@ -27,11 +26,10 @@ class Producer
|
|||||||
@image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) {
|
@image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) {
|
||||||
# Render the item
|
# Render the item
|
||||||
Gosu.draw_rect(0, 0, @box_size - (2 * BORDER), @box_size - (2 * BORDER), Gosu::Color::RED, 0)
|
Gosu.draw_rect(0, 0, @box_size - (2 * BORDER), @box_size - (2 * BORDER), Gosu::Color::RED, 0)
|
||||||
Gosu::Image.from_text("#{@number}", 20).draw(5, 5, 1)
|
Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(5, 5, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "Produces #{@rate} number per second")
|
@tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "Produces #{@rate} number per second")
|
||||||
puts @tooltip.methods.sort
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates numbers depending on the rate. This is done with knowing that the
|
# Creates numbers depending on the rate. This is done with knowing that the
|
||||||
@@ -47,7 +45,6 @@ class Producer
|
|||||||
@camera_zoom = camera_zoom
|
@camera_zoom = camera_zoom
|
||||||
if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom)
|
if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom)
|
||||||
@tooltip_timer += 60.0 * delta_mult
|
@tooltip_timer += 60.0 * delta_mult
|
||||||
puts @tooltip_timer
|
|
||||||
if @tooltip_timer > HOVER_TIME
|
if @tooltip_timer > HOVER_TIME
|
||||||
@tooltip.show = true
|
@tooltip.show = true
|
||||||
@tooltip.update(@draw_x, @draw_y, @camera_zoom)
|
@tooltip.update(@draw_x, @draw_y, @camera_zoom)
|
||||||
|
|||||||
Reference in New Issue
Block a user