forked from bionickatana/number_factory
Fixed coordinate system and finally got zoom working (#1)
Reviewed-on: nathan/number_factory#1 Co-authored-by: bionickatana <nathan@hintonclan.org> Co-committed-by: bionickatana <nathan@hintonclan.org>
This commit is contained in:
+24
-18
@@ -2,36 +2,42 @@
|
||||
## A number consumer that will create numbers when an extractor is placed on it.
|
||||
|
||||
CONSUMER_DEBUG = false
|
||||
BORDER = 2
|
||||
SIZE = 3
|
||||
|
||||
class Consumer
|
||||
attr_reader :x, :y
|
||||
attr_reader :draw_x, :draw_y
|
||||
# Create consumer at a position with the number and rate specified
|
||||
# @param x [Integer] X position to start at
|
||||
# @param y [Integer] Y position to start at
|
||||
# @param number [Integer] The number to produce
|
||||
# @param rate [Integer] The speed in numbers per second to produce
|
||||
def initialize(x, y)
|
||||
@x = x
|
||||
@y = y
|
||||
@image = Gosu.render(30, 30) {Gosu.draw_rect(0, 0, 30, 30, Gosu::Color::GREEN, 0)}
|
||||
#Gosu::Image.new('assets/images/background_square.png', {:tileable => true})
|
||||
def initialize(x, y, box_size, screen_width, screen_height)
|
||||
@x = x - SIZE / 2
|
||||
@y = y - SIZE / 2
|
||||
@box_size = box_size
|
||||
@screen_width = screen_width
|
||||
@screen_height = screen_height
|
||||
@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)
|
||||
}
|
||||
end
|
||||
|
||||
# Creates numbers depending on the rate. This is done with knowing that the
|
||||
# game is 30 fps so we use that for a counter
|
||||
|
||||
# Consumes numbers created
|
||||
# @param delta_mult [Float] The delta multiplier for any actions
|
||||
def update(delta_mult)
|
||||
# @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)
|
||||
@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
|
||||
|
||||
# Draw the consumer. Uses the camera x and y to shift where it should draw
|
||||
# @param camera_x [Integer] The camera X position
|
||||
# @param camera_y [Integer] The camera Y position
|
||||
# @param camera_zoom [Float] The camera zoom
|
||||
def draw(camera_x, camera_y, camera_zoom)
|
||||
if CONSUMER_DEBUG
|
||||
def draw()
|
||||
if PRODUCER_DEBUG
|
||||
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
|
||||
end
|
||||
@image.draw(camera_zoom * (@x - camera_x), camera_zoom * (@y - camera_y), 0, camera_zoom, camera_zoom)
|
||||
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user