game_2d 0.0.1 → 0.0.2
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/README.md +18 -5
- data/bin/game_2d_client.rb +3 -2
- data/lib/game_2d/client_connection.rb +75 -20
- data/lib/game_2d/client_engine.rb +35 -34
- data/lib/game_2d/complex_move.rb +1 -1
- data/lib/game_2d/encryption.rb +35 -0
- data/lib/game_2d/entity.rb +47 -31
- data/lib/game_2d/entity/block.rb +2 -6
- data/lib/game_2d/entity/destination.rb +17 -0
- data/lib/game_2d/entity/owned_entity.rb +3 -2
- data/lib/game_2d/entity/pellet.rb +0 -8
- data/lib/game_2d/entity/teleporter.rb +46 -0
- data/lib/game_2d/game.rb +82 -23
- data/lib/game_2d/game_client.rb +360 -0
- data/lib/game_2d/game_space.rb +104 -18
- data/lib/game_2d/game_window.rb +17 -216
- data/lib/game_2d/menu.rb +3 -3
- data/lib/game_2d/message.rb +37 -0
- data/lib/game_2d/move/rise_up.rb +2 -2
- data/lib/game_2d/password_dialog.rb +44 -0
- data/lib/game_2d/player.rb +15 -18
- data/lib/game_2d/registerable.rb +1 -1
- data/lib/game_2d/serializable.rb +2 -13
- data/lib/game_2d/server_connection.rb +56 -24
- data/lib/game_2d/server_port.rb +14 -8
- data/lib/game_2d/transparency.rb +59 -0
- data/lib/game_2d/version.rb +1 -1
- data/lib/game_2d/zorder.rb +1 -1
- data/media/destination.png +0 -0
- data/media/destination.xcf +0 -0
- data/spec/client_engine_spec.rb +162 -71
- data/spec/game_space_spec.rb +8 -9
- metadata +11 -2
data/lib/game_2d/version.rb
CHANGED
data/lib/game_2d/zorder.rb
CHANGED
Binary file
|
Binary file
|
data/spec/client_engine_spec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'game'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
1
|
+
require 'set'
|
2
|
+
require 'game_2d/game'
|
3
|
+
require 'game_2d/game_client'
|
4
|
+
require 'game_2d/server_port'
|
5
|
+
require 'game_2d/client_engine'
|
6
|
+
require 'game_2d/client_connection'
|
6
7
|
|
7
8
|
IP_ADDRESS = '1.1.1.1'
|
8
9
|
CONNECTION_ID = 666
|
@@ -61,9 +62,12 @@ class FakeENetConnection
|
|
61
62
|
def initialize(*args)
|
62
63
|
$stderr.puts "FakeENetConnection.new(#{args.inspect})"
|
63
64
|
@queue = []
|
65
|
+
@online = false
|
64
66
|
end
|
67
|
+
def online?; @online; end
|
65
68
|
def connect(timeout)
|
66
69
|
$stderr.puts "FakeENetConnection.connect(#{timeout})"
|
70
|
+
@online = true
|
67
71
|
$fake_server_port.on_connection(CONNECTION_ID, IP_ADDRESS)
|
68
72
|
$fake_client_conn.on_connect
|
69
73
|
end
|
@@ -101,28 +105,38 @@ class FakeClientConnection < ClientConnection
|
|
101
105
|
end
|
102
106
|
|
103
107
|
class FakeGameWindow
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
include GameClient
|
109
|
+
attr_accessor :player_id, :conn, :engine, :text_input, :mouse_x, :mouse_y
|
110
|
+
|
111
|
+
def initialize(opts = {})
|
112
|
+
initialize_from_hash(opts)
|
113
|
+
@mouse_x = @mouse_y = @camera_x = @camera_y = 0
|
114
|
+
@dialog = nil
|
115
|
+
@buttons_down = Set.new
|
109
116
|
end
|
110
117
|
|
111
|
-
def
|
112
|
-
|
118
|
+
def _make_client_connection(*args)
|
119
|
+
FakeClientConnection.new(*args)
|
113
120
|
end
|
114
121
|
|
115
|
-
def
|
116
|
-
|
122
|
+
def display_message(*lines)
|
123
|
+
puts lines.collect {|l| "DISPLAY> #{l}"}.join("\n")
|
117
124
|
end
|
125
|
+
def display_message!(*lines); display_message(*lines); end
|
126
|
+
def caption=(c); puts "WINDOW CAPTION => '#{c}'"; end
|
127
|
+
|
128
|
+
def width; SCREEN_WIDTH; end
|
118
129
|
|
119
|
-
def
|
120
|
-
@
|
121
|
-
|
130
|
+
def press_button!(button)
|
131
|
+
@buttons_down << button
|
132
|
+
button_down(button)
|
133
|
+
end
|
134
|
+
def release_button!(button)
|
135
|
+
@buttons_down.delete button
|
122
136
|
end
|
123
137
|
|
124
|
-
def
|
125
|
-
@
|
138
|
+
def button_down?(button)
|
139
|
+
@buttons_down.include?(button)
|
126
140
|
end
|
127
141
|
end
|
128
142
|
|
@@ -137,6 +151,8 @@ describe FakeGame do
|
|
137
151
|
let(:cell_height) { 3 }
|
138
152
|
let(:self_check) { false }
|
139
153
|
let(:profile) { false }
|
154
|
+
let(:registry_broadcast_every) { nil }
|
155
|
+
let(:password_hash) { "0123456789abcdef" }
|
140
156
|
|
141
157
|
let(:game) { FakeGame.new(
|
142
158
|
:port => port_number,
|
@@ -149,87 +165,162 @@ describe FakeGame do
|
|
149
165
|
:profile => profile,
|
150
166
|
:registry_broadcast_every => registry_broadcast_every
|
151
167
|
) }
|
152
|
-
let(:
|
168
|
+
let(:key_size) { 128 }
|
169
|
+
let(:window) {
|
170
|
+
game
|
171
|
+
w = FakeGameWindow.new(:hostname => hostname, :port => port_number, :name => player_name, :key_size => key_size)
|
172
|
+
w.conn.start(password_hash).join
|
173
|
+
w
|
174
|
+
}
|
153
175
|
|
154
176
|
def update_both
|
155
177
|
game.update
|
178
|
+
# $stderr.puts "SERVER updated, TICK #{game.tick}"
|
156
179
|
window.update
|
180
|
+
# $stderr.puts "CLIENT updated"
|
157
181
|
end
|
158
182
|
|
183
|
+
# require 'pry'
|
159
184
|
def expect_spaces_to_match
|
185
|
+
# [
|
186
|
+
# game.space, window.space,
|
187
|
+
# game.space.instance_variable_get(:@grid),
|
188
|
+
# window.space.instance_variable_get(:@grid)
|
189
|
+
# ].pry unless window.space == game.space
|
160
190
|
expect(window.space).to eq(game.space)
|
161
191
|
end
|
162
192
|
|
163
|
-
|
164
|
-
|
165
|
-
it "is in sync after one update" do
|
166
|
-
window
|
193
|
+
it "is in sync after one update" do
|
194
|
+
window
|
167
195
|
|
168
|
-
|
196
|
+
# server sends its public key
|
197
|
+
# client sends encrypted password hash
|
198
|
+
update_both
|
199
|
+
expect(window.space).to be_nil
|
200
|
+
|
201
|
+
# server sends response to login
|
202
|
+
update_both
|
203
|
+
|
204
|
+
expect(game.tick).to eq(window.engine.tick)
|
205
|
+
expect_spaces_to_match
|
206
|
+
end
|
207
|
+
|
208
|
+
def player_on_server
|
209
|
+
game.space.players.first
|
210
|
+
end
|
211
|
+
|
212
|
+
it "is in sync after a fall and a build" do
|
213
|
+
window
|
214
|
+
|
215
|
+
expect(game.tick).to eq(-1)
|
216
|
+
expect(window.engine.tick).to be_nil
|
169
217
|
|
218
|
+
# server sends its public key
|
219
|
+
# client sends encrypted password hash
|
220
|
+
update_both
|
221
|
+
expect(window.space).to be_nil
|
222
|
+
|
223
|
+
# server sends response to login in time for tick 1
|
224
|
+
27.times do |n|
|
225
|
+
update_both
|
226
|
+
expect(game.tick).to eq(n+1)
|
227
|
+
expect(window.engine.tick).to eq(n+1)
|
170
228
|
expect_spaces_to_match
|
171
229
|
end
|
172
|
-
it "is in sync after a fall and a build" do
|
173
|
-
window
|
174
230
|
|
175
|
-
|
176
|
-
|
231
|
+
# Command generated at tick 28, scheduled for tick 34
|
232
|
+
window.press_button! Gosu::KbDown
|
177
233
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
expect_spaces_to_match
|
183
|
-
end
|
234
|
+
update_both
|
235
|
+
expect_spaces_to_match
|
236
|
+
expect(game.space.players.size).to eq(1)
|
237
|
+
expect(game.space.npcs.size).to eq(0)
|
184
238
|
|
185
|
-
|
239
|
+
plr = player_on_server
|
240
|
+
expect(plr.y).to eq(800)
|
241
|
+
expect(plr.falling?).to be false
|
242
|
+
|
243
|
+
5.times do # ticks 29 - 33
|
244
|
+
update_both
|
245
|
+
expect_spaces_to_match
|
186
246
|
expect(game.space.npcs.size).to eq(0)
|
247
|
+
end
|
187
248
|
|
188
|
-
|
189
|
-
|
249
|
+
# tick 34
|
250
|
+
window.release_button! Gosu::KbDown
|
251
|
+
update_both
|
252
|
+
expect(game.tick).to eq(34)
|
253
|
+
expect(game.space.npcs.size).to eq(1)
|
190
254
|
|
191
|
-
|
192
|
-
window.generate_move :build
|
255
|
+
expect_spaces_to_match
|
193
256
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
257
|
+
# Command generated at tick 35, scheduled for tick 41
|
258
|
+
window.press_button! Gosu::KbUp
|
259
|
+
6.times do # ticks 35 - 40
|
260
|
+
update_both
|
261
|
+
expect_spaces_to_match
|
262
|
+
expect(plr.y).to eq(800)
|
263
|
+
end
|
264
|
+
window.release_button! Gosu::KbUp
|
265
|
+
41.times do |n| # ticks 41 - 81
|
266
|
+
update_both
|
267
|
+
expect(plr.y).to eq(800 - (10 * n))
|
268
|
+
cplr = window.engine.space.players.first
|
269
|
+
binding.pry unless cplr == plr
|
270
|
+
expect(cplr).to eq(plr)
|
271
|
+
expect_spaces_to_match
|
272
|
+
end
|
273
|
+
end
|
199
274
|
|
200
|
-
|
275
|
+
it "stays in sync during a block-move" do
|
276
|
+
window
|
277
|
+
update_both
|
278
|
+
loop do
|
201
279
|
update_both
|
202
|
-
|
203
|
-
|
280
|
+
break if player_on_server.y == 800
|
281
|
+
end
|
204
282
|
|
205
|
-
|
283
|
+
window.press_button! Gosu::KbDown
|
284
|
+
update_both
|
285
|
+
window.release_button! Gosu::KbDown
|
286
|
+
window.press_button! Gosu::KbLeft
|
206
287
|
|
207
|
-
|
208
|
-
|
209
|
-
5.times do # ticks 34 - 38
|
210
|
-
update_both
|
211
|
-
$stderr.puts "TICK ##{game.tick}"
|
212
|
-
expect_spaces_to_match
|
213
|
-
expect(plr.y).to eq(800)
|
214
|
-
end
|
215
|
-
41.times do |n| # ticks 39 - 79
|
216
|
-
update_both
|
217
|
-
$stderr.puts "TICK ##{game.tick}"
|
218
|
-
expect(plr.y).to eq(800 - (10 * n))
|
219
|
-
cplr = window.engine.space.players.first
|
220
|
-
binding.pry unless cplr == plr
|
221
|
-
expect(cplr).to eq(plr)
|
222
|
-
expect_spaces_to_match
|
223
|
-
end
|
288
|
+
30.times do
|
289
|
+
update_both
|
224
290
|
end
|
225
|
-
|
226
|
-
|
227
|
-
let(:registry_broadcast_every) { 0 }
|
228
|
-
it "is in sync after one update" do
|
229
|
-
window
|
291
|
+
window.release_button! Gosu::KbLeft
|
292
|
+
loop do
|
230
293
|
update_both
|
294
|
+
break if player_on_server.x == 0
|
295
|
+
end
|
296
|
+
expect_spaces_to_match
|
297
|
+
|
298
|
+
blk = window.engine.space.npcs.first
|
299
|
+
expect([blk.x, blk.y]).to eq([400,800])
|
300
|
+
|
301
|
+
window.mouse_x, window.mouse_y = 50, 90
|
302
|
+
expect(window.mouse_entity_location).to eq([300, 700])
|
231
303
|
|
304
|
+
window.press_button! Gosu::MsRight
|
305
|
+
update_both
|
306
|
+
window.release_button! Gosu::MsRight
|
307
|
+
expect_spaces_to_match
|
308
|
+
|
309
|
+
in_a_row = 0
|
310
|
+
99.times do |n|
|
311
|
+
update_both
|
232
312
|
expect_spaces_to_match
|
313
|
+
|
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
|
317
|
+
in_a_row += 1
|
318
|
+
else
|
319
|
+
in_a_row = 0
|
320
|
+
end
|
321
|
+
break if in_a_row > 3
|
233
322
|
end
|
323
|
+
expect(in_a_row).to eq(4)
|
234
324
|
end
|
325
|
+
|
235
326
|
end
|
data/spec/game_space_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'set'
|
2
|
-
|
3
|
-
require 'game_space'
|
2
|
+
require 'game_2d/game_space'
|
4
3
|
|
5
4
|
describe GameSpace do
|
6
5
|
subject { GameSpace.new(nil).establish_world('lump', nil, 3, 3) }
|
@@ -59,18 +58,18 @@ describe GameSpace do
|
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
|
-
describe "#
|
61
|
+
describe "#cell_location_at_point" do
|
63
62
|
it "translates from a point to a cell" do
|
64
|
-
expect(subject.
|
65
|
-
expect(subject.
|
66
|
-
expect(subject.
|
67
|
-
expect(subject.
|
63
|
+
expect(subject.cell_location_at_point(399,399)).to eq([0,0])
|
64
|
+
expect(subject.cell_location_at_point(399,400)).to eq([0,1])
|
65
|
+
expect(subject.cell_location_at_point(401,399)).to eq([1,0])
|
66
|
+
expect(subject.cell_location_at_point(799,800)).to eq([1,2])
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
describe "#
|
70
|
+
describe "#cell_locations_at_points" do
|
72
71
|
it "translates from points to cells" do
|
73
|
-
expect(subject.
|
72
|
+
expect(subject.cell_locations_at_points(
|
74
73
|
[
|
75
74
|
[399,399],
|
76
75
|
[399,400],
|
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.
|
4
|
+
version: 0.0.2
|
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
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: facets
|
@@ -175,24 +175,31 @@ files:
|
|
175
175
|
- lib/game_2d/client_connection.rb
|
176
176
|
- lib/game_2d/client_engine.rb
|
177
177
|
- lib/game_2d/complex_move.rb
|
178
|
+
- lib/game_2d/encryption.rb
|
178
179
|
- lib/game_2d/entity.rb
|
179
180
|
- lib/game_2d/entity/block.rb
|
181
|
+
- lib/game_2d/entity/destination.rb
|
180
182
|
- lib/game_2d/entity/owned_entity.rb
|
181
183
|
- lib/game_2d/entity/pellet.rb
|
184
|
+
- lib/game_2d/entity/teleporter.rb
|
182
185
|
- lib/game_2d/entity/titanium.rb
|
183
186
|
- lib/game_2d/entity_constants.rb
|
184
187
|
- lib/game_2d/game.rb
|
188
|
+
- lib/game_2d/game_client.rb
|
185
189
|
- lib/game_2d/game_space.rb
|
186
190
|
- lib/game_2d/game_window.rb
|
187
191
|
- lib/game_2d/hash.rb
|
188
192
|
- lib/game_2d/menu.rb
|
193
|
+
- lib/game_2d/message.rb
|
189
194
|
- lib/game_2d/move/rise_up.rb
|
195
|
+
- lib/game_2d/password_dialog.rb
|
190
196
|
- lib/game_2d/player.rb
|
191
197
|
- lib/game_2d/registerable.rb
|
192
198
|
- lib/game_2d/serializable.rb
|
193
199
|
- lib/game_2d/server_connection.rb
|
194
200
|
- lib/game_2d/server_port.rb
|
195
201
|
- lib/game_2d/storage.rb
|
202
|
+
- lib/game_2d/transparency.rb
|
196
203
|
- lib/game_2d/version.rb
|
197
204
|
- lib/game_2d/wall.rb
|
198
205
|
- lib/game_2d/zorder.rb
|
@@ -203,6 +210,8 @@ files:
|
|
203
210
|
- media/brick.gif
|
204
211
|
- media/cement.gif
|
205
212
|
- media/crosshair.gif
|
213
|
+
- media/destination.png
|
214
|
+
- media/destination.xcf
|
206
215
|
- media/dirt.gif
|
207
216
|
- media/pellet.png
|
208
217
|
- media/pellet.xcf
|