diff options
| author | realtradam <[email protected]> | 2021-05-04 06:23:39 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-05-04 06:23:39 -0400 |
| commit | a62ac5e77570516c399f9bad114aaba7bf20ff67 (patch) | |
| tree | 96b39ea4c9a51fc6fcf90ad86e595a20a04a8912 | |
| parent | 5942751cd24345cfe1fb4a40f9390ae99fd0a57d (diff) | |
| download | tileset-map-editor-a62ac5e77570516c399f9bad114aaba7bf20ff67.tar.gz tileset-map-editor-a62ac5e77570516c399f9bad114aaba7bf20ff67.zip | |
testing grid
| -rw-r--r-- | assets/kenny/PNG/128/towerDefense_tile299.png | bin | 2154 -> 0 bytes | |||
| -rw-r--r-- | run.rb | 48 | ||||
| -rw-r--r-- | tileset.rb | 30 |
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 Binary files differdeleted file mode 100644 index 0e8550c..0000000 --- a/assets/kenny/PNG/128/towerDefense_tile299.png +++ /dev/null @@ -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 @@ -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 |
