Added actual images and prepared to add extractors

This commit is contained in:
2026-06-16 21:58:05 -06:00
parent 46d45783f3
commit 564c600150
16 changed files with 121 additions and 20 deletions
+33
View File
@@ -1,3 +1,36 @@
# number_factory
A game where you create combinations of numbers!
# UI elements
If you hover over the producers you will see the speed at which it produces.
If you hover over the consumer, you can see your next goal or quest
## tools
### Extractor
Extracts numbers. It is a three by three square and populates numbers from any
side (max 12) every time the producer ticks.
### Conveyer belt
Can move numbers around.
### Adder
Can output to either side but will only output to one space. Prefers the slot
on the left. If it is full though it will use the slots to the right
### Multiplier
### Subtractor
### Divider
### Exponent
### Logarithm
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 653 B

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.
+2 -2
View File
@@ -37,11 +37,11 @@ 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, mouse_x, mouse_y)
def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y, mouse_used)
@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)
if !mouse_used && 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
+26
View File
@@ -0,0 +1,26 @@
# Nathan Hinton
#
# When placed it will extract numbers at a specified rate and place them on any
# conveyer belts that are adjacent to it.
class Extractor
def initialize(x, y, box_size)
@x = x
@y = y
@box_size = box_size
@image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) {
Gosu::Image.new('assets/images/producer.png').draw(0, 0, 0, @box_size / 32.0, @box_size / 32.0)
Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(10 / 32.0 * @box_size, (8 / 32.0 * @box_size), 1, 2, 2, 0xFFFA32C0)
}
end
def update(delta_mult, camera_x, camera_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
end
def draw()
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
end
end
+10 -12
View File
@@ -7,7 +7,7 @@ require 'yaml'
require './producer.rb'
require './consumer.rb'
require './dialouge_box.rb'
require './ui.rb'
FONT_PATH = 'assets/font/Cousine-Regular.ttf'
@@ -45,8 +45,7 @@ class NumFactory < Gosu::Window
@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
@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 = []
@ui = UI.new(WIDTH, HEIGHT)
# Load from file or initialize a new game
begin
@@ -188,8 +187,10 @@ class NumFactory < Gosu::Window
@camera_y = [@camera_y, @game_width].min
### ITEMS ###
mouse_used = @ui.update(self.mouse_x, self.mouse_y)
@producers.each do |producer|
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y)
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used)
end
@belts.each do |belt|
@@ -197,10 +198,7 @@ class NumFactory < Gosu::Window
end
@consumers.each do |consumer|
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y)
end
@dialouges.each do |dialouge|
dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}")
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used)
end
end
@@ -209,9 +207,11 @@ class NumFactory < Gosu::Window
def draw
# Draw mouse coords:
onscreen_items = 0
# TODO: The background does *not* actually need to move. It can just stay
# in one spot and scale... This would make the program load so much faster
# as well as allow for larger maps.
@background.draw(
(((((WIDTH / BOX_SIZE.to_f) / 2.0) - (@camera_x * @camera_zoom)) * (BOX_SIZE))),
((((HEIGHT / BOX_SIZE.to_f) / 2.0) - (@camera_y * @camera_zoom)) * (BOX_SIZE)),
0,
@camera_zoom,
@@ -236,9 +236,7 @@ class NumFactory < Gosu::Window
end
end
@dialouges.each do |dialouge|
dialouge.draw()
end
@ui.draw()
Gosu::Image.from_text("#{width}, #{height}", 20, font: FONT_PATH).draw(1600, 0, 1)
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20, font: FONT_PATH).draw(1600, 100, 1)
+10 -5
View File
@@ -7,7 +7,6 @@ PRODUCER_DEBUG = false
BORDER = 2
HOVER_TIME = 500 # ms
class Producer
attr_reader :draw_x, :draw_y
# Create producer at a position with the number and rate specified
@@ -25,8 +24,8 @@ class Producer
@screen_height = screen_height
@image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) {
# Render the item
Gosu.draw_rect(0, 0, @box_size - (2 * BORDER), @box_size - (2 * BORDER), Gosu::Color::RED, 0)
Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(5, 5, 1)
Gosu::Image.new('assets/images/producer.png').draw(0, 0, 0, @box_size / 32.0, @box_size / 32.0)
Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(10 / 32.0 * @box_size, (8 / 32.0 * @box_size), 1, 2, 2, 0xFFFA32C0)
}
@tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "Produces #{@rate} number per second")
@@ -39,11 +38,11 @@ class Producer
# @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, mouse_x, mouse_y)
def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y, mouse_used)
@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 < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom)
if !mouse_used && 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
if @tooltip_timer > HOVER_TIME
@tooltip.show = true
@@ -53,6 +52,9 @@ class Producer
@tooltip_timer = 0
@tooltip.show = false
end
if @extractor
@extractor.update()
end
end
# Draw the producer. Uses the camera x and y to shift where it should draw
@@ -62,5 +64,8 @@ class Producer
end
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
@tooltip.draw()
if @extractor
@extractor.update()
end
end
end
+39
View File
@@ -0,0 +1,39 @@
# Nathan Hinton
# This is the UI for the game and will contain all of the sub elements required.
# There will be three main areas that we will be in charge of. First, the
# bottom bar has the selector of item types. There will be a menu in the top
# right as well as any store things that we need/
class UI
# Setup for the UI
# @param width [Integer] Width of screen in pixels
# @param height [Integer] Height of the screen in pixels
def initialize(width, height)
@width = width
@height = height
@tool_selector = []
@toolbar_width = width / 2
@toolbar_height = height / 9
@tool_selector_image = Gosu.render(@toolbar_width, @toolbar_height) {
Gosu.draw_rect(
0,
0,
@toolbar_width,
@toolbar_height,
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
0)
Gosu::Image.from_text('tool selector', TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN)
}
@x = (@width / 2) - (@toolbar_width / 2)
@y = @height - @toolbar_height
end
def update(mouse_x, mouse_y)
false
end
def draw()
@tool_selector_image.draw(@x, @y)
end
end