public
Description: A game on the lines of commercial game called CakeMania. The idea is to make an exciting free game which runs on GNU/linux and mac as well.
Homepage: http://codehunk.wordpress.com/
Clone URL: git://github.com/janmejay/bakery.git
bakery / src / bakery_wizard.rb
100644 71 lines (55 sloc) 1.532 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class BakeryWizard
  
  class BaseWindow < Gosu::Window
    
    WIDTH, HEIGHT = 1024, 768
    
    def listner= listner
      @listner = listner
    end
  
    def draw
      draw_quad(0, 0, 0xffffffff, WIDTH, 0, 0xffffffff, 0, HEIGHT, 0xffffffff, WIDTH, HEIGHT, 0xffffffff)
      @listner && @listner.draw
    end
    
    def update
      @listner && @listner.update
    end
    
  end
  
  class Window
    
    module Buildable
      def build context, window, from = nil, caption = 'Bakery'
        instance = from ? Marshal.load(File.open(from, 'r').read) : new(context)
        instance.window= window
        window.caption = caption
        window.listner = instance
        instance
      end
    end
 
    def self.REL map
      {:x => (BaseWindow::WIDTH - self::WIDTH)/2 + map[:x], :y => (BaseWindow::HEIGHT - self::HEIGHT)/2 + map[:y]}
    end
    
    def self.inherited subclass
      subclass.extend Buildable
    end
    
    def update; end
    def draw; end
    
    def window
      @window
    end
    
    def method_missing *args
      @window.send(*args)
    end
  end
  
  def initialize
    @screens = []
    @current_screen = nil
    @context = {}
    @window = BaseWindow.new(1024, 768, false)
  end
  
  def add screen
    @screens << screen
  end
  
  def go_to requested_screen, *args
    @current_screen && @current_screen.close
    arguments = [@context, @window] + args
    @current_screen = @screens.find { |screen| screen == requested_screen }.build(*arguments)
    @current_screen.show
  end
end