TileMap parser can now load spawn locations, added construction yard building, added particle emitters, added smoke sprite and svg.

This commit is contained in:
2019-11-20 12:51:24 -06:00
parent 7775ccb3a3
commit a9307733e3
10 changed files with 476 additions and 6 deletions

BIN
assets/smoke/smoke.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

259
assets/svg/smoke/smoke.svg Normal file
View File

@@ -0,0 +1,259 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666659 8.4666659"
version="1.1"
id="svg8"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="smoke.svg"
inkscape:export-filename="/home/cyberarm/Code/i-mic-rts/assets/smoke/smoke.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96">
<defs
id="defs2">
<inkscape:path-effect
effect="spiro"
id="path-effect825"
is_visible="true" />
<inkscape:path-effect
effect="bspline"
id="path-effect821"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="spiro"
id="path-effect825-3"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect825-3-7"
is_visible="true" />
<filter
style="color-interpolation-filters:sRGB"
x="-0.25"
width="1.5"
y="-0.25"
height="1.5"
inkscape:menu="Non-realistic 3D Shaders"
inkscape:menu-tooltip="Chrome effect with darkened edges"
inkscape:label="Sharp Metal"
id="filter1180">
<feGaussianBlur
result="result8"
stdDeviation="5"
in="SourceGraphic"
id="feGaussianBlur1160" />
<feComposite
in="result8"
result="result19"
in2="result8"
operator="xor"
id="feComposite1162" />
<feComposite
k2="1"
operator="arithmetic"
result="result17"
in2="result8"
id="feComposite1164" />
<feComposite
in2="result17"
in="SourceGraphic"
operator="atop"
result="result6"
id="feComposite1166" />
<feOffset
result="result18"
id="feOffset1168" />
<feDisplacementMap
in2="result6"
result="result4"
scale="100"
yChannelSelector="A"
xChannelSelector="A"
in="result18"
id="feDisplacementMap1170" />
<feComposite
in2="result4"
k1="1"
in="result4"
operator="arithmetic"
result="result2"
k3="1"
id="feComposite1172" />
<feComposite
in2="result2"
operator="over"
in="result2"
result="fbSourceGraphic"
id="feComposite1174" />
<feComposite
in2="result19"
operator="over"
result="result15"
id="feComposite1176" />
<feComposite
result="result16"
in2="SourceGraphic"
operator="in"
in="result15"
id="feComposite1178" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
x="-0.25"
width="1.5"
y="-0.25"
height="1.5"
inkscape:menu="Non-realistic 3D Shaders"
inkscape:menu-tooltip="Chrome effect with darkened edges"
inkscape:label="Sharp Metal"
id="filter1202">
<feGaussianBlur
result="result8"
stdDeviation="5"
in="SourceGraphic"
id="feGaussianBlur1182" />
<feComposite
in="result8"
result="result19"
in2="result8"
operator="xor"
id="feComposite1184" />
<feComposite
k2="1"
operator="arithmetic"
result="result17"
in2="result8"
id="feComposite1186" />
<feComposite
in2="result17"
in="SourceGraphic"
operator="atop"
result="result6"
id="feComposite1188" />
<feOffset
result="result18"
id="feOffset1190" />
<feDisplacementMap
in2="result6"
result="result4"
scale="100"
yChannelSelector="A"
xChannelSelector="A"
in="result18"
id="feDisplacementMap1192" />
<feComposite
in2="result4"
k1="1"
in="result4"
operator="arithmetic"
result="result2"
k3="1"
id="feComposite1194" />
<feComposite
in2="result2"
operator="over"
in="result2"
result="fbSourceGraphic"
id="feComposite1196" />
<feComposite
in2="result19"
operator="over"
result="result15"
id="feComposite1198" />
<feComposite
result="result16"
in2="SourceGraphic"
operator="in"
in="result15"
id="feComposite1200" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="15.839192"
inkscape:cx="9.3141628"
inkscape:cy="10.702259"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
units="px"
borderlayer="false"
inkscape:showpageshadow="false"
inkscape:pagecheckerboard="false"
showguides="true"
inkscape:window-width="1920"
inkscape:window-height="1006"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid815"
empspacing="8" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.53333)">
<path
style="fill:#555753;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 5.0270829,289.59166 c 0.364094,0.19632 0.7591713,0.32895 1.128675,0.51489 0.3695038,0.18594 0.7239799,0.43782 0.9238603,0.79997 0.1670072,0.30259 0.2124203,0.65711 0.2214755,1.00261 0.00906,0.3455 -0.015012,0.69278 0.026403,1.03591 0.044865,0.37171 0.1654133,0.72936 0.2577926,1.09219 0.092379,0.36284 0.1569665,0.74275 0.087626,1.11068 -0.056139,0.29789 -0.2004818,0.57762 -0.405535,0.80087 -0.2050532,0.22325 -0.4697145,0.39003 -0.7574149,0.48551 -0.575401,0.19096 -1.2295775,0.0872 -1.7474663,-0.22804 -0.2213846,-0.13473 -0.4188975,-0.3047 -0.6292414,-0.4561 -0.2103439,-0.15139 -0.4395812,-0.28665 -0.6936752,-0.33765 -0.2611395,-0.0524 -0.5307277,-0.0127 -0.7950185,0.0203 -0.2642907,0.033 -0.5380656,0.0585 -0.7924813,-0.0203 -0.2001309,-0.062 -0.3778857,-0.18695 -0.5172234,-0.34342 -0.1393376,-0.15646 -0.2415074,-0.34363 -0.3143838,-0.54007 -0.14575293,-0.39287 -0.17566293,-0.81727 -0.22672627,-1.23318 -0.050161,-0.40856 -0.1221334,-0.81705 -0.11085219,-1.22852 0.0112812,-0.41147 0.11401466,-0.83477 0.37543546,-1.15273 0.2810969,-0.34189 0.7081768,-0.52302 1.0583333,-0.79375 0.256865,-0.1986 0.4721774,-0.44565 0.7199445,-0.65549 0.1238836,-0.10492 0.2564331,-0.20081 0.4016582,-0.27337 0.145225,-0.0726 0.3037539,-0.12142 0.4658973,-0.12947 0.2407199,-0.012 0.4778935,0.066 0.694039,0.17266 0.2161454,0.10663 0.4167361,0.24211 0.6288776,0.3565 z"
id="path823"
inkscape:connector-curvature="0"
inkscape:path-effect="#path-effect825"
inkscape:original-d="m 5.0270829,289.59166 c 0.2643187,0.0885 1.082661,0.52085 2.0525353,1.31486 0.9698743,0.79401 0.1599488,1.50909 0.2478788,2.03852 0.08793,0.52943 0.1692944,1.58525 0.3454188,2.20287 0.1761244,0.61763 -2.1164017,0.70529 -2.9104162,1.05834 -0.7940145,0.35304 -0.6170964,-0.26485 -1.3229166,-0.79375 -0.7058201,-0.52891 -1.1462631,-0.17665 -1.5874998,0 -0.4412368,0.17666 -0.7052911,-1.49957 -1.05833347,-2.11667 -0.35304232,-0.6171 0.17665347,-1.58776 0.26458327,-2.38125 0.08793,-0.79349 0.5294313,-0.61762 1.0583333,-0.79375 0.528902,-0.17612 1.4113756,-0.61763 1.5875,-1.05833 0.1761244,-0.44071 1.0585976,0.4407 1.3229166,0.52916 z"
sodipodi:nodetypes="cssccccssccc" />
<path
transform="matrix(0.81985073,-0.08904363,0.08904363,0.81985073,-25.409834,52.881942)"
style="fill:#515350;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1;filter:url(#filter1180)"
d="m 5.0270829,289.59166 c 0.364094,0.19632 0.7591713,0.32895 1.128675,0.51489 0.3695038,0.18594 0.7239799,0.43782 0.9238603,0.79997 0.1670072,0.30259 0.2124203,0.65711 0.2214755,1.00261 0.00906,0.3455 -0.015012,0.69278 0.026403,1.03591 0.044865,0.37171 0.1654133,0.72936 0.2577926,1.09219 0.092379,0.36284 0.1569665,0.74275 0.087626,1.11068 -0.056139,0.29789 -0.2004818,0.57762 -0.405535,0.80087 -0.2050532,0.22325 -0.4697145,0.39003 -0.7574149,0.48551 -0.575401,0.19096 -1.2295775,0.0872 -1.7474663,-0.22804 -0.2213846,-0.13473 -0.4188975,-0.3047 -0.6292414,-0.4561 -0.2103439,-0.15139 -0.4395812,-0.28665 -0.6936752,-0.33765 -0.2611395,-0.0524 -0.5307277,-0.0127 -0.7950185,0.0203 -0.2642907,0.033 -0.5380656,0.0585 -0.7924813,-0.0203 -0.2001309,-0.062 -0.3778857,-0.18695 -0.5172234,-0.34342 -0.1393376,-0.15646 -0.2415074,-0.34363 -0.3143838,-0.54007 -0.14575293,-0.39287 -0.17566293,-0.81727 -0.22672627,-1.23318 -0.050161,-0.40856 -0.1221334,-0.81705 -0.11085219,-1.22852 0.0112812,-0.41147 0.11401466,-0.83477 0.37543546,-1.15273 0.2810969,-0.34189 0.7081768,-0.52302 1.0583333,-0.79375 0.256865,-0.1986 0.4721774,-0.44565 0.7199445,-0.65549 0.1238836,-0.10492 0.2564331,-0.20081 0.4016582,-0.27337 0.145225,-0.0726 0.3037539,-0.12142 0.4658973,-0.12947 0.2407199,-0.012 0.4778935,0.066 0.694039,0.17266 0.2161454,0.10663 0.4167361,0.24211 0.6288776,0.3565 z"
id="path823-6"
inkscape:connector-curvature="0"
inkscape:path-effect="#path-effect825-3"
inkscape:original-d="m 5.0270829,289.59166 c 0.2643187,0.0885 1.082661,0.52085 2.0525353,1.31486 0.9698743,0.79401 0.1599488,1.50909 0.2478788,2.03852 0.08793,0.52943 0.1692944,1.58525 0.3454188,2.20287 0.1761244,0.61763 -2.1164017,0.70529 -2.9104162,1.05834 -0.7940145,0.35304 -0.6170964,-0.26485 -1.3229166,-0.79375 -0.7058201,-0.52891 -1.1462631,-0.17665 -1.5874998,0 -0.4412368,0.17666 -0.7052911,-1.49957 -1.05833347,-2.11667 -0.35304232,-0.6171 0.17665347,-1.58776 0.26458327,-2.38125 0.08793,-0.79349 0.5294313,-0.61762 1.0583333,-0.79375 0.528902,-0.17612 1.4113756,-0.61763 1.5875,-1.05833 0.1761244,-0.44071 1.0585976,0.4407 1.3229166,0.52916 z"
sodipodi:nodetypes="cssccccssccc" />
<path
transform="matrix(-0.60855834,-0.35497998,0.2775773,-0.4617296,-74.414381,429.32255)"
style="fill:#4e504d;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter1202)"
d="m 5.0270829,289.59166 c 0.364094,0.19632 0.7591713,0.32895 1.128675,0.51489 0.3695038,0.18594 0.7239799,0.43782 0.9238603,0.79997 0.1670072,0.30259 0.2124203,0.65711 0.2214755,1.00261 0.00906,0.3455 -0.015012,0.69278 0.026403,1.03591 0.044865,0.37171 0.1654133,0.72936 0.2577926,1.09219 0.092379,0.36284 0.1569665,0.74275 0.087626,1.11068 -0.056139,0.29789 -0.2004818,0.57762 -0.405535,0.80087 -0.2050532,0.22325 -0.4697145,0.39003 -0.7574149,0.48551 -0.575401,0.19096 -1.2295775,0.0872 -1.7474663,-0.22804 -0.2213846,-0.13473 -0.4188975,-0.3047 -0.6292414,-0.4561 -0.2103439,-0.15139 -0.4395812,-0.28665 -0.6936752,-0.33765 -0.2611395,-0.0524 -0.5307277,-0.0127 -0.7950185,0.0203 -0.2642907,0.033 -0.5380656,0.0585 -0.7924813,-0.0203 -0.2001309,-0.062 -0.3778857,-0.18695 -0.5172234,-0.34342 -0.1393376,-0.15646 -0.2415074,-0.34363 -0.3143838,-0.54007 -0.14575293,-0.39287 -0.17566293,-0.81727 -0.22672627,-1.23318 -0.050161,-0.40856 -0.1221334,-0.81705 -0.11085219,-1.22852 0.0112812,-0.41147 0.11401466,-0.83477 0.37543546,-1.15273 0.2810969,-0.34189 0.7081768,-0.52302 1.0583333,-0.79375 0.256865,-0.1986 0.4721774,-0.44565 0.7199445,-0.65549 0.1238836,-0.10492 0.2564331,-0.20081 0.4016582,-0.27337 0.145225,-0.0726 0.3037539,-0.12142 0.4658973,-0.12947 0.2407199,-0.012 0.4778935,0.066 0.694039,0.17266 0.2161454,0.10663 0.4167361,0.24211 0.6288776,0.3565 z"
id="path823-6-5"
inkscape:connector-curvature="0"
inkscape:path-effect="#path-effect825-3-7"
inkscape:original-d="m 5.0270829,289.59166 c 0.2643187,0.0885 1.082661,0.52085 2.0525353,1.31486 0.9698743,0.79401 0.1599488,1.50909 0.2478788,2.03852 0.08793,0.52943 0.1692944,1.58525 0.3454188,2.20287 0.1761244,0.61763 -2.1164017,0.70529 -2.9104162,1.05834 -0.7940145,0.35304 -0.6170964,-0.26485 -1.3229166,-0.79375 -0.7058201,-0.52891 -1.1462631,-0.17665 -1.5874998,0 -0.4412368,0.17666 -0.7052911,-1.49957 -1.05833347,-2.11667 -0.35304232,-0.6171 0.17665347,-1.58776 0.26458327,-2.38125 0.08793,-0.79349 0.5294313,-0.61762 1.0583333,-0.79375 0.528902,-0.17612 1.4113756,-0.61763 1.5875,-1.05833 0.1761244,-0.44071 1.0585976,0.4407 1.3229166,0.52916 z"
sodipodi:nodetypes="cssccccssccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -30,6 +30,7 @@ require_relative "lib/states/menus/multiplayer_lobby_menu"
require_relative "lib/zorder"
require_relative "lib/component"
require_relative "lib/particle_emitter"
require_relative "lib/entity"
require_relative "lib/map"
require_relative "lib/tiled_map"

View File

@@ -0,0 +1,34 @@
IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, "Provides radar and builds construction workers") do |entity|
entity.radius = 40
entity.max_health = 100.0
entity.body_image = "buildings/construction_yard/construction_yard.png"
entity.shell_image = "buildings/construction_yard/construction_yard_shell.png"
entity.overlay_image = "buildings/construction_yard/construction_yard_overlay.png"
position = entity.position.clone
position.z = IMICRTS::ZOrder::OVERLAY
emitters = []
p1 = position.clone
p1.x -= 25
p1.y -= 8
p2 = p1.clone
p2.y += 25
p3 = position.clone
p3.x += 8
p3.y -= 15
p4 = p3.clone
p4.x += 21
emitters.push(p1, p2, p3, p4)
emitters.each do |pos|
entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: pos)
end
entity.on_tick do
end
end

View File

@@ -18,7 +18,7 @@ class IMICRTS
attr_reader :player, :id, :name, :type, :speed
attr_accessor :position, :angle, :radius, :target, :state,
:movement, :health, :max_health,
:turret, :center
:turret, :center, :particle_emitters
def initialize(name:, player:, id:, position:, angle:, director:)
@player = player
@id = id
@@ -27,10 +27,13 @@ class IMICRTS
@director = director
@speed = 0.5
@radius = 32 / 2
@sight_radius = 5 # tiles
@range_radius = 3 # tiles
@radius = 32 / 2 # pixels
@target = nil
@state = :idle
@center = CyberarmEngine::Vector.new(0.5, 0.5)
@particle_emitters = []
@components = {}
@@ -101,7 +104,7 @@ class IMICRTS
end
def render
@render = Gosu.render(32, 32, retro: true) do
@render = Gosu.render(@shell_image.width, @shell_image.height, retro: true) do
@body_image.draw(0, 0, 0) if @body_image
@shell_image.draw(0, 0, 0, 1, 1, @player.color)
@overlay_image.draw(0, 0, 0) if @overlay_image
@@ -113,6 +116,7 @@ class IMICRTS
@render.draw_rot(@position.x, @position.y, @position.z, @angle, @center.x, @center.y)
component(:turret).draw if component(:turret)
@particle_emitters.each(&:draw)
end
def update
@@ -123,6 +127,11 @@ class IMICRTS
component(:movement).follow_path
end
@particle_emitters.each do |emitter|
@particle_emitters.delete(emitter) if emitter.die?
emitter.update
end
end
def tick(tick_id)

View File

@@ -1,6 +1,6 @@
class IMICRTS
class Map
attr_reader :tile_size, :tiles, :ores, :width, :height
attr_reader :tile_size, :tiles, :ores, :spawnpoints, :width, :height
def initialize(map_file:)
@tiled_map = TiledMap.new(map_file)
@@ -9,6 +9,7 @@ class IMICRTS
@tiles = {}
@ores = {}
@spawnpoints = @tiled_map.spawnpoints.freeze
@tiled_map.layers.each do |layer|
layer.height.times do |y|

93
lib/particle_emitter.rb Normal file
View File

@@ -0,0 +1,93 @@
class IMICRTS
class ParticleEmitter
def initialize(position:, direction: CyberarmEngine::Vector.up, time_to_live: 1000, particle_time_to_live: 500, speed: 10.0, max_particles: 128, frequency: 10.0, images: [], color: Gosu::Color::WHITE.dup, jitter: 10.0)
@position = position
@direction = direction
@time_to_live = time_to_live
@particle_time_to_live = particle_time_to_live
@speed = speed
@max_particles = max_particles
@frequency = frequency
@images = images
@color = color
@jitter = jitter
@born_at = Gosu.milliseconds
@last_emitted_at = 0
@particles = []
@factor = CyberarmEngine::Vector.new(1.0 ,1.0)
setup
end
def setup
end
def emit
dir = @direction.clone
dir.x = rand(-@jitter.to_f..@jitter.to_f) * 1
dir.normalized
@particles << Particle.new(
position: @position, direction: dir,
factor: @factor.clone, angle: rand(360.0),
speed: @speed, time_to_live: @particle_time_to_live, image: @images.sample,
color: @color.dup
)
@last_emitted_at = Gosu.milliseconds
end
def draw
@particles.each(&:draw)
end
def update
if @particles.count < @max_particles && Gosu.milliseconds >= @last_emitted_at + (1000.0 / @frequency)
emit
end
@particles.each do |particle|
@particles.delete(particle) if particle.die?
particle.update
end
end
def die?
Gosu.milliseconds >= @born_at + @time_to_live
end
end
class Particle
attr_accessor :position, :direction, :factor, :angle, :speed, :time_to_live, :image, :color, :born_at
def initialize(position:, direction:, factor:, angle:, speed:, time_to_live:, image:, color:)
@position = position
@direction = direction
@factor = factor
@angle = angle
@speed = speed
@time_to_live = time_to_live
@image = image
@color = color
@born_at = Gosu.milliseconds
end
def draw
@image.draw_rot(*@position.to_a[0..2], @angle, 0.5, 0.5, @factor.x, @factor.y, @color)
end
def update
@position -= (@direction * @speed) * $window.dt
end
def die?
Gosu.milliseconds >= @born_at + @time_to_live
end
end
end
Dir.glob("#{IMICRTS::GAME_ROOT_PATH}/lib/particle_emitters/**/*.rb").each do |emitter|
p emitter
require_relative emitter
end

View File

@@ -0,0 +1,37 @@
class IMICRTS
class SmokeEmitter < ParticleEmitter
def setup
@time_to_live = Float::INFINITY
@particle_time_to_live = 2_500
@frequency = 10.0
@color = Gosu::Color.rgba(255, 255, 255, 255.0 * 0.4)
@direction = CyberarmEngine::Vector.up
@direction.y = 4.5
@jitter = 25.0
@images = Gosu::Image.load_tiles("#{IMICRTS::ASSETS_PATH}/smoke/smoke.png", 32, 32, retro: false)
end
def emit
super
@particles.last.factor = CyberarmEngine::Vector.new(0.1, 0.1)
end
def update
super
@particles.each do |particle|
life_cycle = (Gosu.milliseconds - particle.born_at.to_f) / particle.time_to_live
scale = (2.0 * life_cycle) + 0.25
particle.factor.x = scale
particle.factor.y = scale
particle.color.alpha = ((255.0 * (1.0 - life_cycle)) - 255.0 * 0.4).clamp(0.0, 255.0)
particle.angle += rand(0.1..0.5)
particle.direction.x = Math.cos(Gosu.milliseconds / 1_000.0) * 0.162
end
end
end
end

View File

@@ -65,7 +65,24 @@ class IMICRTS
end
end
100.times { |i| [@c, @h, @t].sample.instance_variable_get("@block").call }
# 100.times { |i| [@c, @h, @t].sample.instance_variable_get("@block").call }
spawnpoint = @director.map.spawnpoints.last
@player.entities << Entity.new(
name: :construction_yard,
director: @director,
player: @player,
id: @player.next_entity_id,
position: CyberarmEngine::Vector.new(spawnpoint.x, spawnpoint.y, ZOrder::BUILDING),
angle: 0
)
@player.entities << Entity.new(
name: :construction_worker,
director: @director,
player: @player,
id: @player.next_entity_id,
position: CyberarmEngine::Vector.new(spawnpoint.x - 64, spawnpoint.y + 64, ZOrder::GROUND_VEHICLE),
angle: 0
)
end
def draw

View File

@@ -1,7 +1,7 @@
class IMICRTS
class TiledMap
attr_reader :width, :height, :tile_size
attr_reader :layers, :tilesets
attr_reader :layers, :tilesets, :spawnpoints
def initialize(map_file)
@xml = Nokogiri::XML(File.read("#{IMICRTS::ASSETS_PATH}/#{map_file}"))
@@ -10,6 +10,7 @@ class IMICRTS
@layers = []
@tilesets = []
@spawnpoints = []
@tiles = []
@@ -33,6 +34,15 @@ class IMICRTS
@xml.search("//layer").each do |layer|
@layers << Layer.new(layer)
end
@xml.search("//objectgroup").each do |objectgroup|
if objectgroup.attr("name") == "spawns"
objectgroup.children.each do |object|
next unless object.attr("name") && object.attr("name").downcase.strip == "spawn"
@spawnpoints << SpawnPoint.new(object)
end
end
end
end
def get_tile(tile_id)
@@ -121,5 +131,14 @@ class IMICRTS
end
end
end
class SpawnPoint
attr_reader :x, :y
def initialize(xml_object)
@x, @y = Integer(xml_object.attr("x")), Integer(xml_object.attr("y"))
end
end
end
end