Class: Core::States::GameState
Overview
Runs the map and basic game logic
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
-
#osd ⇒ Object
readonly
Returns the value of attribute osd.
-
#party ⇒ Object
readonly
Returns the value of attribute party.
Attributes inherited from State
Instance Method Summary collapse
- #battle(enemies, bg, ctrl) ⇒ Object
- #draw ⇒ Object
-
#find_object(x, y) ⇒ Object
Looks for an objects on the current map at the given screen coordinates.
-
#initialize(window) ⇒ GameState
constructor
A new instance of GameState.
- #player ⇒ Object
- #update ⇒ Object
Methods inherited from State
#draw_cursor, #finish, #update_cursor
Constructor Details
#initialize(window) ⇒ GameState
Returns a new instance of GameState.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/states/states.rb', line 44 def initialize(window) super(window) Core.window.state = self Core::Game.items = Core::Parse.items Core::Game.skills = Core::Parse.skills Core::Game.spells = Core::Parse.spells Core::Game.weapons = Core::Parse.weapons Core::Game.enemies = Core::Parse.enemies # needs the weapons Core::Game.characters = Core::Parse.characters Core::Game::Alchemy.recipies = Core::Parse.recipies Core::Trans.parse_items Core::Trans.parse_skills Core::Trans.parse_spells Core::Trans.parse_dialogues Core::Trans.parse_enemies @party = Core::Game::Party.new @map = Core::Game::MapLoader.new @map.load("test") # TODO fetch from init.def @setup = false @context = nil @osd = {} end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
42 43 44 |
# File 'lib/states/states.rb', line 42 def map @map end |
#osd ⇒ Object (readonly)
Returns the value of attribute osd.
42 43 44 |
# File 'lib/states/states.rb', line 42 def osd @osd end |
#party ⇒ Object (readonly)
Returns the value of attribute party.
42 43 44 |
# File 'lib/states/states.rb', line 42 def party @party end |
Instance Method Details
#battle(enemies, bg, ctrl) ⇒ Object
132 133 134 135 |
# File 'lib/states/states.rb', line 132 def battle(enemies, bg, ctrl) Core.window.save Core.window.advance(BattleState.new(@party, enemies, bg, ctrl)) end |
#draw ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/states/states.rb', line 101 def draw @map.draw @osd.each_value { |w| w.draw } @context.draw if @context draw_cursor end |
#find_object(x, y) ⇒ Object
Looks for an objects on the current map at the given screen coordinates
Returns nil
if nothing was found
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/states/states.rb', line 113 def find_object(x, y) #puts("looking for object at #{x/32}|#{y/32} (#{x}|#{y})") @map.objects.each { |obj| if obj.x/32 == x/32 and obj.y/32 == y/32 #puts("found #{obj.inspect}") return obj end } return nil end |
#player ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/states/states.rb', line 124 def player @map.objects.each { |obj| if obj.class == Core::Game::Player return obj end } end |
#update ⇒ Object
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 |
# File 'lib/states/states.rb', line 67 def update if @window.pressed?(Gosu::KbEscape) @window.save @window.advance(IngameMenu.new(Core.window, @party)) return end if @window.pressed?(Gosu::MsRight) and @context ? !Core.inside?(@window.mouse_x, @window.mouse_y, @context.x, @context.y, @context.x+@context.w, @context.y+@context.h) : true obj = find_object(@window.mouse_x.to_i - @map.xoff, @window.mouse_y.to_i - @map.yoff) @context = Core::GUI::ContextMenu.new(@window.mouse_x, @window.mouse_y, obj) end if @context @context.update # TODO fade context menu if (@window.pressed?(Gosu::MsLeft) and !Core.inside?(@window.mouse_x, @window.mouse_y, @context.x, @context.y, @context.x+@context.w, @context.y+@context.h)) or @context.remove? #@context.fade @context = nil end #if @context.faded? #end end @party.update @map.update @osd.each_value { |w| w.update if w.remove? @osd.delete(@osd.key(w)) end } update_cursor @window.unpress @setup = true #battle([Core::Game.enemies.first], "white_ties_grass", Core::Game::Combat::Control.new(:test)) end |