Top Level Namespace
Defined Under Namespace
Classes: Client, ClientCfg, Config, Console, Game, GameLogic, GameMap, Gui, Particles, Player, Projectile, ServerCfg, ServerCore, String, TextField, ZipFileGenerator
Constant Summary collapse
- MENU_MAIN =
0- MENU_CONNECT =
1- MENU_USERNAME =
2- MOUSE_RADIUS =
200- SIDE_LEFT =
-1
- SIDE_RIGHT =
1- KEY_A =
4- KEY_B =
5- KEY_C =
6- KEY_D =
7- KEY_E =
8- KEY_F =
9- KEY_G =
10- KEY_H =
11- KEY_I =
12- KEY_J =
13- KEY_K =
14- KEY_L =
15- KEY_M =
16- KEY_N =
17- KEY_O =
18- KEY_P =
19- KEY_Q =
20- KEY_R =
21- KEY_S =
22- KEY_T =
23- KEY_U =
24- KEY_V =
25- KEY_W =
26- KEY_RIGHT =
79- KEY_LEFT =
80- KEY_DOWN =
81- KEY_UP =
82- SPAWN_X =
512- SPAWN_Y =
100- STATE_ERROR =
-2
- STATE_MENU =
-1
- STATE_OFFLINE =
0- STATE_CONNECTING =
1- STATE_DOWNLOADING =
2- STATE_INGAME =
3- STATE_REC_PLAYBACK =
4- DEBUG =
false- DEBUG_PHYSICS =
true- GAME_VERSION =
update GAME_VERSION on network protocol changes
'0015'- TILE_SIZE =
game
64- PLAYER_SIZE =
TILE_SIZE - 2
- MAP_WIDTH =
16- MAP_HEIGHT =
9- WINDOW_SIZE_X =
TILE_SIZE * MAP_WIDTH
- WINDOW_SIZE_Y =
TILE_SIZE * MAP_HEIGHT
- FULLHD_X =
1920- UI_SCALE =
WINDOW_SIZE_X.to_f / FULLHD_X
- SPEED =
TILE_SIZE- CMD_LEN =
networking
7- NAME_LEN =
9- MAX_MAPNAME_LEN =
43- MAX_CLIENTS =
12- PLAYER_PACKAGE_LEN =
16- CLIENT_PACKAGE_LEN =
used by server
11- SERVER_PACKAGE_LEN =
used by client
MAX_CLIENTS * PLAYER_PACKAGE_LEN + 4
- MAX_TIMEOUT =
5- MAX_TICK_SPEED =
the lower the faster client and server tick
0.01- NET_ERR_FULL =
MAX_TICK_SPEED = 0.07 MAX_TICK_SPEED = 0.005
'404'- NET_ERR_DISCONNECT =
'001'- NET_ERR_KICK =
'002'- NET_ERR_BAN =
'003'- NET_ERR_SERVER_OUTDATED =
'004'- NET_ERR_CLIENT_OUTDATED =
'005'- NET_ERR =
{ '404' => 'SERVER FULL', '001' => 'DISCONNECTED', '002' => 'KICKED', '003' => 'BANNED', '004' => 'SERVER OUTDATED', '005' => 'CLIENT OUTDATED' }.freeze
- CLIENT_PCK_TYPE =
{ error: '0', join: '1', move: '2', info: '3', cmd: '4' }.freeze
- SERVER_PCK_TYPE =
{ error: '0', update: '1', # TODO: find a good name here info: '3', cmd: '4', event: '5' }.freeze
- NET_INT_OFFSET =
33- NET_INT_BASE =
93- NET_MAX_INT =
NET_INT_BASE- NET_MIN_INT =
0- MAX_UNZIP_SIZE =
1MiB
1024**2
- MAP_VERSION =
1- MAP_FILES =
[ 'background.png', 'gametiles.txt', 'metadata.json' ].freeze
- NET_CLIENT =
0- PLAYER_ID =
1
Instance Method Summary collapse
-
#closest_interval_side(interval, point) ⇒ Object
Checks wether a given point is closer to the left or right step of a given interval.
- #draw_scoreboard(win_size_x, win_size_y, players, font, debug) ⇒ Object
- #frame_time ⇒ Object
- #net_error(err) ⇒ Object
-
#net_pack_bigint(int, size) ⇒ String
Converts a integer to multi character network string.
-
#net_pack_int(int) ⇒ String
Converts a integer to single character network string.
-
#net_unpack_bigint(net_int) ⇒ Integer
Converts a multi character network string to integer.
-
#net_unpack_int(net_int) ⇒ Integer
Converts a single character network string to integer.
- #save_read(socket, size) ⇒ Object
Instance Method Details
#closest_interval_side(interval, point) ⇒ Object
Checks wether a given point is closer to the left or right step of a given interval
12 13 14 |
# File 'lib/share/math.rb', line 12 def closest_interval_side(interval, point) (point % interval) * 2 < interval ? SIDE_LEFT : SIDE_RIGHT end |
#draw_scoreboard(win_size_x, win_size_y, players, font, debug) ⇒ Object
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 |
# File 'lib/client/scoreboard.rb', line 3 def draw_scoreboard(win_size_x, win_size_y, players, font, debug) # TODO: do not compute those every frame pad_x = win_size_x / 3 size_x = win_size_x / 3 pad_y = win_size_y / 6 size_y = win_size_y / 3 slot_height = size_y / MAX_CLIENTS text_scale = slot_height / 15 # background draw_rect(pad_x, pad_y, size_x, size_y + 3, 0xaa000000) # left border draw_rect(pad_x, pad_y, 3, size_y + 3, 0xaa000000) # right border draw_rect(pad_x + size_x - 3, pad_y, 3, size_y + 3, 0xaa000000) (0..MAX_CLIENTS).each do |i| # row borders draw_rect(pad_x + 3, pad_y + (i * slot_height), size_x - 6, 3, 0xaa000000) end players.each_with_index do |player, i| score_offset = text_scale * 10 * player.score.to_s.length dbg = 0 if debug dbg += 25 score_offset += 25 font.draw_text(player.id, pad_x + 5, pad_y + (i * slot_height), 0, text_scale, text_scale, 0xFF00FF00) end font.draw_text(player.name, dbg + pad_x + 5, pad_y + (i * slot_height), 0, text_scale, text_scale) font.draw_text(player.score, dbg + pad_x + size_x - score_offset, pad_y + (i * slot_height), 0, text_scale, text_scale) end end |
#frame_time ⇒ Object
21 22 23 24 25 |
# File 'lib/client/gui.rb', line 21 def frame_time diff = Time.now - $time_point $time_point = Time.now diff end |
#net_error(err) ⇒ Object
150 151 152 |
# File 'lib/share/network.rb', line 150 def net_error(err) raise "NetError: #{err}" end |
#net_pack_bigint(int, size) ⇒ String
Converts a integer to multi character network string
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/share/network.rb', line 110 def net_pack_bigint(int, size) sum = '' div = size - 1 (size - 1).times do buf = int / ((NET_MAX_INT + 1)**div) sum += net_pack_int(buf) int = int % ((NET_MAX_INT + 1)**div) div -= 1 end sum += net_pack_int(int) # TODO: check reminder and so on # throw and error when int is too big for size int /= NET_MAX_INT sum end |
#net_pack_int(int) ⇒ String
Converts a integer to single character network string
the base of the network is NET_INT_BASE so the number 93 is the last single character number represented as ‘~’
83 84 85 86 87 88 |
# File 'lib/share/network.rb', line 83 def net_pack_int(int) net_error "#{__method__}: '#{int}' is too low allowed range #{NET_MIN_INT}-#{NET_MAX_INT}" if int < NET_MIN_INT net_error "#{__method__}: '#{int}' is too high allowed range #{NET_MIN_INT}-#{NET_MAX_INT}" if int > NET_MAX_INT int += NET_INT_OFFSET int.chr end |
#net_unpack_bigint(net_int) ⇒ Integer
Converts a multi character network string to integer
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/share/network.rb', line 132 def net_unpack_bigint(net_int) sum = 0 net_int.chars.reverse.each_with_index do |c, i| if i.zero? sum = net_unpack_int(c) else sum += net_unpack_int(c) * (NET_MAX_INT + 1)**i end end sum end |
#net_unpack_int(net_int) ⇒ Integer
Converts a single character network string to integer
the base of the network is NET_INT_BASE so the number 93 is the last single character number represented as ‘~’
99 100 101 |
# File 'lib/share/network.rb', line 99 def net_unpack_int(net_int) net_int.ord - NET_INT_OFFSET end |
#save_read(socket, size) ⇒ Object
144 145 146 147 148 |
# File 'lib/share/network.rb', line 144 def save_read(socket, size) socket.read_nonblock(size) rescue IO::WaitReadable '' end |