Class: Core::Game::MapLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/game/map/map_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMapLoader

Returns a new instance of MapLoader.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/game/map/map_loader.rb', line 10

def initialize
  @objects = []
  @maps = []
  @misc = []
  @player = Core::Game::Player.new(0, 0)
  @tonepic = Core.sprite("pixel", true)
  @box = Core::GUI::Textfield.new(256, 480, 512, 224, "", 24, :left)
  @message = false
  @xoff = 496
  @yoff = 360
end

Instance Attribute Details

#miscObject (readonly)

Returns the value of attribute misc.



7
8
9
# File 'lib/game/map/map_loader.rb', line 7

def misc
  @misc
end

#objectsObject (readonly)

Returns the value of attribute objects.



7
8
9
# File 'lib/game/map/map_loader.rb', line 7

def objects
  @objects
end

#playerObject (readonly)

Returns the value of attribute player.



7
8
9
# File 'lib/game/map/map_loader.rb', line 7

def player
  @player
end

#xoffObject

Returns the value of attribute xoff.



8
9
10
# File 'lib/game/map/map_loader.rb', line 8

def xoff
  @xoff
end

#yoffObject

Returns the value of attribute yoff.



8
9
10
# File 'lib/game/map/map_loader.rb', line 8

def yoff
  @yoff
end

Instance Method Details

#currentObject



22
23
24
# File 'lib/game/map/map_loader.rb', line 22

def current
  return @maps[4]
end

#drawObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/game/map/map_loader.rb', line 152

def draw
  @maps.each { |map|
    map.draw(@xoff, @yoff) if map
  }
  @objects.each { |obj|
    obj.draw(@xoff, @yoff)
  }
  @misc.each { |m|
    m.draw
  }
  @fog.draw if @fog
  @tonepic.draw(0, 0, 500000, 1024, 768, @tone) if @tone
  if @message
    @box.draw
  end
end

#leftObject



26
27
28
# File 'lib/game/map/map_loader.rb', line 26

def left
  return @maps[3]
end

#load(file) ⇒ Object

0 1 2 3 4 5 6 7 8

4 => current



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/game/map/map_loader.rb', line 48

def load(file)
  @maps.clear
  map = Core::Parse.map(file)
  @objects = map.objects
  @objects.push(@player)
  @maps[4] = map
  if map.upper
    @maps[1] = Core::Parse.map(map.upper)
    @maps[1].yoff = -@maps[1].height*32
    if @maps[1].left
      @maps[0] = Core::Parse.map(@maps[1].left)
      @maps[0].xoff = -@maps[1].height*32
      @maps[0].yoff = -@maps[0].height*32
    end
    if @maps[1].right
      @maps[2] = Core::Parse.map(@maps[1].right)
      @maps[2].xoff = @maps[1].height*32
      @maps[2].yoff = -@maps[1].height*32
    end
  end
  if map.right
    @maps[5] = Core::Parse.map(map.right)
    @maps[5].xoff = @maps[4].width*32
    if @maps[5].upper
      @maps[2] = Core::Parse.map(@maps[5].upper)
      @maps[2].xoff = @maps[4].width*32
      @maps[2].yoff = -@maps[2].height*32
    end
    if @maps[5].lower
      @maps[8] = Core::Parse.map(@maps[5].lower)
      @maps[8].xoff = @maps[4].width*32
      @maps[8].yoff = @maps[4].height*32
    end
  end
  if map.left
    @maps[3] = Core::Parse.map(map.left)
    @maps[3].xoff = -@maps[3].width*32
    if !@maps[1].left and @maps[3].upper
      @maps[0] = Core::Parse.map(@maps[3].upper)
      @maps[0].xoff = -@maps[0].width*32
      @maps[0].yoff = -@maps[0].height*32
    end
  end
  if map.lower
    @maps[7] = Core::Parse.map(map.lower)
    @maps[7].yoff = @maps[7].height*32
    if @maps[7].left
      @maps[6] = Core::Parse.map(@maps[7].left)
      @maps[6].xoff = -@maps[7].height*32
      @maps[6].yoff = @maps[7].height*32
      if !@maps[6].left and @maps[3].lower
        @maps[6] = Core::Parse.map(@maps[3].lower)
        @maps[6].xoff = -@maps[6].width*32
        @maps[6].yoff = +@maps[6].height*32
      end
    end
    if @maps[7].right
      @maps[8] = Core::Parse.map(@maps[7].right)
      @maps[8].xoff = @maps[7].height*32
      @maps[8].yoff = @maps[7].height*32
    end
  end
  if map.properties[:music]
    if map.properties[:music] == "nil"
      @song.stop if @song
    else
      @song = Core::Song.new(map.properties[:music])
      @song.play(true)
    end
  end
  if map.properties[:fog]
    if map.properties[:fog] == "nil"
      @fog = nil
    else
      @fog = Core::Game::Fog.new(map.properties[:fog], map.properties[:fogx].to_f, map.properties[:fogy].to_f, map.properties[:foga].to_i, map.properties[:fogr].to_i, map.properties[:fogg].to_i, map.properties[:fogb].to_i)
    end
  end
  if map.properties[:tonea] or map.properties[:toner] or map.properties[:toneg] or map.properties[:toneb]
    @tone = Gosu::Color.new(map.properties[:tonea].to_i, map.properties[:toner].to_i, map.properties[:toneg].to_i, map.properties[:toneb].to_i)
  else
    @tone = nil
  end
end

#lowerObject



38
39
40
# File 'lib/game/map/map_loader.rb', line 38

def lower
  return @maps[7]
end

#message(str, x = 256, y = 480, w = 512, h = 224) ⇒ Object



169
170
171
172
173
174
# File 'lib/game/map/map_loader.rb', line 169

def message(str, x=256, y=480, w=512, h=224)
  @box.text = str
  @message = true
  @box.x, @box.y = x, y
  @box.w, @box.h = w, h
end

#rightObject



30
31
32
# File 'lib/game/map/map_loader.rb', line 30

def right
  return @maps[5]
end

#updateObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/game/map/map_loader.rb', line 132

def update
  if !@message
    @objects.each { |obj|
      obj.setup if obj.do_setup?
      obj.update
      if obj.dead?
        @objects.delete(obj)
      end
    }
    @misc.each { |obj|
      obj.update
    }
    @fog.update if @fog
  else
    if Core.window.pressed?(Gosu::KbSpace)
      @message = false
    end
  end
end

#upperObject



34
35
36
# File 'lib/game/map/map_loader.rb', line 34

def upper
  return @maps[1]
end