chichilku3 14.0.4 → 15.0.0

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.
@@ -1,115 +1,114 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'console'
2
4
 
5
+ # Projectile class handles arrow logic
3
6
  class Projectile
4
- attr_accessor :x, :y, :dx, :dy, :r, :w, :h, :owner_id
7
+ attr_accessor :x, :y, :dx, :dy, :r, :w, :h, :owner_id
5
8
 
6
- def initialize
7
- @x = 0
8
- @y = 0
9
- @dx = 0
10
- @dy = 0
11
- @w = 16
12
- @h = 16
13
- @owner = nil
14
- @left_owner = false
15
- @flying = false
16
- @tick = 0
17
- end
9
+ def initialize
10
+ @x = 0
11
+ @y = 0
12
+ @dx = 0
13
+ @dy = 0
14
+ @w = 16
15
+ @h = 16
16
+ @owner = nil
17
+ @left_owner = false
18
+ @flying = false
19
+ @tick = 0
20
+ end
18
21
 
19
- def fire(x, y, dx, dy, owner)
20
- return if @flying
22
+ def fire(x, y, dx, dy, owner)
23
+ return if @flying
21
24
 
22
- @x = x
23
- @y = y
24
- @dx = dx
25
- @dy = dy
26
- calc_rotation()
27
- @owner = owner
28
- @left_owner = false
29
- @flying = true
30
- $console.dbg "Projectile(x=#{x}, y=#{y}, dx=#{dx}, dy=#{dy})"
31
- end
25
+ @x = x
26
+ @y = y
27
+ @dx = dx
28
+ @dy = dy
29
+ calc_rotation
30
+ @owner = owner
31
+ @left_owner = false
32
+ @flying = true
33
+ $console.dbg "Projectile(x=#{x}, y=#{y}, dx=#{dx}, dy=#{dy})"
34
+ end
32
35
 
33
- def hit
34
- @flying = false
35
- @x = 0
36
- @y = 0
37
- end
36
+ def hit
37
+ @flying = false
38
+ @x = 0
39
+ @y = 0
40
+ end
38
41
 
39
- def tick(players)
40
- return unless @flying
42
+ def tick(players)
43
+ return unless @flying
41
44
 
42
- @tick += 1
43
- @x = @x + @dx
44
- @y = @y + @dy
45
- @dy += 1 if @tick % 3 == 0
46
- calc_rotation()
47
- check_hit(players)
48
- hit if @y > WINDOW_SIZE_Y
49
- hit if @x > WINDOW_SIZE_X
50
- hit if @x < 0
51
- end
45
+ @tick += 1
46
+ @x += @dx
47
+ @y += @dy
48
+ @dy += 1 if (@tick % 3).zero?
49
+ calc_rotation
50
+ check_hit(players)
51
+ hit if @y > WINDOW_SIZE_Y
52
+ hit if @x > WINDOW_SIZE_X
53
+ hit if @x.negative?
54
+ end
52
55
 
53
- def check_hit(players)
54
- owner_hit = false
55
- players.each do |player|
56
- if player.x + player.w > @x && player.x < @x + @w
57
- if player.y + player.h > @y && player.y < @y + @h
58
- if @owner.id == player.id
59
- owner_hit = true
60
- if @left_owner
61
- player.damage(@owner)
62
- hit()
63
- end
64
- else
65
- player.damage(@owner)
66
- hit()
67
- end
68
- end
69
- end
70
- end
71
- if owner_hit == false
72
- @left_owner = true
56
+ def check_hit(players)
57
+ owner_hit = false
58
+ players.each do |player|
59
+ next unless player.x + player.w > @x && player.x < @x + @w
60
+
61
+ if player.y + player.h > @y && player.y < @y + @h
62
+ if @owner.id == player.id
63
+ owner_hit = true
64
+ if @left_owner
65
+ player.damage(@owner)
66
+ hit
67
+ end
68
+ else
69
+ player.damage(@owner)
70
+ hit
73
71
  end
72
+ end
74
73
  end
74
+ @left_owner = true if owner_hit == false
75
+ end
75
76
 
76
- # NETWORK ROTATION
77
- # 0 -> 4 <-
77
+ # NETWORK ROTATION
78
+ # 0 -> 4 <-
78
79
 
79
- # ^
80
- # 1 \ 5 \
81
- # v
80
+ # ^
81
+ # 1 \ 5 \
82
+ # v
82
83
 
83
- # ^
84
- # 2 | 6 |
85
- # v
84
+ # ^
85
+ # 2 | 6 |
86
+ # v
86
87
 
87
- # ^
88
- # 3 / 7 /
89
- # v
90
- def calc_rotation
91
- if @dy > -3 && @dy < 3
92
- if @dx < 0
93
- @r = 4
94
- else
95
- @r = 0
96
- end
97
- elsif @dy < 0
98
- if @dx > -3 && @dx < 3
99
- @r = 6
100
- elsif @dx < 0
101
- @r = 5
102
- else
103
- @r = 7
104
- end
105
- else
106
- if @dx > -3 && @dx < 3
107
- @r = 2
108
- elsif @dx < 0
109
- @r = 3
110
- else
111
- @r = 1
112
- end
113
- end
114
- end
88
+ # ^
89
+ # 3 / 7 /
90
+ # v
91
+ def calc_rotation
92
+ @r = if @dy > -3 && @dy < 3
93
+ if @dx.negative?
94
+ 4
95
+ else
96
+ 0
97
+ end
98
+ elsif @dy.negative?
99
+ if @dx > -3 && @dx < 3
100
+ 6
101
+ elsif @dx.negative?
102
+ 5
103
+ else
104
+ 7
105
+ end
106
+ elsif @dx > -3 && @dx < 3
107
+ 2
108
+ elsif @dx.negative?
109
+ 3
110
+ else
111
+ 1
112
+ end
113
+ end
115
114
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # String color
4
+ class String
5
+ def colorize(color_code)
6
+ "\e[#{color_code}m#{self}\e[0m"
7
+ end
8
+
9
+ def red
10
+ colorize(31)
11
+ end
12
+
13
+ def green
14
+ colorize(32)
15
+ end
16
+
17
+ def yellow
18
+ colorize(33)
19
+ end
20
+
21
+ def pink
22
+ colorize(35)
23
+ end
24
+ end
data/server.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
- "port": 9900
2
+ "port": 9900,
3
+ "max_clients_per_ip": 2,
4
+ "map": ""
3
5
  }
4
-
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chichilku3
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.0.4
4
+ version: 15.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChillerDragon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fileutils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: gosu
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: 0.15.2
33
+ version: 1.4.3
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: 0.15.2
40
+ version: 1.4.3
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: os
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,36 +53,36 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: 1.0.1
41
55
  - !ruby/object:Gem::Dependency
42
- name: fileutils
56
+ name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 1.2.0
61
+ version: 3.9.0
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 1.2.0
68
+ version: 3.9.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec
70
+ name: rubyzip
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 3.9.0
75
+ version: 2.3.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 3.9.0
69
- description: Simple 2d online multiplayer stick figure battle game using the gosu
70
- (SDL2 based) gem for client side graphics. The network protocol is tcp based and
71
- only using ASCII printable characters.
82
+ version: 2.3.0
83
+ description: |2
84
+ Simple 2d online multiplayer stick figure battle game using the gosu (SDL2 based) gem for client side graphics.
85
+ The network protocol is tcp based and only using ASCII printable characters.
72
86
  email: ChillerDragon@gmail.com
73
87
  executables:
74
88
  - chichilku3
@@ -85,20 +99,24 @@ files:
85
99
  - lib/client/gui.rb
86
100
  - lib/client/img/arrow64.png
87
101
  - lib/client/img/background1024x512.png
88
- - lib/client/img/battle1024x576.png
89
102
  - lib/client/img/bow64/bow0.png
90
103
  - lib/client/img/bow64/bow1.png
91
104
  - lib/client/img/bow64/bow2.png
92
105
  - lib/client/img/bow64/bow3.png
93
106
  - lib/client/img/connecting1024x512.png
94
107
  - lib/client/img/crosshair128x128.png
95
- - lib/client/img/grass1024x512.png
96
108
  - lib/client/img/grey128.png
97
109
  - lib/client/img/menu1920x1080.png
98
110
  - lib/client/img/stick128/arm64/arm0.png
99
111
  - lib/client/img/stick128/arm64/arm1.png
100
112
  - lib/client/img/stick128/arm64/arm2.png
101
113
  - lib/client/img/stick128/arm64/arm3.png
114
+ - lib/client/img/stick128/noarms/stick0.png
115
+ - lib/client/img/stick128/noarms/stick1.png
116
+ - lib/client/img/stick128/noarms/stick2.png
117
+ - lib/client/img/stick128/noarms/stick3.png
118
+ - lib/client/img/stick128/noarms/stick4.png
119
+ - lib/client/img/stick128/noarms/stick5.png
102
120
  - lib/client/img/stick128/stick0.png
103
121
  - lib/client/img/stick128/stick1.png
104
122
  - lib/client/img/stick128/stick2.png
@@ -111,24 +129,26 @@ files:
111
129
  - lib/client/img/stick128/stick_crouching3.png
112
130
  - lib/client/img/stick128/stick_crouching4.png
113
131
  - lib/client/img/stick128/stick_crouching5.png
114
- - lib/client/img/stick128/stick_noarms.png
132
+ - lib/client/keys.rb
133
+ - lib/client/particles.rb
115
134
  - lib/client/scoreboard.rb
116
- - lib/client/test.rb
117
- - lib/client/text.rb
118
135
  - lib/server/chichilku3_server.rb
119
136
  - lib/server/gamelogic.rb
120
137
  - lib/server/server_cfg.rb
121
138
  - lib/share/config.rb
122
139
  - lib/share/console.rb
140
+ - lib/share/game_map.rb
141
+ - lib/share/math.rb
123
142
  - lib/share/network.rb
124
143
  - lib/share/player.rb
125
144
  - lib/share/projectile.rb
145
+ - lib/share/string.rb
126
146
  - server.json
127
147
  homepage: https://github.com/chichilku/chichilku3
128
148
  licenses:
129
149
  - Unlicense
130
150
  metadata: {}
131
- post_install_message:
151
+ post_install_message:
132
152
  rdoc_options: []
133
153
  require_paths:
134
154
  - lib
@@ -136,15 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
156
  requirements:
137
157
  - - ">="
138
158
  - !ruby/object:Gem::Version
139
- version: '0'
159
+ version: 2.5.0
140
160
  required_rubygems_version: !ruby/object:Gem::Requirement
141
161
  requirements:
142
162
  - - ">="
143
163
  - !ruby/object:Gem::Version
144
164
  version: '0'
145
165
  requirements: []
146
- rubygems_version: 3.0.3
147
- signing_key:
166
+ rubygems_version: 3.2.32
167
+ signing_key:
148
168
  specification_version: 4
149
169
  summary: Stick battle game
150
170
  test_files: []
Binary file
Binary file
data/lib/client/test.rb DELETED
@@ -1,39 +0,0 @@
1
- require_relative '../share/player'
2
-
3
- def server_package_to_player_strs(slots, data)
4
- players = []
5
- slots.times do |index|
6
- players[index] = data[index * 8..index * 8 + 7]
7
- end
8
- players
9
- end
10
-
11
- def player_strs_to_objects(player_strs)
12
- players = []
13
- player_strs.each do |player_str|
14
- id = player_str[0..1].to_i
15
- x = player_str[2..4].to_i
16
- y = player_str[5..7].to_i
17
- # puts "id: #{id} x: #{x} y: #{y}"
18
- players << Player.new(id, x, y) unless id.zero?
19
- end
20
- players
21
- end
22
-
23
- def server_package_to_player_array(data)
24
- # /(?<count>\d{2})(?<player>(?<id>\d{2})(?<x>\d{3})(?<y>\d{3}))/
25
- slots = data[0..1].to_i # save slots
26
- data = data[2..-1] # cut slots off
27
- players = server_package_to_player_strs(slots, data)
28
- # puts players
29
- player_strs_to_objects(players)
30
- end
31
-
32
- # 3 players
33
- pl3 = '03011001010220020203300303'
34
- p server_package_to_player_array(pl3)
35
- p server_package_to_player_array(pl3).count
36
- # 2 players (first has id 00 -> offline)
37
- pl2 = '03001001010220020203300303'
38
- p server_package_to_player_array(pl2)
39
- p server_package_to_player_array(pl2).count
data/lib/client/text.rb DELETED
@@ -1,86 +0,0 @@
1
- # https://github.com/gosu/gosu-examples/blob/master/examples/text_input.rb
2
- require "gosu"
3
-
4
- class TextField < Gosu::TextInput
5
- FONT = Gosu::Font.new(60)
6
- WIDTH = 800
7
- LENGTH_LIMIT = 20
8
- PADDING = 5
9
-
10
- INACTIVE_COLOR = 0xcc_666666
11
- ACTIVE_COLOR = 0xcc_555555
12
- SELECTION_COLOR = 0xcc_444444
13
- CARET_COLOR = 0xff_ffffff
14
-
15
- attr_reader :x, :y
16
-
17
- def initialize(window, x, y)
18
- # It's important to call the inherited constructor.
19
- super()
20
-
21
- @window, @x, @y = window, x, y
22
-
23
- # Start with a self-explanatory text in each field.
24
- self.text = "Click to edit"
25
- end
26
-
27
- # In this example, we use the filter method to prevent the user from entering a text that exceeds
28
- # the length limit. However, you can also use this to blacklist certain characters, etc.
29
- def filter new_text
30
- allowed_length = [LENGTH_LIMIT - text.length, 0].max
31
- new_text[0, allowed_length]
32
- end
33
-
34
- def draw(z)
35
- # 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
41
- # ChillerDragon's epic shadow to at least have edited the stolen sample a lil bit
42
- Gosu.draw_rect (x - PADDING) + 5, (y - PADDING) + 5, WIDTH + 2 * PADDING, height + 2 * PADDING, INACTIVE_COLOR, z
43
- Gosu.draw_rect x - PADDING, y - PADDING, WIDTH + 2 * PADDING, height + 2 * PADDING, color, z
44
- Gosu.draw_rect x - PADDING, y - PADDING, WIDTH + 2 * PADDING, height + 2 * PADDING, color, z
45
-
46
- # 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])
49
- sel_w = pos_x - sel_x
50
-
51
- # Draw the selection background, if any. (If not, sel_x and pos_x will be
52
- # the same value, making this a no-op call.)
53
- Gosu.draw_rect sel_x, y, sel_w, height, SELECTION_COLOR, z
54
-
55
- # 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
59
-
60
- # Finally, draw the text itself!
61
- FONT.draw_text self.text, x, y, z
62
- end
63
-
64
- def height
65
- FONT.height
66
- end
67
-
68
- # Hit-test for selecting a text field with the mouse.
69
- def under_mouse?
70
- @window.mouse_x > x - PADDING and @window.mouse_x < x + WIDTH + PADDING and
71
- @window.mouse_y > y - PADDING and @window.mouse_y < y + height + PADDING
72
- 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
- end