pugnacious_juices 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/{pugnacious.rb → pugnacious} +1 -1
- data/lib/pugnacious/application.rb +7 -5
- data/lib/pugnacious/fight_scene.rb +13 -40
- data/lib/pugnacious/game_map.rb +34 -6
- data/lib/pugnacious/molecule.rb +3 -3
- data/lib/pugnacious/movable.rb +87 -42
- data/lib/pugnacious/player.rb +4 -26
- data/lib/pugnacious/version.rb +1 -1
- metadata +5 -5
@@ -1,15 +1,17 @@
|
|
1
1
|
module Pugnacious
|
2
2
|
MAP_SIZE = 500
|
3
|
-
MOLECULE_SIZE =
|
3
|
+
MOLECULE_SIZE = 3
|
4
4
|
|
5
|
-
class Application
|
6
|
-
|
5
|
+
class Application
|
6
|
+
attr_accessor :number_of_molecules
|
7
|
+
def self.run(argv)
|
7
8
|
Ray.game "Pugnacious Juices", :size => [MAP_SIZE, MAP_SIZE] do
|
8
|
-
frames_per_second = 16
|
9
9
|
register { add_hook :quit, method(:exit!) }
|
10
|
+
|
11
|
+
number_of_molecules = argv[0].to_i | 250
|
10
12
|
|
11
13
|
FightScene.bind(self)
|
12
|
-
|
14
|
+
push_scene(:fight_scene, number_of_molecules)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -2,53 +2,22 @@ module Pugnacious
|
|
2
2
|
class FightScene < Ray::Scene
|
3
3
|
scene_name :fight_scene
|
4
4
|
|
5
|
-
def setup
|
6
|
-
@gc_counter = 0
|
7
|
-
#self.frames_per_second = 5
|
5
|
+
def setup(number_of_molecules)
|
8
6
|
@player1 = Player.new(
|
9
7
|
color: Ray::Color.blue,
|
10
8
|
position: [0, 0],
|
11
|
-
control_keys:
|
9
|
+
control_keys: {:up => :up, :right => :right, :down => :down, :left => :left})
|
12
10
|
|
13
11
|
@player2 = Player.new(
|
14
12
|
color: Ray::Color.red,
|
15
13
|
position: [0, 0],
|
16
|
-
control_keys:
|
14
|
+
control_keys: {:up => :w, :right => :d, :down => :s, :left => :a})
|
17
15
|
|
18
|
-
@player2.pointer.pos = [
|
19
|
-
@player1.pointer.pos = [
|
16
|
+
@player2.pointer.pos = [50, 300]
|
17
|
+
@player1.pointer.pos = [450, 300]
|
20
18
|
|
21
19
|
@game_map = GameMap.generate_empty_map(MAP_SIZE, MAP_SIZE)
|
22
|
-
|
23
|
-
@molecules = []
|
24
|
-
|
25
|
-
@game_map.size.times do |i|
|
26
|
-
@molecules << Molecule.new(
|
27
|
-
:player => @player1,
|
28
|
-
:rival => @player2,
|
29
|
-
:molecules => @molecules,
|
30
|
-
:pos => [i,10],
|
31
|
-
:map => @game_map)
|
32
|
-
@molecules << Molecule.new(
|
33
|
-
:player => @player1,
|
34
|
-
:rival => @player2,
|
35
|
-
:molecules => @molecules,
|
36
|
-
:pos => [i,11],
|
37
|
-
:map => @game_map)
|
38
|
-
|
39
|
-
@molecules << Molecule.new(
|
40
|
-
:player => @player2,
|
41
|
-
:rival => @player1,
|
42
|
-
:molecules => @molecules,
|
43
|
-
:pos => [i,72],
|
44
|
-
:map => @game_map)
|
45
|
-
@molecules << Molecule.new(
|
46
|
-
:player => @player2,
|
47
|
-
:rival => @player1,
|
48
|
-
:molecules => @molecules,
|
49
|
-
:pos => [i,75],
|
50
|
-
:map => @game_map)
|
51
|
-
end
|
20
|
+
@molecules = GameMap.generate_molecules(@game_map, @player1, @player2, number_of_molecules)
|
52
21
|
|
53
22
|
@players = [@player1, @player2]
|
54
23
|
end
|
@@ -56,18 +25,22 @@ module Pugnacious
|
|
56
25
|
def register
|
57
26
|
always do
|
58
27
|
@players.each do |player|
|
59
|
-
player.control_keys.each do |direction|
|
28
|
+
player.control_keys.values.each do |direction|
|
60
29
|
if holding? direction then player.move direction end
|
61
30
|
end
|
62
31
|
end
|
63
32
|
|
64
|
-
@molecules.each &:move
|
33
|
+
@molecules.each &:move
|
34
|
+
if @molecules.all?{|m| m.player == @player1} or @molecules.all?{|m| m.player == @player2}
|
35
|
+
@winner = text("You are the winner!!", :at => [200, 200], :size => 30)
|
36
|
+
end
|
65
37
|
end
|
66
38
|
end
|
67
39
|
|
68
40
|
def render(window)
|
69
41
|
@molecules.each { |molecule| window.draw molecule.body}
|
70
42
|
@players.each { |player| window.draw player.pointer }
|
43
|
+
window.draw(@winner) unless @winner.nil?
|
71
44
|
end
|
72
45
|
|
73
46
|
def clean_up
|
@@ -78,6 +51,6 @@ module Pugnacious
|
|
78
51
|
@players = nil
|
79
52
|
|
80
53
|
Ray::ImageSet.clear
|
81
|
-
end
|
54
|
+
end
|
82
55
|
end
|
83
56
|
end
|
data/lib/pugnacious/game_map.rb
CHANGED
@@ -1,21 +1,49 @@
|
|
1
1
|
module Pugnacious
|
2
2
|
class GameMap
|
3
|
-
attr_accessor :map
|
4
|
-
|
5
|
-
def initialize(number_of_lines, number_of_columns)
|
6
|
-
generate_empty_map(number_of_lines, number_of_columns)
|
7
|
-
end
|
8
3
|
|
9
4
|
def self.generate_empty_map(number_of_lines, number_of_columns)
|
10
5
|
game_map = []
|
11
6
|
(number_of_columns/MOLECULE_SIZE).times do |l|
|
12
7
|
game_map << []
|
13
8
|
(number_of_lines/MOLECULE_SIZE).times do |c|
|
14
|
-
game_map[l][c] =
|
9
|
+
game_map[l][c] = [l, c]
|
15
10
|
end
|
16
11
|
end
|
17
12
|
game_map
|
18
13
|
end
|
19
14
|
|
15
|
+
def self.generate_molecules(map, player1, player2, number)
|
16
|
+
molecules = []
|
17
|
+
|
18
|
+
positions = map.flatten(1).sample(number)
|
19
|
+
|
20
|
+
positions[0..(number/2)].each do |p|
|
21
|
+
molecules << Molecule.new(
|
22
|
+
:player => player1,
|
23
|
+
:rival => player2,
|
24
|
+
:molecules => molecules,
|
25
|
+
:pos => p,
|
26
|
+
:map => map)
|
27
|
+
end
|
28
|
+
|
29
|
+
positions[(number/2)..number].each do |p|
|
30
|
+
molecules << Molecule.new(
|
31
|
+
:player => player2,
|
32
|
+
:rival => player1,
|
33
|
+
:molecules => molecules,
|
34
|
+
:pos => p,
|
35
|
+
:map => map)
|
36
|
+
end
|
37
|
+
|
38
|
+
map.each do |l|
|
39
|
+
l.each_with_index do |c, index|
|
40
|
+
if c.kind_of?(Array)
|
41
|
+
l[index] = :empty
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
molecules
|
47
|
+
end
|
20
48
|
end
|
21
49
|
end
|
data/lib/pugnacious/molecule.rb
CHANGED
@@ -4,7 +4,7 @@ module Pugnacious
|
|
4
4
|
|
5
5
|
attr_accessor :player, :life, :body, :molecules, :pointer, :position, :game_map, :life, :rival
|
6
6
|
|
7
|
-
MAX_LIFE =
|
7
|
+
MAX_LIFE = 30
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@player = options[:player]
|
@@ -21,9 +21,9 @@ module Pugnacious
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def receive_damage()
|
24
|
-
@life -=
|
24
|
+
@life -=3
|
25
25
|
if @life <= 0
|
26
|
-
@player = @rival
|
26
|
+
@rival, @player = @player, @rival
|
27
27
|
@body.color = Ray::Color.new(100, 100, 0) + @player.color
|
28
28
|
@life = MAX_LIFE
|
29
29
|
@pointer = @player.pointer
|
data/lib/pugnacious/movable.rb
CHANGED
@@ -11,42 +11,76 @@ module Pugnacious
|
|
11
11
|
:north_west => [-1, -1]}
|
12
12
|
|
13
13
|
def move
|
14
|
-
|
14
|
+
unless pointer_direction() == :here
|
15
|
+
posible_directions = posible_directions(pointer_direction())
|
16
|
+
|
17
|
+
posible_directions.each do |direction|
|
18
|
+
case check_tile(direction)
|
19
|
+
when :empty
|
20
|
+
move!(direction)
|
21
|
+
return
|
22
|
+
when :enemy
|
23
|
+
fight(direction)
|
24
|
+
return
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def fight(direction)
|
31
|
+
xw, yw = DIRECTIONS[direction]
|
32
|
+
|
33
|
+
x = xw + @position[0]
|
34
|
+
y = yw + @position[1]
|
35
|
+
|
36
|
+
tile = @game_map[x][y]
|
37
|
+
|
38
|
+
tile.receive_damage
|
15
39
|
end
|
16
40
|
|
17
|
-
def
|
18
|
-
directions =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
41
|
+
def posible_directions(direction)
|
42
|
+
directions = []
|
43
|
+
index = DIRECTIONS.keys.find_index(direction)
|
44
|
+
indexes = []
|
45
|
+
|
46
|
+
# The order is important.
|
47
|
+
indexes << index
|
48
|
+
indexes << index - 1
|
49
|
+
indexes << index + 1
|
50
|
+
indexes << index - 2
|
51
|
+
indexes << index + 2
|
52
|
+
|
53
|
+
directions = indexes.map do |i|
|
54
|
+
if i>7
|
55
|
+
DIRECTIONS.keys[i-7]
|
56
|
+
else
|
57
|
+
DIRECTIONS.keys[i]
|
58
|
+
end
|
28
59
|
end
|
60
|
+
|
61
|
+
directions
|
29
62
|
end
|
30
63
|
|
31
|
-
def
|
64
|
+
def check_tile(direction)
|
32
65
|
xw, yw = DIRECTIONS[direction]
|
33
66
|
|
34
67
|
x = xw + @position[0]
|
35
68
|
y = yw + @position[1]
|
36
69
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
70
|
+
tile = @game_map[x][y]
|
71
|
+
|
72
|
+
if tile == :empty
|
73
|
+
return :empty
|
74
|
+
elsif tile.class == Molecule
|
75
|
+
if tile.player != self.player
|
76
|
+
return :enemy
|
77
|
+
else
|
78
|
+
return :friend
|
79
|
+
end
|
46
80
|
end
|
47
81
|
end
|
48
82
|
|
49
|
-
def
|
83
|
+
def move!(direction)
|
50
84
|
xw, yw = DIRECTIONS[direction]
|
51
85
|
|
52
86
|
x = xw + @position[0]
|
@@ -59,51 +93,62 @@ module Pugnacious
|
|
59
93
|
@position = [x, y]
|
60
94
|
end
|
61
95
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
96
|
+
def pointer_direction()
|
97
|
+
case
|
98
|
+
when pointer_at_south
|
99
|
+
:south
|
100
|
+
when pointer_at_north
|
101
|
+
:north
|
102
|
+
when pointer_at_east
|
103
|
+
:east
|
104
|
+
when pointer_at_west
|
105
|
+
:west
|
106
|
+
when pointer_at_south_east
|
107
|
+
:south_east
|
108
|
+
when pointer_at_north_east
|
109
|
+
:north_east
|
110
|
+
when pointer_at_south_west
|
111
|
+
:south_west
|
112
|
+
when pointer_at_north_west
|
113
|
+
:north_west
|
114
|
+
when here
|
115
|
+
:here
|
116
|
+
end
|
72
117
|
end
|
73
118
|
|
74
|
-
def pointer_at_south
|
119
|
+
def pointer_at_south()
|
75
120
|
@pointer.x == body.x and @pointer.y > body.y
|
76
121
|
end
|
77
122
|
|
78
|
-
def pointer_at_north
|
123
|
+
def pointer_at_north()
|
79
124
|
@pointer.x == body.x and @pointer.y < body.y
|
80
125
|
end
|
81
126
|
|
82
|
-
def pointer_at_east
|
127
|
+
def pointer_at_east()
|
83
128
|
@pointer.x > body.x and @pointer.y == body.y
|
84
129
|
end
|
85
130
|
|
86
|
-
def pointer_at_west
|
131
|
+
def pointer_at_west()
|
87
132
|
@pointer.x < body.x and @pointer.y == body.y
|
88
133
|
end
|
89
134
|
|
90
|
-
def pointer_at_south_east
|
135
|
+
def pointer_at_south_east()
|
91
136
|
@pointer.x > body.x and @pointer.y > body.y
|
92
137
|
end
|
93
138
|
|
94
|
-
def pointer_at_north_east
|
139
|
+
def pointer_at_north_east()
|
95
140
|
@pointer.x > body.x and @pointer.y < body.y
|
96
141
|
end
|
97
142
|
|
98
|
-
def pointer_at_south_west
|
143
|
+
def pointer_at_south_west()
|
99
144
|
@pointer.x < body.x and @pointer.y > body.y
|
100
145
|
end
|
101
146
|
|
102
|
-
def pointer_at_north_west
|
147
|
+
def pointer_at_north_west()
|
103
148
|
@pointer.x < body.x and @pointer.y < body.y
|
104
149
|
end
|
105
150
|
|
106
|
-
def here
|
151
|
+
def here()
|
107
152
|
@pointer.x == body.x and @pointer.y == body.y
|
108
153
|
end
|
109
154
|
end
|
data/lib/pugnacious/player.rb
CHANGED
@@ -10,7 +10,6 @@ module Pugnacious
|
|
10
10
|
position = options[:position] || [200, 200]
|
11
11
|
|
12
12
|
@control_keys = options[:control_keys]
|
13
|
-
@control_keys ||= [:up, :right, :down, :left]
|
14
13
|
|
15
14
|
@pointer = Ray::Polygon.circle(position, POINTER_SIZE, @color , 3, @color)
|
16
15
|
@pointer.filled = false
|
@@ -18,36 +17,15 @@ module Pugnacious
|
|
18
17
|
|
19
18
|
def move(direction)
|
20
19
|
case direction
|
21
|
-
when
|
20
|
+
when control_keys[:up]
|
22
21
|
pointer.y -= SPEED unless (pointer.pos.y -= SPEED) < 0 + POINTER_SIZE
|
23
|
-
when
|
22
|
+
when control_keys[:right]
|
24
23
|
pointer.x += SPEED unless (pointer.pos.x += SPEED) > MAP_SIZE - POINTER_SIZE
|
25
|
-
when
|
24
|
+
when control_keys[:down]
|
26
25
|
pointer.y += SPEED unless (pointer.pos.y += SPEED) > MAP_SIZE - POINTER_SIZE
|
27
|
-
when
|
26
|
+
when control_keys[:left]
|
28
27
|
pointer.x -= SPEED unless (pointer.pos.x -= SPEED) < 0 + POINTER_SIZE
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
32
|
-
########################
|
33
|
-
# Control keys aliases
|
34
|
-
#######################
|
35
|
-
|
36
|
-
def control_keys_up
|
37
|
-
control_keys[0]
|
38
|
-
end
|
39
|
-
|
40
|
-
def control_keys_right
|
41
|
-
control_keys[1]
|
42
|
-
end
|
43
|
-
|
44
|
-
def control_keys_down
|
45
|
-
control_keys[2]
|
46
|
-
end
|
47
|
-
|
48
|
-
def control_keys_left
|
49
|
-
control_keys[3]
|
50
|
-
end
|
51
|
-
|
52
30
|
end
|
53
31
|
end
|
data/lib/pugnacious/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pugnacious_juices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-14 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ray
|
16
|
-
requirement: &
|
16
|
+
requirement: &70135957685520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,11 +21,11 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70135957685520
|
25
25
|
description: It is a clone of Liquid Wars.
|
26
26
|
email: siotopo@gmail.com
|
27
27
|
executables:
|
28
|
-
- pugnacious
|
28
|
+
- pugnacious
|
29
29
|
extensions: []
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- lib/pugnacious/player.rb
|
38
38
|
- lib/pugnacious/version.rb
|
39
39
|
- lib/pugnacious.rb
|
40
|
-
- bin/pugnacious
|
40
|
+
- bin/pugnacious
|
41
41
|
homepage: https://github.com/Nerian/Pugnacious-Juices
|
42
42
|
licenses: []
|
43
43
|
post_install_message:
|