Class: Patience::GameScene
- Defined in:
- lib/patience/scenes/game_scene.rb
Overview
Patience::GameScene is a main scene of the game. All stuff happens here.
Instance Method Summary collapse
Instance Method Details
#register ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/patience/scenes/game_scene.rb', line 23 def register add_hook :quit, method(:exit!) add_hook :key_press, key(:q), method(:exit!) # If mouse button pressed, create Click event. If a card has # been clicked, create Drag event. Drag only face up cards. on :mouse_press do @cursor.click = EventHandler::Click.new(@cursor.mouse_pos, @areas) if @cursor. @cursor.drag = EventHandler::Drag.new(@cursor) end end on :mouse_motion do if @cursor.movable? and @cursor.click.not.stock? @cursor.drag.move(@cursor.mouse_pos) end end on :mouse_release do @cursor.click! if @cursor.clicked_something? if @cursor. @cursor.drop = EventHandler::Drop.new(@cursor.click, @areas) @cursor.drop! unless @cursor.click.stock? end end always do @cursor.mouse_pos = mouse_pos end end |
#render(win) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/patience/scenes/game_scene.rb', line 56 def render(win) win.draw @bg_sprite @areas.values.to_a.each { |area| area.draw_on(win) } # Draw the card, which is being dragged. if @cursor.drawable? @cursor.click.cards.keys.each { |card| card.draw_on(win) } end end |
#setup ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/patience/scenes/game_scene.rb', line 6 def setup @bg_sprite = Ray::Sprite.new path_of('patience/sprites/table_bg.png') @cursor = Cursor.new @deck = Deck.new @deck.cards.shuffle! @tableau = Tableau.new(@deck.shuffle_off! 28) @stock = Stock.new(@deck.shuffle_off! 24) @waste = Waste.new @foundation = Foundation.new @areas = { :tableau => @tableau, :stock => @stock, :waste => @waste, :foundation => @foundation } end |