chichilku3 14.0.2 → 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.
- checksums.yaml +4 -4
- data/bin/chichilku3 +1 -0
- data/bin/chichilku3-server +1 -0
- data/lib/client/chichilku3.rb +3 -1
- data/lib/client/client.rb +112 -59
- data/lib/client/client_cfg.rb +2 -1
- data/lib/client/gui.rb +219 -197
- data/lib/client/img/stick128/arm64/arm0.png +0 -0
- data/lib/client/img/stick128/arm64/arm1.png +0 -0
- data/lib/client/img/stick128/arm64/arm2.png +0 -0
- data/lib/client/img/stick128/arm64/arm3.png +0 -0
- data/lib/client/img/stick128/noarms/stick0.png +0 -0
- data/lib/client/img/stick128/noarms/stick1.png +0 -0
- data/lib/client/img/stick128/noarms/stick2.png +0 -0
- data/lib/client/img/stick128/noarms/stick3.png +0 -0
- data/lib/client/img/stick128/noarms/stick4.png +0 -0
- data/lib/client/img/stick128/noarms/stick5.png +0 -0
- data/lib/client/keys.rb +29 -0
- data/lib/client/particles.rb +54 -0
- data/lib/client/scoreboard.rb +29 -27
- data/lib/server/chichilku3_server.rb +169 -64
- data/lib/server/gamelogic.rb +107 -51
- data/lib/server/server_cfg.rb +2 -0
- data/lib/share/config.rb +21 -7
- data/lib/share/console.rb +22 -5
- data/lib/share/game_map.rb +279 -0
- data/lib/share/math.rb +14 -0
- data/lib/share/network.rb +47 -42
- data/lib/share/player.rb +168 -105
- data/lib/share/projectile.rb +97 -98
- data/lib/share/string.rb +24 -0
- data/server.json +3 -2
- metadata +44 -20
- data/lib/client/img/battle1024x576.png +0 -0
- data/lib/client/img/grass1024x512.png +0 -0
- data/lib/client/img/stick128/stick_noarms.png +0 -0
- data/lib/client/test.rb +0 -39
- data/lib/client/text.rb +0 -86
data/lib/share/projectile.rb
CHANGED
@@ -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
|
-
|
7
|
+
attr_accessor :x, :y, :dx, :dy, :r, :w, :h, :owner_id
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
22
|
+
def fire(x, y, dx, dy, owner)
|
23
|
+
return if @flying
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def hit
|
37
|
+
@flying = false
|
38
|
+
@x = 0
|
39
|
+
@y = 0
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
def tick(players)
|
43
|
+
return unless @flying
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
77
|
-
|
77
|
+
# NETWORK ROTATION
|
78
|
+
# 0 -> 4 <-
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
# ^
|
81
|
+
# 1 \ 5 \
|
82
|
+
# v
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
# ^
|
85
|
+
# 2 | 6 |
|
86
|
+
# v
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
data/lib/share/string.rb
ADDED
@@ -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
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:
|
4
|
+
version: 15.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ChillerDragon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
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:
|
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:
|
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:
|
56
|
+
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
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:
|
68
|
+
version: 3.9.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubyzip
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
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.
|
69
|
-
description:
|
70
|
-
|
71
|
-
|
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,16 +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
|
110
|
+
- lib/client/img/stick128/arm64/arm0.png
|
111
|
+
- lib/client/img/stick128/arm64/arm1.png
|
112
|
+
- lib/client/img/stick128/arm64/arm2.png
|
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
|
98
120
|
- lib/client/img/stick128/stick0.png
|
99
121
|
- lib/client/img/stick128/stick1.png
|
100
122
|
- lib/client/img/stick128/stick2.png
|
@@ -107,18 +129,20 @@ files:
|
|
107
129
|
- lib/client/img/stick128/stick_crouching3.png
|
108
130
|
- lib/client/img/stick128/stick_crouching4.png
|
109
131
|
- lib/client/img/stick128/stick_crouching5.png
|
110
|
-
- lib/client/
|
132
|
+
- lib/client/keys.rb
|
133
|
+
- lib/client/particles.rb
|
111
134
|
- lib/client/scoreboard.rb
|
112
|
-
- lib/client/test.rb
|
113
|
-
- lib/client/text.rb
|
114
135
|
- lib/server/chichilku3_server.rb
|
115
136
|
- lib/server/gamelogic.rb
|
116
137
|
- lib/server/server_cfg.rb
|
117
138
|
- lib/share/config.rb
|
118
139
|
- lib/share/console.rb
|
140
|
+
- lib/share/game_map.rb
|
141
|
+
- lib/share/math.rb
|
119
142
|
- lib/share/network.rb
|
120
143
|
- lib/share/player.rb
|
121
144
|
- lib/share/projectile.rb
|
145
|
+
- lib/share/string.rb
|
122
146
|
- server.json
|
123
147
|
homepage: https://github.com/chichilku/chichilku3
|
124
148
|
licenses:
|
@@ -132,14 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
156
|
requirements:
|
133
157
|
- - ">="
|
134
158
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
159
|
+
version: 2.5.0
|
136
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
161
|
requirements:
|
138
162
|
- - ">="
|
139
163
|
- !ruby/object:Gem::Version
|
140
164
|
version: '0'
|
141
165
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
166
|
+
rubygems_version: 3.2.32
|
143
167
|
signing_key:
|
144
168
|
specification_version: 4
|
145
169
|
summary: Stick battle game
|
Binary file
|
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
|