Compare commits
6 Commits
main
...
52f3ad0d48
| Author | SHA1 | Date | |
|---|---|---|---|
| 52f3ad0d48 | |||
| 509d30f6ad | |||
| 7aea94c224 | |||
| f8d69be2ad | |||
| 1b1696becd | |||
| c099fd5a19 |
Binary file not shown.
@@ -0,0 +1,60 @@
|
|||||||
|
# Nathan Hinotn
|
||||||
|
# Creates a simple dialouge box that can be spawned from any location
|
||||||
|
|
||||||
|
TEXT_SIZE = 20
|
||||||
|
TEXT_MARGIN = 3
|
||||||
|
class DialougeBox
|
||||||
|
attr_accessor :show
|
||||||
|
def initialize(parent_x, parent_y, screen_width, screen_height, text)
|
||||||
|
@text = text
|
||||||
|
@longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 2.25).to_i
|
||||||
|
@line_count = @text.split("\n").length
|
||||||
|
|
||||||
|
@x = parent_x
|
||||||
|
@y = parent_y
|
||||||
|
@show = false
|
||||||
|
@screen_width = screen_width
|
||||||
|
@screen_height = screen_height
|
||||||
|
@image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line, (TEXT_SIZE + TEXT_MARGIN) * @line_count) {
|
||||||
|
Gosu.draw_rect(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
|
||||||
|
((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
|
||||||
|
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
Gosu::Image.from_text(text, TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(x, y, camera_zoom, newtext: nil)
|
||||||
|
if !newtext.nil?
|
||||||
|
@text = newtext
|
||||||
|
@longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 3.5).to_i
|
||||||
|
@line_count = @text.split("\n").length
|
||||||
|
|
||||||
|
@image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line, (TEXT_SIZE + TEXT_MARGIN) * @line_count) {
|
||||||
|
Gosu.draw_rect(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
|
||||||
|
((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
|
||||||
|
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
Gosu::Image.from_text(newtext, TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
@camera_zoom = camera_zoom
|
||||||
|
@x = x
|
||||||
|
@y = y
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw()
|
||||||
|
if @show
|
||||||
|
puts "Drawing tooltip at #{@x}, #{@y}"
|
||||||
|
@image.draw(@x, @y, 0, @camera_zoom, @camera_zoom)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -7,6 +7,9 @@ require 'yaml'
|
|||||||
|
|
||||||
require './producer.rb'
|
require './producer.rb'
|
||||||
require './consumer.rb'
|
require './consumer.rb'
|
||||||
|
require './dialouge_box.rb'
|
||||||
|
|
||||||
|
FONT_PATH = 'assets/font/Cousine-Regular.ttf'
|
||||||
|
|
||||||
# Viewport resolution
|
# Viewport resolution
|
||||||
WIDTH = Gosu::screen_width
|
WIDTH = Gosu::screen_width
|
||||||
@@ -42,6 +45,9 @@ class NumFactory < Gosu::Window
|
|||||||
@camera_x_zoom_offset = WIDTH.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
@camera_x_zoom_offset = WIDTH.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
||||||
@camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
@camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
||||||
|
|
||||||
|
@dd = DialougeBox.new(0, 0, WIDTH, HEIGHT, "This is a really really really really really really really really really really string\nof test text!")
|
||||||
|
@dialouges = []
|
||||||
|
|
||||||
# Load from file or initialize a new game
|
# Load from file or initialize a new game
|
||||||
begin
|
begin
|
||||||
game_save_data = YAML.load_file("#{GAME_SAVE_DIRECTORY}/positions.yaml")
|
game_save_data = YAML.load_file("#{GAME_SAVE_DIRECTORY}/positions.yaml")
|
||||||
@@ -164,15 +170,15 @@ class NumFactory < Gosu::Window
|
|||||||
### CAMERA ###
|
### CAMERA ###
|
||||||
# Move the camera if needed
|
# Move the camera if needed
|
||||||
if self.mouse_x < CAMERA_MOVE_RANGE
|
if self.mouse_x < CAMERA_MOVE_RANGE
|
||||||
@camera_x -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_x ) / 5)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
@camera_x -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_x ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
||||||
elsif self.mouse_x > WIDTH - CAMERA_MOVE_RANGE
|
elsif self.mouse_x > WIDTH - CAMERA_MOVE_RANGE
|
||||||
@camera_x += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (WIDTH - self.mouse_x) ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
@camera_x += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (WIDTH - self.mouse_x + 1)) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.mouse_y < CAMERA_MOVE_RANGE
|
if self.mouse_y < CAMERA_MOVE_RANGE
|
||||||
@camera_y -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_y ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
@camera_y -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_y ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
||||||
elsif self.mouse_y > HEIGHT - CAMERA_MOVE_RANGE
|
elsif self.mouse_y > HEIGHT - CAMERA_MOVE_RANGE
|
||||||
@camera_y += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (HEIGHT - (self.mouse_y + 1)) ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
@camera_y += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (HEIGHT - (self.mouse_y + 1)) ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prevent camera from leaving the screen
|
# Prevent camera from leaving the screen
|
||||||
@@ -183,7 +189,7 @@ class NumFactory < Gosu::Window
|
|||||||
|
|
||||||
### ITEMS ###
|
### ITEMS ###
|
||||||
@producers.each do |producer|
|
@producers.each do |producer|
|
||||||
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom)
|
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y)
|
||||||
end
|
end
|
||||||
|
|
||||||
@belts.each do |belt|
|
@belts.each do |belt|
|
||||||
@@ -193,6 +199,10 @@ class NumFactory < Gosu::Window
|
|||||||
@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)
|
||||||
end
|
end
|
||||||
|
@dialouges.each do |dialouge|
|
||||||
|
dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## Called when OS wants to update window.
|
## Called when OS wants to update window.
|
||||||
@@ -225,15 +235,20 @@ class NumFactory < Gosu::Window
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Gosu::Image.from_text("#{width}, #{height}", 20).draw(1600, 0, 1)
|
|
||||||
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20).draw(1600, 100, 1)
|
@dialouges.each do |dialouge|
|
||||||
Gosu::Image.from_text("Tick time: #{((Time.now() - @tick_time).to_f * 1000).to_i}", 20).draw(1600, 25, 1)
|
dialouge.draw()
|
||||||
Gosu::Image.from_text("FPS: #{Gosu.fps}", 20).draw(1600, 50, 1)
|
end
|
||||||
Gosu::Image.from_text("items on screen: #{onscreen_items}", 20).draw(1600, 75, 1)
|
|
||||||
Gosu::Image.from_text("Camera boxes: #{@camera_boxes}", 20).draw(1600, 175, 1)
|
Gosu::Image.from_text("#{width}, #{height}", 20, font: FONT_PATH).draw(1600, 0, 1)
|
||||||
Gosu::Image.from_text("Camera location: #{@camera_x}, #{@camera_y}", 20).draw(1600, 200, 1)
|
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20, font: FONT_PATH).draw(1600, 100, 1)
|
||||||
Gosu::Image.from_text("Camera zoom: #{@camera_zoom}, #{@camera_x_zoom_offset}", 20).draw(1600, 225, 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("Camera viewport: (#{@camera_min_x}, #{@camera_min_y}) to (#{@camera_max_x}, #{@camera_max_y})", 20).draw(1600, 250, 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, 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 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 viewport: (#{@camera_min_x}, #{@camera_min_y}) to (#{@camera_max_x}, #{@camera_max_y})", 20, font: FONT_PATH).draw(1600, 250, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+22
-4
@@ -1,8 +1,13 @@
|
|||||||
## Nathan Hinton
|
## Nathan Hinton
|
||||||
## A number producer that will create numbers when an extractor is placed on it.
|
## A number producer that will create numbers when an extractor is placed on it.
|
||||||
|
|
||||||
|
require './dialouge_box.rb'
|
||||||
|
|
||||||
|
|
||||||
PRODUCER_DEBUG = false
|
PRODUCER_DEBUG = false
|
||||||
BORDER = 2
|
BORDER = 2
|
||||||
|
HOVER_TIME = 500 # ms
|
||||||
|
|
||||||
|
|
||||||
class Producer
|
class Producer
|
||||||
attr_reader :draw_x, :draw_y
|
attr_reader :draw_x, :draw_y
|
||||||
@@ -15,16 +20,18 @@ class Producer
|
|||||||
@x = x
|
@x = x
|
||||||
@y = y
|
@y = y
|
||||||
@number = [number, 1].max
|
@number = [number, 1].max
|
||||||
@rate = (30/rate).to_i
|
@rate = rate
|
||||||
@box_size = box_size
|
@box_size = box_size
|
||||||
@screen_width = screen_width
|
@screen_width = screen_width
|
||||||
@screen_height = screen_height
|
@screen_height = screen_height
|
||||||
@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")
|
||||||
|
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
|
||||||
@@ -34,11 +41,21 @@ class Producer
|
|||||||
# @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 < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom)
|
||||||
|
@tooltip_timer += 60.0 * delta_mult
|
||||||
|
puts @tooltip_timer
|
||||||
|
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 producer. Uses the camera x and y to shift where it should draw
|
# Draw the producer. Uses the camera x and y to shift where it should draw
|
||||||
@@ -47,5 +64,6 @@ class Producer
|
|||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user