chichilku3 14.0.3 → 15.0.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/bin/chichilku3 +1 -0
  3. data/bin/chichilku3-server +1 -0
  4. data/lib/client/chichilku3.rb +3 -1
  5. data/lib/client/client.rb +112 -59
  6. data/lib/client/client_cfg.rb +2 -1
  7. data/lib/client/gui.rb +219 -197
  8. data/lib/client/img/stick128/arm64/arm0.png +0 -0
  9. data/lib/client/img/stick128/arm64/arm1.png +0 -0
  10. data/lib/client/img/stick128/arm64/arm2.png +0 -0
  11. data/lib/client/img/stick128/arm64/arm3.png +0 -0
  12. data/lib/client/img/stick128/noarms/stick0.png +0 -0
  13. data/lib/client/img/stick128/noarms/stick1.png +0 -0
  14. data/lib/client/img/stick128/noarms/stick2.png +0 -0
  15. data/lib/client/img/stick128/noarms/stick3.png +0 -0
  16. data/lib/client/img/stick128/noarms/stick4.png +0 -0
  17. data/lib/client/img/stick128/noarms/stick5.png +0 -0
  18. data/lib/client/keys.rb +29 -0
  19. data/lib/client/particles.rb +54 -0
  20. data/lib/client/scoreboard.rb +29 -27
  21. data/lib/{client → external/gosu}/text.rb +29 -38
  22. data/lib/external/rubyzip/recursive.rb +58 -0
  23. data/lib/server/chichilku3_server.rb +169 -64
  24. data/lib/server/gamelogic.rb +107 -51
  25. data/lib/server/server_cfg.rb +2 -0
  26. data/lib/share/config.rb +21 -7
  27. data/lib/share/console.rb +22 -5
  28. data/lib/share/game_map.rb +279 -0
  29. data/lib/share/math.rb +14 -0
  30. data/lib/share/network.rb +47 -42
  31. data/lib/share/player.rb +168 -105
  32. data/lib/share/projectile.rb +97 -98
  33. data/lib/share/string.rb +24 -0
  34. data/server.json +3 -2
  35. metadata +49 -23
  36. data/lib/client/img/battle1024x576.png +0 -0
  37. data/lib/client/img/grass1024x512.png +0 -0
  38. data/lib/client/img/stick128/stick_noarms.png +0 -0
  39. data/lib/client/test.rb +0 -39
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ KEY_A = 4
4
+ KEY_B = 5
5
+ KEY_C = 6
6
+ KEY_D = 7
7
+ KEY_E = 8
8
+ KEY_F = 9
9
+ KEY_G = 10
10
+ KEY_H = 11
11
+ KEY_I = 12
12
+ KEY_J = 13
13
+ KEY_K = 14
14
+ KEY_L = 15
15
+ KEY_M = 16
16
+ KEY_N = 17
17
+ KEY_O = 18
18
+ KEY_P = 19
19
+ KEY_Q = 20
20
+ KEY_R = 21
21
+ KEY_S = 22
22
+ KEY_T = 23
23
+ KEY_U = 24
24
+ KEY_V = 25
25
+ KEY_W = 26
26
+ KEY_RIGHT = 79
27
+ KEY_LEFT = 80
28
+ KEY_DOWN = 81
29
+ KEY_UP = 82
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Renderer for moving textures like grass
4
+ class Particles
5
+ def initialize(console)
6
+ @console = console
7
+ @grass_img = Gosu::Image.new(img('grass/single_64.png'))
8
+ end
9
+
10
+ def draw(game_map, players)
11
+ # y = MAP_HEIGHT * TILE_SIZE - TILE_SIZE * 3
12
+ # y += TILE_SIZE / 2
13
+ # y += 2
14
+ # grass(0, TILE_SIZE * 5, y, move_x, move_y)
15
+
16
+ game_map.grass_rows.each do |grass_row|
17
+ grass(grass_row[:x1], grass_row[:x2], grass_row[:y], players)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def img(path)
24
+ File.join(File.dirname(__FILE__), '../../lib/client/img/', path)
25
+ end
26
+
27
+ def grass(x1, x2, y, players, density = 3)
28
+ # @console.log(x1.to_s + " " + x2.to_s + " " + y.to_s + " " + move_x.to_s + " " + move_y.to_s)
29
+ srand(0)
30
+ x = x1
31
+ amount = (x2 - x1) / density
32
+ amount.times do
33
+ x += density
34
+ rot = rand(-8..8)
35
+ move = false
36
+ players.each do |player|
37
+ next unless player.x > x - 10 && player.x < x + 10 && player.y > y - 128 && player.y < y + 128
38
+
39
+ move = true
40
+ break
41
+ end
42
+ if move
43
+ if rot.positive?
44
+ rot += 2
45
+ else
46
+ rot -= 2
47
+ end
48
+ @grass_img.draw_rot(x + rand(-3..3), y + rand(0..3) + 1, 0, rot)
49
+ else
50
+ @grass_img.draw_rot(x + rand(-3..3), y + rand(0..3), 0, rot)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,31 +1,33 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  def draw_scoreboard(win_size_x, win_size_y, players, font, debug)
3
- # TODO: do not compute those every frame
4
- padX = win_size_x / 3
5
- sizeX = win_size_x / 3
6
- padY = win_size_y / 6
7
- sizeY = win_size_y / 3
8
- slot_height = sizeY / MAX_CLIENTS
9
- text_scale = slot_height / 15
10
- # background
11
- draw_rect(padX, padY, sizeX, sizeY+3, 0xaa000000)
12
- # left border
13
- draw_rect(padX, padY, 3, sizeY+3, 0xaa000000)
14
- # right border
15
- draw_rect(padX + sizeX - 3, padY, 3, sizeY+3, 0xaa000000)
16
- (0..MAX_CLIENTS).each do |i|
17
- # row borders
18
- draw_rect(padX + 3, padY + (i * slot_height), sizeX - 6, 3, 0xaa000000)
19
- end
20
- players.each_with_index do | player, i |
21
- score_offset = text_scale * 10 * player.score.to_s.length
22
- dbg = 0
23
- if debug
24
- dbg += 25
25
- score_offset += 25
26
- font.draw_text(player.id, padX + 5, padY + (i * slot_height), 0, text_scale, text_scale, 0xFF00FF00)
27
- end
28
- font.draw_text(player.name, dbg + padX + 5, padY + (i * slot_height), 0, text_scale, text_scale)
29
- font.draw_text(player.score, dbg + padX + sizeX - score_offset, padY + (i * slot_height), 0, text_scale, text_scale)
4
+ # TODO: do not compute those every frame
5
+ pad_x = win_size_x / 3
6
+ size_x = win_size_x / 3
7
+ pad_y = win_size_y / 6
8
+ size_y = win_size_y / 3
9
+ slot_height = size_y / MAX_CLIENTS
10
+ text_scale = slot_height / 15
11
+ # background
12
+ draw_rect(pad_x, pad_y, size_x, size_y + 3, 0xaa000000)
13
+ # left border
14
+ draw_rect(pad_x, pad_y, 3, size_y + 3, 0xaa000000)
15
+ # right border
16
+ draw_rect(pad_x + size_x - 3, pad_y, 3, size_y + 3, 0xaa000000)
17
+ (0..MAX_CLIENTS).each do |i|
18
+ # row borders
19
+ draw_rect(pad_x + 3, pad_y + (i * slot_height), size_x - 6, 3, 0xaa000000)
20
+ end
21
+ players.each_with_index do |player, i|
22
+ score_offset = text_scale * 10 * player.score.to_s.length
23
+ dbg = 0
24
+ if debug
25
+ dbg += 25
26
+ score_offset += 25
27
+ font.draw_text(player.id, pad_x + 5, pad_y + (i * slot_height), 0, text_scale, text_scale, 0xFF00FF00)
30
28
  end
29
+ font.draw_text(player.name, dbg + pad_x + 5, pad_y + (i * slot_height), 0, text_scale, text_scale)
30
+ font.draw_text(player.score, dbg + pad_x + size_x - score_offset, pad_y + (i * slot_height), 0, text_scale,
31
+ text_scale)
32
+ end
31
33
  end
@@ -1,66 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # https://github.com/gosu/gosu-examples/blob/master/examples/text_input.rb
2
- require "gosu"
4
+ # Gosu is released under the MIT license.
5
+ require 'gosu'
3
6
 
7
+ # Input text boxes
4
8
  class TextField < Gosu::TextInput
5
9
  FONT = Gosu::Font.new(60)
6
10
  WIDTH = 800
7
11
  LENGTH_LIMIT = 20
8
12
  PADDING = 5
9
-
13
+
10
14
  INACTIVE_COLOR = 0xcc_666666
11
15
  ACTIVE_COLOR = 0xcc_555555
12
16
  SELECTION_COLOR = 0xcc_444444
13
17
  CARET_COLOR = 0xff_ffffff
14
-
18
+
15
19
  attr_reader :x, :y
16
-
20
+
17
21
  def initialize(window, x, y)
18
22
  # It's important to call the inherited constructor.
19
23
  super()
20
-
21
- @window, @x, @y = window, x, y
22
-
24
+
25
+ @window = window
26
+ @x = x
27
+ @y = y
28
+
23
29
  # Start with a self-explanatory text in each field.
24
- self.text = "Click to edit"
30
+ self.text = 'Click to edit'
25
31
  end
26
-
32
+
27
33
  # In this example, we use the filter method to prevent the user from entering a text that exceeds
28
34
  # the length limit. However, you can also use this to blacklist certain characters, etc.
29
- def filter new_text
35
+ def filter(new_text)
30
36
  allowed_length = [LENGTH_LIMIT - text.length, 0].max
31
37
  new_text[0, allowed_length]
32
38
  end
33
-
39
+
34
40
  def draw(z)
35
41
  # Change the background colour if this is the currently selected text field.
36
- if @window.text_input == self
37
- color = ACTIVE_COLOR
38
- else
39
- color = INACTIVE_COLOR
40
- end
42
+ color = if @window.text_input == self
43
+ ACTIVE_COLOR
44
+ else
45
+ INACTIVE_COLOR
46
+ end
41
47
  # ChillerDragon's epic shadow to at least have edited the stolen sample a lil bit
42
48
  Gosu.draw_rect (x - PADDING) + 5, (y - PADDING) + 5, WIDTH + 2 * PADDING, height + 2 * PADDING, INACTIVE_COLOR, z
43
49
  Gosu.draw_rect x - PADDING, y - PADDING, WIDTH + 2 * PADDING, height + 2 * PADDING, color, z
44
50
  Gosu.draw_rect x - PADDING, y - PADDING, WIDTH + 2 * PADDING, height + 2 * PADDING, color, z
45
-
51
+
46
52
  # Calculate the position of the caret and the selection start.
47
- pos_x = x + FONT.text_width(self.text[0...self.caret_pos])
48
- sel_x = x + FONT.text_width(self.text[0...self.selection_start])
53
+ pos_x = x + FONT.text_width(text[0...caret_pos])
54
+ sel_x = x + FONT.text_width(text[0...selection_start])
49
55
  sel_w = pos_x - sel_x
50
-
56
+
51
57
  # Draw the selection background, if any. (If not, sel_x and pos_x will be
52
58
  # the same value, making this a no-op call.)
53
59
  Gosu.draw_rect sel_x, y, sel_w, height, SELECTION_COLOR, z
54
60
 
55
61
  # Draw the caret if this is the currently selected field.
56
- if @window.text_input == self
57
- Gosu.draw_line pos_x, y, CARET_COLOR, pos_x, y + height, CARET_COLOR, z
58
- end
62
+ Gosu.draw_line pos_x, y, CARET_COLOR, pos_x, y + height, CARET_COLOR, z if @window.text_input == self
59
63
 
60
64
  # Finally, draw the text itself!
61
- FONT.draw_text self.text, x, y, z
65
+ FONT.draw_text text, x, y, z
62
66
  end
63
-
67
+
64
68
  def height
65
69
  FONT.height
66
70
  end
@@ -70,17 +74,4 @@ class TextField < Gosu::TextInput
70
74
  @window.mouse_x > x - PADDING and @window.mouse_x < x + WIDTH + PADDING and
71
75
  @window.mouse_y > y - PADDING and @window.mouse_y < y + height + PADDING
72
76
  end
73
-
74
- # Tries to move the caret to the position specifies by mouse_x
75
- def move_caret_to_mouse
76
- # Test character by character
77
- 1.upto(self.text.length) do |i|
78
- if @window.mouse_x < x + FONT.text_width(text[0...i])
79
- self.caret_pos = self.selection_start = i - 1;
80
- return
81
- end
82
- end
83
- # Default case: user must have clicked the right edge
84
- self.caret_pos = self.selection_start = self.text.length
85
- end
86
77
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://github.com/rubyzip/rubyzip/blob/9d891f7353e66052283562d3e252fe380bb4b199/samples/example_recursive.rb
4
+ # http://www.ruby-lang.org/en/about/license.txt
5
+ require 'zip'
6
+
7
+ # This is a simple example which uses rubyzip to
8
+ # recursively generate a zip file from the contents of
9
+ # a specified directory. The directory itself is not
10
+ # included in the archive, rather just its contents.
11
+ #
12
+ # Usage:
13
+ # directory_to_zip = "/tmp/input"
14
+ # output_file = "/tmp/out.zip"
15
+ # zf = ZipFileGenerator.new(directory_to_zip, output_file)
16
+ # zf.write()
17
+ class ZipFileGenerator
18
+ # Initialize with the directory to zip and the location of the output archive.
19
+ def initialize(input_dir, output_file)
20
+ @input_dir = input_dir
21
+ @output_file = output_file
22
+ end
23
+
24
+ # Zip the input directory.
25
+ def write
26
+ entries = Dir.entries(@input_dir) - %w[. ..]
27
+
28
+ ::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile|
29
+ write_entries entries, '', zipfile
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # A helper method to make the recursion work.
36
+ def write_entries(entries, path, zipfile)
37
+ entries.each do |e|
38
+ zipfile_path = path == '' ? e : File.join(path, e)
39
+ disk_file_path = File.join(@input_dir, zipfile_path)
40
+
41
+ if File.directory? disk_file_path
42
+ recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
43
+ else
44
+ put_into_archive(disk_file_path, zipfile, zipfile_path)
45
+ end
46
+ end
47
+ end
48
+
49
+ def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
50
+ zipfile.mkdir zipfile_path
51
+ subdir = Dir.entries(disk_file_path) - %w[. ..]
52
+ write_entries subdir, zipfile_path, zipfile
53
+ end
54
+
55
+ def put_into_archive(disk_file_path, zipfile, zipfile_path)
56
+ zipfile.add(zipfile_path, disk_file_path)
57
+ end
58
+ end