summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-05-04 06:23:39 -0400
committerrealtradam <[email protected]>2021-05-04 06:23:39 -0400
commita62ac5e77570516c399f9bad114aaba7bf20ff67 (patch)
tree96b39ea4c9a51fc6fcf90ad86e595a20a04a8912
parent5942751cd24345cfe1fb4a40f9390ae99fd0a57d (diff)
downloadtileset-map-editor-a62ac5e77570516c399f9bad114aaba7bf20ff67.tar.gz
tileset-map-editor-a62ac5e77570516c399f9bad114aaba7bf20ff67.zip
testing grid
-rw-r--r--assets/kenny/PNG/128/towerDefense_tile299.pngbin2154 -> 0 bytes
-rw-r--r--run.rb48
-rw-r--r--tileset.rb30
3 files changed, 44 insertions, 34 deletions
diff --git a/assets/kenny/PNG/128/towerDefense_tile299.png b/assets/kenny/PNG/128/towerDefense_tile299.png
deleted file mode 100644
index 0e8550c..0000000
--- a/assets/kenny/PNG/128/towerDefense_tile299.png
+++ /dev/null
Binary files differ
diff --git a/run.rb b/run.rb
index 06e0fc6..46a9d16 100644
--- a/run.rb
+++ b/run.rb
@@ -9,53 +9,61 @@ set width: 1024, height: 720
@eks = 0
@why = 0
-on :key_down do |event|
+on :key_held do |event|
if event.key == 'w'
- @why -= 1
+ Camera.y += -10
end
if event.key == 's'
- @why += 1
+ Camera.y += 10
end
if event.key == 'a'
- @eks -= 1
+ Camera.x += -10
end
if event.key == 'd'
- @eks += 1
+ Camera.x += 10
end
end
on :mouse_up do |event|
case event.button
when :left
- @new = @yep.create_image(@selected_item[0], @selected_item[1])
- @new.x = Window.mouse_x - (Window.mouse_x % 128)
- @new.y = Window.mouse_y - (Window.mouse_y % 128)
+ @new = @yep.create_image(column: @selected_item[0],
+ row: @selected_item[1],
+ x: Window.mouse_x - (Window.mouse_x % 128),
+ y: Window.mouse_y - (Window.mouse_y % 128))
end
end
on :mouse_scroll do |event|
@selected_item[0] += event.delta_y
- puts "=="
- pp @selected_item
- @selected_item[1] += @selected_item[0] / @yep.width
- @selected_item[0] %= @yep.width
- pp @selected_item
- @selected_item[1] %= @yep.height
- pp @selected_item
+ @selected_item[1] += @selected_item[0] / @yep.columns
+ @selected_item[0] %= @yep.columns
+ @selected_item[1] %= @yep.rows
end
@yep = Tileset.new('./assets/kenny/PNG/128', 128, 128)
+
@yep.tileset.each do |thing|
thing.each do |stuff|
- pp stuff
+ #stuff
+ end
+end
+
+([email protected]).each do |row|
+ ([email protected]).each do |column|
+ Camera << @yep.create_image(column: column, row: row, x: (column * 128) + (12 * column), y: (row * 128) + (row * 12))
end
end
@selected_item = [0,0]
-@selected_image = @yep.create_image(@selected_item[0], @selected_item[1])
+@selected_image = @yep.create_image(column: @selected_item[0], row: @selected_item[1])
+
+Camera.zoom = 0.25
update do
@selected_image.remove
- @selected_image = @yep.create_image(@selected_item[0], @selected_item[1])
- @selected_image.x = Window.mouse_x - (Window.mouse_x % 128)
- @selected_image.y = Window.mouse_y - (Window.mouse_y % 128)
+ @selected_image = @yep.create_image(column: @selected_item[0],
+ row: @selected_item[1],
+ x: (Window.mouse_x - (Window.mouse_x % 128)),
+ y: (Window.mouse_y - (Window.mouse_y % 128)))
+ Camera.redraw
end
show
diff --git a/tileset.rb b/tileset.rb
index 6f32d39..f2fc1a2 100644
--- a/tileset.rb
+++ b/tileset.rb
@@ -3,13 +3,13 @@
# A Tileset :) TODO
class Tileset
attr_reader :tileset,
- :x_dimension, :y_dimension,
+ :columns, :rows,
:width, :height
- def initialize(directory, x_dimension, y_dimension)
+ def initialize(directory, width, height)
puts directory
- @x_dimension = x_dimension
- @y_dimension = y_dimension
+ @width = width
+ @height = height
if directory[-1] == '/'
directory = "#{directory}*"
elsif directory[-1] != '*'
@@ -20,28 +20,30 @@ class Tileset
images = Dir[directory].sort
factors = divisors_of(images.length)
puts factors
- @width = factors[factors.length / 2]
- @height = factors[(factors.length / 2) - 1]
+ @columns = factors[factors.length / 2]
+ @rows = factors[(factors.length / 2) - 1]
- @tileset = Array.new(@width, nil) { Array.new(@height, nil) }
+ @tileset = Array.new(@columns, nil) { Array.new(@rows, nil) }
images.each_with_index do |image, index|
- x = index % @width
+ x = index % @columns
puts "Image #{index} is #{image}"
#@tileset[x] = [] if @tileset[x].nil?
- @tileset[x][((index - x) / @width)] = image
+ @tileset[x][((index - x) / @columns)] = image
#puts @tileset[x][((index - x) / 23)]
end
end
- def create_image(x_tile, y_tile)
- Image.new(tileset[x_tile][y_tile],
- width: x_dimension,
- height: y_dimension)
+ def create_image(column:, row:, x: 0, y: 0)
+ Image.new(tileset[column][row],
+ width: width,
+ height: height,
+ x: x,
+ y: y)
end
private
def divisors_of(num)
- (1..num).select { |n|num % n == 0 }
+ (1..num).select { |n| (num % n).zero? }
end
end