game_2d 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -209,7 +209,7 @@ describe FakeGame do
209
209
  game.space.players.first
210
210
  end
211
211
 
212
- it "is in sync after a fall and a build" do
212
+ it "is in sync after a fall, slide left, and build" do
213
213
  window
214
214
 
215
215
  expect(game.tick).to eq(-1)
@@ -218,61 +218,78 @@ describe FakeGame do
218
218
  # server sends its public key
219
219
  # client sends encrypted password hash
220
220
  update_both
221
+ expected_tick = 0
222
+ expect(game.tick).to eq(expected_tick)
221
223
  expect(window.space).to be_nil
224
+ expect(game.space.players.size).to eq(0)
225
+ expect(game.space.npcs.size).to eq(1) # the starter Base
222
226
 
223
227
  # server sends response to login in time for tick 1
224
- 27.times do |n|
228
+ # The base is still falling, and the player falls with it
229
+ loop do
225
230
  update_both
226
- expect(game.tick).to eq(n+1)
227
- expect(window.engine.tick).to eq(n+1)
231
+ expected_tick += 1
232
+ expect(game.tick).to eq(expected_tick)
233
+ expect(window.engine.tick).to eq(expected_tick)
228
234
  expect_spaces_to_match
235
+ expect(game.space.players.size).to eq(1)
236
+ expect(game.space.npcs.size).to eq(1)
237
+ break if player_on_server.y == 800
238
+ expect(player_on_server.should_fall?).to be true
239
+ end
240
+ expect(player_on_server.should_fall?).to be false
241
+
242
+ # We can't build where the base is
243
+ # So slide into the space on the left
244
+ window.press_button! Gosu::KbLeft
245
+ 27.times do
246
+ update_both
247
+ expect_spaces_to_match
248
+ end
249
+ window.release_button! Gosu::KbLeft
250
+ loop do
251
+ update_both
252
+ expect_spaces_to_match
253
+ break if player_on_server.x == 0
229
254
  end
230
255
 
231
- # Command generated at tick 28, scheduled for tick 34
232
256
  window.press_button! Gosu::KbDown
233
257
 
234
258
  update_both
235
259
  expect_spaces_to_match
236
- expect(game.space.players.size).to eq(1)
237
- expect(game.space.npcs.size).to eq(0)
238
-
239
- plr = player_on_server
240
- expect(plr.y).to eq(800)
241
- expect(plr.falling?).to be false
260
+ # Does not take effect immediately, but only after 6 ticks
261
+ expect(game.space.npcs.size).to eq(1) # the starter Base
262
+ window.release_button! Gosu::KbLeft
242
263
 
243
- 5.times do # ticks 29 - 33
264
+ 5.times do # waiting for the 6-tick delay to transpire
244
265
  update_both
245
266
  expect_spaces_to_match
246
- expect(game.space.npcs.size).to eq(0)
267
+ expect(game.space.npcs.size).to eq(1)
247
268
  end
248
269
 
249
- # tick 34
250
- window.release_button! Gosu::KbDown
251
270
  update_both
252
- expect(game.tick).to eq(34)
253
- expect(game.space.npcs.size).to eq(1)
271
+ expect(game.space.npcs.size).to eq(2)
254
272
 
255
273
  expect_spaces_to_match
256
274
 
257
- # Command generated at tick 35, scheduled for tick 41
258
275
  window.press_button! Gosu::KbUp
259
- 6.times do # ticks 35 - 40
276
+ 6.times do # waiting for this command to go through
260
277
  update_both
261
278
  expect_spaces_to_match
262
- expect(plr.y).to eq(800)
279
+ expect(player_on_server.y).to eq(800)
263
280
  end
264
281
  window.release_button! Gosu::KbUp
265
- 41.times do |n| # ticks 41 - 81
282
+ 41.times do |n|
266
283
  update_both
267
- expect(plr.y).to eq(800 - (10 * n))
284
+ expect(player_on_server.y).to eq(800 - (10 * n))
268
285
  cplr = window.engine.space.players.first
269
- binding.pry unless cplr == plr
270
- expect(cplr).to eq(plr)
286
+ binding.pry unless cplr == player_on_server
287
+ expect(cplr).to eq(player_on_server)
271
288
  expect_spaces_to_match
272
289
  end
273
290
  end
274
291
 
275
- it "stays in sync during a block-move" do
292
+ it "stays in sync during a base-move" do
276
293
  window
277
294
  update_both
278
295
  loop do
@@ -280,23 +297,18 @@ describe FakeGame do
280
297
  break if player_on_server.y == 800
281
298
  end
282
299
 
283
- window.press_button! Gosu::KbDown
284
- update_both
285
- window.release_button! Gosu::KbDown
286
300
  window.press_button! Gosu::KbLeft
287
-
288
- 30.times do
289
- update_both
290
- end
301
+ 27.times { update_both }
291
302
  window.release_button! Gosu::KbLeft
303
+
292
304
  loop do
293
305
  update_both
294
306
  break if player_on_server.x == 0
295
307
  end
296
308
  expect_spaces_to_match
297
309
 
298
- blk = window.engine.space.npcs.first
299
- expect([blk.x, blk.y]).to eq([400,800])
310
+ base = window.engine.space.npcs.first
311
+ expect([base.x, base.y]).to eq([400,800])
300
312
 
301
313
  window.mouse_x, window.mouse_y = 50, 90
302
314
  expect(window.mouse_entity_location).to eq([300, 700])
@@ -311,9 +323,9 @@ describe FakeGame do
311
323
  update_both
312
324
  expect_spaces_to_match
313
325
 
314
- blk = window.engine.space.npcs.first
315
- $stderr.puts "step ##{n}: blk is at #{blk.x},#{blk.y} moving #{blk.x_vel},#{blk.y_vel}"
316
- if blk.x == 400 && blk.y == 700
326
+ base = window.engine.space.npcs.first
327
+ $stderr.puts "step ##{n}: base is at #{base.x},#{base.y} moving #{base.x_vel},#{base.y_vel}"
328
+ if base.x == 300 && base.y == 700
317
329
  in_a_row += 1
318
330
  else
319
331
  in_a_row = 0
@@ -343,4 +343,38 @@ describe GameSpace do
343
343
  expect(subject[:B]).to be_nil
344
344
  end
345
345
  end
346
+
347
+ describe "#copy_from" do
348
+ it "copies from the original" do
349
+ thing1a = Entity::Block.new(200, 800)
350
+ thing1a.registry_id = :A
351
+ thing1a.hp = 8
352
+ subject << thing1a
353
+ thing2a = Entity::Block.new(600, 800)
354
+ thing2a.registry_id = :B
355
+ thing2a.hp = 22
356
+ subject << thing2a
357
+
358
+ expect(thing1a.moving).to be true
359
+ expect(thing2a.moving).to be true
360
+
361
+ subject.update
362
+ expect(thing1a.moving).to be false
363
+ expect(thing2a.moving).to be false
364
+
365
+ copy = GameSpace.new(nil)
366
+ copy.copy_from(subject)
367
+
368
+ # This precludes using << during copy_from, as that
369
+ # causes neighbors of the new entity to be woken up
370
+ thing1b = copy.entities_at_point(200, 800).first
371
+ thing2b = copy.entities_at_point(600, 800).first
372
+ expect(thing1b.moving).to be false
373
+ expect(thing2b.moving).to be false
374
+
375
+ expect(thing1b).to eq(thing1a)
376
+ expect(thing2b).to eq(thing2a)
377
+ expect(copy).to eq(subject)
378
+ end
379
+ end
346
380
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: game_2d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-01 00:00:00.000000000 Z
12
+ date: 2014-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facets
@@ -155,7 +155,36 @@ dependencies:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
157
  version: 3.1.0
158
- description: Client/server sandbox game using Gosu and REnet
158
+ description: ! 'Built on top of Gosu, an engine for making 2-D games. Gosu provides
159
+ the means
160
+
161
+ to handle the graphics, sound, and keyboard/mouse events. It doesn''t provide
162
+
163
+ any sort of client/server network architecture for multiplayer games, nor a
164
+
165
+ system for tracking objects in game-space. This gem aims to fill that gap.
166
+
167
+
168
+ Originally I tried using Chipmunk as the physics engine, but its outcomes were
169
+
170
+ too unpredictable for the client to anticipate the server. It was also hard to
171
+
172
+ constrain in the ways I wanted. So I elected to build something integer-based.
173
+
174
+
175
+ In the short term, I''m throwing anything into this gem that interests me. There
176
+
177
+ are reusable elements (GameSpace, Entity, ServerPort), and game-specific
178
+
179
+ elements (particular Entity subclasses with custom behaviors). Longer term, I
180
+
181
+ could see splitting it into two gems. This gem, game_2d, would retain the
182
+
183
+ reusable platform classes. The other classes would move into a new gem specific
184
+
185
+ to the game I''m developing, as a sort of reference implementation.
186
+
187
+ '
159
188
  email:
160
189
  - cmdr.samvimes@gmail.com
161
190
  executables:
@@ -177,10 +206,15 @@ files:
177
206
  - lib/game_2d/complex_move.rb
178
207
  - lib/game_2d/encryption.rb
179
208
  - lib/game_2d/entity.rb
209
+ - lib/game_2d/entity/base.rb
180
210
  - lib/game_2d/entity/block.rb
181
211
  - lib/game_2d/entity/destination.rb
212
+ - lib/game_2d/entity/gecko.rb
213
+ - lib/game_2d/entity/ghost.rb
214
+ - lib/game_2d/entity/hole.rb
182
215
  - lib/game_2d/entity/owned_entity.rb
183
216
  - lib/game_2d/entity/pellet.rb
217
+ - lib/game_2d/entity/slime.rb
184
218
  - lib/game_2d/entity/teleporter.rb
185
219
  - lib/game_2d/entity/titanium.rb
186
220
  - lib/game_2d/entity_constants.rb
@@ -192,6 +226,7 @@ files:
192
226
  - lib/game_2d/menu.rb
193
227
  - lib/game_2d/message.rb
194
228
  - lib/game_2d/move/rise_up.rb
229
+ - lib/game_2d/move/spawn.rb
195
230
  - lib/game_2d/password_dialog.rb
196
231
  - lib/game_2d/player.rb
197
232
  - lib/game_2d/registerable.rb
@@ -207,25 +242,34 @@ files:
207
242
  - media/Space.png
208
243
  - media/Star.png
209
244
  - media/Starfighter.bmp
245
+ - media/base.png
246
+ - media/base.xcf
210
247
  - media/brick.gif
211
248
  - media/cement.gif
212
249
  - media/crosshair.gif
213
250
  - media/destination.png
214
251
  - media/destination.xcf
215
252
  - media/dirt.gif
253
+ - media/gecko.png
254
+ - media/gecko.xcf
255
+ - media/ghost.png
256
+ - media/ghost.xcf
257
+ - media/hole.png
258
+ - media/hole.xcf
216
259
  - media/pellet.png
217
260
  - media/pellet.xcf
218
- - media/player.png
219
- - media/player.xcf
220
261
  - media/rock.png
221
262
  - media/rock.xcf
263
+ - media/slime.png
264
+ - media/slime.xcf
222
265
  - media/steel.gif
223
266
  - media/tele.gif
224
267
  - media/titanium.gif
225
268
  - media/unlikelium.gif
269
+ - spec/block_spec.rb
226
270
  - spec/client_engine_spec.rb
227
271
  - spec/game_space_spec.rb
228
- homepage: ''
272
+ homepage: https://github.com/sereneiconoclast/game_2d
229
273
  licenses:
230
274
  - MIT
231
275
  post_install_message:
@@ -251,5 +295,6 @@ signing_key:
251
295
  specification_version: 3
252
296
  summary: Client/server sandbox game using Gosu and REnet
253
297
  test_files:
298
+ - spec/block_spec.rb
254
299
  - spec/client_engine_spec.rb
255
300
  - spec/game_space_spec.rb