Created
April 23, 2021 11:43
-
-
Save Elerphore/c31c5cd1ef422934b5bd6ff18d7e48f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def set_bars_positions item | |
| item.x = item[:x] * 60 | |
| item.y = ($gtk.args.state.border.y + $gtk.args.state.border.h - 60) - item[:y] * 60 | |
| item.w = 60 | |
| item.h = 60 | |
| end | |
| def set_bases_positions item | |
| item.x = item[:x] * 60 | |
| item.y = ($gtk.args.state.border.y + $gtk.args.state.border.h - 60) - item[:y] * 60 | |
| item.w = 40 | |
| item.h = 60 | |
| end | |
| def set_units_positions item | |
| item.x = item[:x] * 30 | |
| item.y = ($gtk.args.state.border.y + $gtk.args.state.border.h - 30) - item[:y] * 30 | |
| item.w = 30 | |
| item.h = 30 | |
| end | |
| def set_health_bar_positions item | |
| item.x = item[:x] * 30 | |
| item.y = ($gtk.args.state.border.y + $gtk.args.state.border.h - 30) - item[:y] * 30 | |
| item.w = item[:value] / 3.6 | |
| item.h = 10 | |
| end | |
| def render | |
| render_background | |
| render_bases | |
| render_top_bar | |
| render_left_bar | |
| render_units | |
| render_health_bars | |
| render_money | |
| render_units_limit | |
| end | |
| def render_background | |
| $gtk.args.outputs.background_color = [0, 100, 100] | |
| end | |
| def render_top_bar | |
| $gtk.args.outputs.solids << $gtk.args.state.top_bar | |
| end | |
| def render_left_bar | |
| $gtk.args.outputs.solids << $gtk.args.state.left_bar | |
| end | |
| def render_bases | |
| $gtk.args.outputs.solids << $gtk.args.state.bases | |
| end | |
| def render_units | |
| $gtk.args.outputs.solids << $gtk.args.state.units | |
| end | |
| def render_health_bars | |
| $gtk.args.state.units.each {|item| $gtk.args.outputs.solids << item[:health]} | |
| end | |
| def render_money | |
| $gtk.args.outputs.labels << [$gtk.args.grid.left.shift_right(100), $gtk.args.grid.top.shift_down(25), "0", 0, 0] | |
| end | |
| def render_units_limit | |
| $gtk.args.outputs.labels << [$gtk.args.grid.left.shift_right(125), $gtk.args.grid.top.shift_down(25), "0/16", 0, 0] | |
| end | |
| $gtk.args.state.sprite_size = 60 | |
| $gtk.args.state.sprite_unit_size = 30 | |
| $gtk.args.state.border.h = $gtk.args.state.sprite_size * 3 | |
| $gtk.args.state.border.y = 710 - $gtk.args.state.border.h | |
| $gtk.args.state.top_bar = [ | |
| {x: 0 + 6.5, y: 0}, | |
| {x: 1 + 6.5, y: 0}, | |
| {x: 2 + 6.5, y: 0}, | |
| {x: 3 + 6.5, y: 0}, | |
| {x: 4 + 6.5, y: 0}, | |
| {x: 5 + 6.5, y: 0}, | |
| {x: 6 + 6.5, y: 0}, | |
| {x: 7 + 6.5, y: 0} | |
| ] | |
| $gtk.args.state.left_bar = [ | |
| {x: 0, y: 0 + 0}, | |
| {x: 0, y: 1 + 0}, | |
| {x: 0, y: 2 + 0}, | |
| {x: 0, y: 3 + 0}, | |
| {x: 0, y: 4 + 0}, | |
| {x: 0, y: 5 + 0}, | |
| ] | |
| $gtk.args.state.bases = [ | |
| {type: :player, x: 0, y: 11}, | |
| {type: :enemy, x: 20.7, y: 11}, | |
| ] | |
| $gtk.args.state.units = [ | |
| {x: 7, y: 23, damage: 0.2, static?: false, in_fight?: false, lvl: :soldier, type: :player, health: {x: 7, y: 21.7, r: 255, g: 0, b: 0, a: 255, value: 100}}, | |
| {x: 3, y: 23, damage: 0.2, static?: false, in_fight?: false, lvl: :soldier, type: :player, health: {x: 3, y: 21.7, r: 255, g: 0, b: 0, a: 255, value: 100}}, | |
| {x: 24, y: 23, damage: 0.2, static?: false, in_fight?: false, lvl: :soldier, type: :enemy, health: {x: 24, y: 21.7, r: 255, g: 0, b: 0, a: 255, value: 100}}, | |
| {x: 26.3, y: 23, damage: 0.2, static?: false, in_fight?: false, lvl: :soldier, type: :enemy, health: {x: 26.3, y: 21.7, r: 255, g: 0, b: 0, a: 255, value: 100}}, | |
| ] | |
| $gtk.args.state.left_bar.each {|item| set_bars_positions item} | |
| $gtk.args.state.top_bar.each {|item| set_bars_positions item} | |
| $gtk.args.state.bases.each {|item| set_bases_positions item} | |
| $gtk.args.state.units.each {|item| set_units_positions item} | |
| $gtk.args.state.units.each {|item| set_health_bar_positions item[:health]} | |
| def move item | |
| # $gtk.args.state.units.each_with_index do |item, index| | |
| (item[:x] += 0.3; item[:health][:x] += 0.3;) if item[:type] == :player | |
| (item[:x] -= 0.3; item[:health][:x] -= 0.3;) if item[:type] == :enemy | |
| # end | |
| end | |
| def setNewHealthBarWidth item | |
| item.w = item[:value] / 3.6 if item[:value] > 0 | |
| end | |
| def calc | |
| calc_remove_dead_units | |
| end | |
| def calc_remove_dead_units | |
| $gtk.args.state.units.select! {|item| item[:health][:value] > 0} | |
| end | |
| def calc_units_list type | |
| return $gtk.args.state.units.select {|item| item[:type] == type} | |
| end | |
| def handle_units_behaiver parentArray, childArray | |
| parentArray.each_with_index do |unit, index| | |
| pl = unit.dup | |
| pl[:type] == :player ? pl[:x] += 10 : pl[:x] -= 10 | |
| if (parentArray.select{|item| unit != item}.any_intersect_rect? pl) | |
| unit[:static?] = true | |
| else | |
| unit[:static?] = false | |
| end | |
| if !childArray.any_intersect_rect? unit | |
| unit[:in_fight?] = false | |
| end | |
| move unit if !unit[:in_fight?] && !unit[:static?] | |
| childArray.each do |childUnit| | |
| if unit.intersect_rect?(childUnit) | |
| unit[:in_fight?] = true | |
| unit[:health][:value] -= childUnit[:damage] | |
| setNewHealthBarWidth unit[:health] | |
| elsif !childArray.any_intersect_rect? unit | |
| unit[:in_fight?] = false | |
| unit[:static?] = false | |
| end | |
| end | |
| end | |
| end | |
| def tick args | |
| render | |
| calc | |
| player_list = calc_units_list :player | |
| enemy_list = calc_units_list :enemy | |
| handle_units_behaiver player_list, enemy_list | |
| handle_units_behaiver enemy_list, player_list | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment