Class: WrappedScreen

Inherits:
Object show all
Defined in:
lib/gamebox/core/wrapped_screen.rb

Constant Summary collapse

CIRCLE_STEP =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWrappedScreen

Returns a new instance of WrappedScreen.



4
5
6
7
8
9
10
11
12
# File 'lib/gamebox/core/wrapped_screen.rb', line 4

def initialize
  width, height = *config_manager[:screen_resolution]
  fullscreen = config_manager[:fullscreen]
  @screen = HookedGosuWindow.new width, height, fullscreen
  @screen.tap do |screen|
    screen.caption = Gamebox.configuration.game_name
    screen.needs_cursor = Gamebox.configuration.needs_cursor?
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



14
15
16
# File 'lib/gamebox/core/wrapped_screen.rb', line 14

def method_missing(name,*args, &blk)
  @screen.send name, *args, &blk
end

Instance Attribute Details

#screenObject

Returns the value of attribute screen.



3
4
5
# File 'lib/gamebox/core/wrapped_screen.rb', line 3

def screen
  @screen
end

Instance Method Details

#convert_color(color) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/gamebox/core/wrapped_screen.rb', line 112

def convert_color(color)
  return color if color.is_a? Gosu::Color
  @colors ||= {}
  c = @colors[color]
  if c.nil?
    a = color.size == 4 ? color[3] : 255
    c = Gosu::Color.new a.round, *color[0..2].map{|value|value.round}
    @colors[color] = c
  end
  c
end

#draw_box(x1, y1, x2, y2, color, z) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/gamebox/core/wrapped_screen.rb', line 30

def draw_box(x1,y1,x2,y2,color, z)
  c = convert_color(color)
  @screen.draw_line x1, y1, c, x2, y1, c, z
  @screen.draw_line x2, y1, c, x2, y2, c, z
  @screen.draw_line x2, y2, c, x1, y2, c, z
  @screen.draw_line x1, y2, c, x1, y1, c, z
end

#draw_circle(cx, cy, r, color, z, step = CIRCLE_STEP) ⇒ Object

is very expensive cache it if you can somehow



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gamebox/core/wrapped_screen.rb', line 46

def draw_circle(cx,cy,r,color, z, step=CIRCLE_STEP)
  c_color = convert_color(color)
  
  x1, y1 = 0, -r
  circ = 2 * Math::PI * r
  step = 360 / circ
  step.step(45, step) { |a|
    x2, y2 = offset_x(a, r), offset_y(a, r)
    @screen.draw_line cx + x1, cy + y1, c_color, cx + x2, cy + y2, c_color, z
    @screen.draw_line cx - x1, cy + y1, c_color, cx - x2, cy + y2, c_color, z
    @screen.draw_line cx - x1, cy - y1, c_color, cx - x2, cy - y2, c_color, z
    @screen.draw_line cx + x1, cy - y1, c_color, cx + x2, cy - y2, c_color, z
    @screen.draw_line cx + y1, cy + x1, c_color, cx + y2, cy + x2, c_color, z
    @screen.draw_line cx - y1, cy + x1, c_color, cx - y2, cy + x2, c_color, z
    @screen.draw_line cx - y1, cy - x1, c_color, cx - y2, cy - x2, c_color, z
    @screen.draw_line cx + y1, cy - x1, c_color, cx + y2, cy - x2, c_color, z
    x1, y1 = x2, y2
  }
  @screen.draw_line cx + x1, cy + y1, c_color, cx - y1, cy - x1, c_color, z
  @screen.draw_line cx - x1, cy + y1, c_color, cx + y1, cy - x1, c_color, z
  @screen.draw_line cx - x1, cy - y1, c_color, cx + y1, cy + x1, c_color, z
  @screen.draw_line cx + x1, cy - y1, c_color, cx - y1, cy + x1, c_color, z
end

#draw_circle_filled(cx, cy, r, color, z) ⇒ Object

is very expensive cache it if you can somehow



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
# File 'lib/gamebox/core/wrapped_screen.rb', line 72

def draw_circle_filled(cx,cy,r,color, z)
  c_color = convert_color(color)

  x1, y1 = 0, -r
  circ = 2 * Math::PI * r
  step = 360 / circ
  step.step(45, step) { |a|
    x2, y2 = offset_x(a, r), offset_y(a, r)
    @screen.draw_quad \
      cx + x1, cy + y1, c_color, cx + x2, cy + y2, c_color,
      cx - x2, cy + y2, c_color, cx - x1, cy + y1, c_color, z
    @screen.draw_quad \
      cx - x1, cy - y1, c_color, cx - x2, cy - y2, c_color,
      cx + x2, cy - y2, c_color, cx + x1, cy - y1, c_color, z
    @screen.draw_quad \
      cx + y1, cy + x1, c_color, cx + y2, cy + x2, c_color,
      cx - y2, cy + x2, c_color, cx - y1, cy + x1, c_color, z
    @screen.draw_quad \
      cx - y1, cy - x1, c_color, cx - y2, cy - x2, c_color,
      cx + y2, cy - x2, c_color, cx + y1, cy - x1, c_color, z
    x1, y1 = x2, y2
  }
  @screen.draw_quad \
    cx + x1, cy + y1, c_color, cx - y1, cy - x1, c_color,
    cx + y1, cy - x1, c_color, cx - x1, cy + y1, c_color, z
  @screen.draw_quad \
    cx - x1, cy - y1, c_color, cx + y1, cy + x1, c_color,
    cx - y1, cy + x1, c_color, cx + x1, cy - y1, c_color, z
end

#draw_image(image, x, y, z, x_scale = 1, y_scale = 1, color = 0xffffffff, mode = :default) ⇒ Object



128
129
130
# File 'lib/gamebox/core/wrapped_screen.rb', line 128

def draw_image(image, x, y, z, x_scale = 1, y_scale = 1, color = 0xffffffff, mode = :default)
  image.draw x, y, z, x_scale, y_scale, color, mode
end

#draw_line(x1, y1, x2, y2, color, z) ⇒ Object



38
39
40
41
# File 'lib/gamebox/core/wrapped_screen.rb', line 38

def draw_line(x1,y1,x2,y2,color, z)
  c = convert_color(color)
  @screen.draw_line x1, y1, c, x2, y2, c, z
end

#draw_rotated_image(image, x, y, z, angle, center_x = 0.5, center_y = 0.5, x_scale = 1, y_scale = 1, color = 0xffffffff, mode = :default) ⇒ Object



132
133
134
# File 'lib/gamebox/core/wrapped_screen.rb', line 132

def draw_rotated_image(image, x, y, z, angle, center_x = 0.5, center_y = 0.5, x_scale = 1, y_scale = 1, color = 0xffffffff, mode = :default)
  image.draw_rot x, y, z, angle, center_x, center_y, x_scale, y_scale, color, mode
end

#fill(x1, y1, x2, y2, color, z) ⇒ Object



107
108
109
110
# File 'lib/gamebox/core/wrapped_screen.rb', line 107

def fill(x1,y1,x2,y2,color, z)
  c = convert_color(color)
  @screen.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c, z
end

#fill_screen(color, z) ⇒ Object



102
103
104
105
# File 'lib/gamebox/core/wrapped_screen.rb', line 102

def fill_screen(color, z)
  c = convert_color(color)
  @screen.draw_quad 0, 0, c, @screen.width, 0, c, 0, @screen.height, c, @screen.width, @screen.height, c, z
end

#heightObject



22
23
24
# File 'lib/gamebox/core/wrapped_screen.rb', line 22

def height
  @screen.fullscreen? ? screen_height : @screen.height
end


124
125
126
# File 'lib/gamebox/core/wrapped_screen.rb', line 124

def print(text, x, y, z, font_style)
  font_style.font.draw text, x, y, z, font_style.x_scale, font_style.y_scale, convert_color(font_style.color)
end

#record(width, height, &blk) ⇒ Object



26
27
28
# File 'lib/gamebox/core/wrapped_screen.rb', line 26

def record(width, height, &blk)
  @screen.record width, height, &blk
end

#widthObject



18
19
20
# File 'lib/gamebox/core/wrapped_screen.rb', line 18

def width
  @screen.fullscreen? ? screen_width : @screen.width
end