chingu 0.5.9.2 → 0.5.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.9.2"
5
+ s.version = "0.5.9.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["ippa"]
9
- s.date = %q{2009-11-09}
9
+ s.date = %q{2009-11-11}
10
10
  s.description = %q{OpenGL accelerated 2D game framework for Ruby.
11
11
  Builds on the awesome Gosu (Ruby/C++) which provides all the core functionality.
12
12
  It adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and automation of common task.}
@@ -28,5 +28,5 @@ require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.
28
28
  require_all "#{CHINGU_ROOT}/chingu"
29
29
 
30
30
  module Chingu
31
- VERSION = "0.5.9.2"
31
+ VERSION = "0.5.9.3"
32
32
  end
@@ -35,11 +35,12 @@ module Chingu
35
35
  #
36
36
  def initialize(options = {})
37
37
  @options = options
38
+ @parent = options[:parent]
38
39
 
39
40
  #
40
41
  # A GameObject either belong to a GameState or our mainwindow ($window)
41
42
  #
42
- if $window && $window.respond_to?(:game_state_manager)
43
+ if !@parent && $window && $window.respond_to?(:game_state_manager)
43
44
  @parent = $window.game_state_manager.inside_state || $window
44
45
  end
45
46
 
@@ -32,16 +32,25 @@ module Chingu
32
32
  class Edit < Chingu::GameState
33
33
  def initialize(options = {})
34
34
  super
35
+ @grid = options[:grid]
36
+ @classes = options[:classes] || []
37
+
35
38
  @color = Gosu::Color.new(200,0,0,0)
36
39
  @red = Gosu::Color.new(0xFFFF0000)
37
40
  @white = Gosu::Color.new(0xFFFFFFFF)
38
41
  @selected_game_object = nil
39
42
  self.input = { :left_mouse_button => :left_mouse_button,
40
43
  :released_left_mouse_button => :released_left_mouse_button,
44
+ :delete => :destroy_selected_game_objects,
41
45
  :e => :save_and_quit,
42
46
  :s => :save,
43
- :esc => :quit
44
- }
47
+ :esc => :quit,
48
+ :"1" => :create_object_1,
49
+ :"2" => :create_object_2,
50
+ :"3" => :create_object_3,
51
+ :"4" => :create_object_4,
52
+ :"5" => :create_object_5,
53
+ }
45
54
  end
46
55
 
47
56
  def setup
@@ -51,26 +60,45 @@ module Chingu
51
60
  "#{previous_game_state.class.to_s.downcase}.yml"
52
61
  end
53
62
  @filename = File.join($window.root, name)
54
- @title = Text.create("Editing #{@filename}", :x => 5, :y => 10)
55
- @title2 = Text.create("(S) Save (E) Save and Quit (ESC) Quit without saving", :x => 5, :y => 30)
56
- @text = Text.create("", :x => 5, :y => 50)
63
+ @title = Text.create("File: #{@filename}", :x => 5, :y => 10)
64
+ @title.text += " - Grid: #{@grid}" if @grid
65
+ @title2 = Text.create("(1-10) Create object at mouse pos (DEL) Delete selected object (S) Save (E) Save and Quit (ESC) Quit without saving", :x => 5, :y => 30)
66
+ @text = Text.create("", :x => 5, :y => 50)
57
67
  end
58
68
 
69
+ def create_object_nr(number)
70
+ @classes[number].create(:x => $window.mouse_x, :y => $window.mouse_y, :parent => previous_game_state) if @classes[number]
71
+ end
72
+
73
+ def create_object_1; create_object_nr(0); end
74
+ def create_object_2; create_object_nr(1); end
75
+ def create_object_3; create_object_nr(2); end
76
+ def create_object_4; create_object_nr(3); end
77
+ def create_object_5; create_object_nr(4); end
78
+
79
+
80
+
59
81
  def draw
60
- previous_game_state.draw # Draw prev game state onto screen (in this case our level)
82
+ # Draw prev game state onto screen (the level we're editing for example)
83
+ previous_game_state.draw
61
84
 
85
+ #
86
+ # Draw an edit HUD
87
+ #
62
88
  $window.draw_quad( 0,0,@color,
63
89
  $window.width,0,@color,
64
90
  $window.width,100,@color,
65
91
  0,100,@color,10)
92
+ #
93
+ # Draw debug Texts etc..
94
+ #
66
95
  super
67
96
 
68
- previous_game_state.game_objects.select { |o| o.options[:selected] }.each do |game_object|
69
-
70
- # rect = game_object.bounding_box
71
- # rect.x *= $window.factor
72
- # rect.y *= $window.factor
73
- # $window.fill_rect(rect, @red, game_object.zorder - 1)
97
+ #
98
+ # Draw a red rectangle around all selected game objects
99
+ #
100
+ selected_game_objects.each do |game_object|
101
+ draw_rect(game_object.bounding_box.inflate(2,2), @red, 999)
74
102
  end
75
103
 
76
104
  #
@@ -79,34 +107,64 @@ module Chingu
79
107
  $window.draw_triangle( $window.mouse_x, $window.mouse_y, @white,
80
108
  $window.mouse_x, $window.mouse_y + 10, @white,
81
109
  $window.mouse_x + 10, $window.mouse_y + 10, @white, 9999)
82
-
110
+
111
+ end
112
+
113
+ def update
114
+ super
115
+
83
116
  if @left_mouse_button && @selected_game_object
84
- @selected_game_object.x = $window.mouse_x / $window.factor
85
- @selected_game_object.y = $window.mouse_y / $window.factor
117
+ @selected_game_object.x = ($window.mouse_x + @mouse_x_offset) / $window.factor
118
+ @selected_game_object.y = ($window.mouse_y + @mouse_y_offset) / $window.factor
119
+ @selected_game_object.x -= @selected_game_object.x % @grid[0]
120
+ @selected_game_object.y -= @selected_game_object.y % @grid[1]
86
121
 
87
- #
88
- # Can we abstract this out somehow?
89
- #
122
+ # TODO: better cleaner sollution
90
123
  if @selected_game_object.respond_to?(:bounding_box)
91
124
  @selected_game_object.bounding_box.x = @selected_game_object.x
92
125
  @selected_game_object.bounding_box.y = @selected_game_object.y
93
126
  end
94
127
  end
95
- end
128
+ end
129
+
130
+ def selected_game_objects
131
+ previous_game_state.game_objects.select { |o| o.options[:selected] }
132
+ end
133
+
134
+ def destroy_selected_game_objects
135
+ selected_game_objects.each(&:destroy)
136
+ end
96
137
 
97
138
  def left_mouse_button
98
139
  @left_mouse_button = true
99
140
  x = $window.mouse_x / $window.factor
100
141
  y = $window.mouse_y / $window.factor
142
+
101
143
  @text.text = "Click @ #{x} / #{y}"
144
+
145
+ #
146
+ # Deselect all objects
147
+ #
148
+ selected_game_objects.each do |game_object|
149
+ game_object.options[:selected] = false
150
+ end
151
+
152
+ #
153
+ # Get new object that was clicked at (if any)
154
+ #
102
155
  @selected_game_object = game_object_at(x, y)
156
+
103
157
  if @selected_game_object
104
- @text.text = "#{@text.text} : #{@game_object.class.to_s}"
158
+ @text.text = "#{@text.text} : #{@selected_game_object.class.to_s}"
105
159
  @selected_game_object.options[:selected] = true
160
+
161
+ @mouse_x_offset = @selected_game_object.x - $window.mouse_x
162
+ @mouse_y_offset = @selected_game_object.y - $window.mouse_y
106
163
  end
164
+
107
165
  end
108
166
 
109
- def released_left_mouse_button
167
+ def released_left_mouse_button
110
168
  @left_mouse_button = false
111
169
  @selected_game_object = false
112
170
  end
@@ -148,7 +206,7 @@ module Chingu
148
206
  end
149
207
 
150
208
  def quit
151
- pop_game_state
209
+ pop_game_state(:setup => false)
152
210
  end
153
211
 
154
212
  #
@@ -97,7 +97,16 @@ module Chingu
97
97
  end
98
98
  end
99
99
 
100
-
100
+ #
101
+ # Draws a unfilled rect in given color
102
+ #
103
+ def draw_rect(rect, color, zorder)
104
+ $window.draw_line(rect.x, rect.y, color, rect.right, rect.y, color, zorder)
105
+ $window.draw_line(rect.right, rect.y, color, rect.right, rect.bottom, color, zorder)
106
+ $window.draw_line(rect.right, rect.bottom, color, rect.x, rect.bottom, color, zorder)
107
+ $window.draw_line(rect.x, rect.bottom, color, rect.x, rect.y, color, zorder)
108
+ end
109
+
101
110
  #
102
111
  # Fills a given Rect 'rect' with Color 'color', drawing with zorder 'zorder'
103
112
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9.2
4
+ version: 0.5.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -30,7 +30,7 @@ cert_chain:
30
30
  hxtMlw==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-11-09 00:00:00 +01:00
33
+ date: 2009-11-11 00:00:00 +01:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file