pugnacious_juices 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pugnacious.rb +4 -0
- data/lib/pugnacious.rb +8 -0
- data/lib/pugnacious/application.rb +19 -0
- data/lib/pugnacious/fight_scene.rb +83 -0
- data/lib/pugnacious/game_map.rb +21 -0
- data/lib/pugnacious/molecule.rb +33 -0
- data/lib/pugnacious/movable.rb +110 -0
- data/lib/pugnacious/player.rb +53 -0
- data/lib/pugnacious/version.rb +3 -0
- metadata +65 -0
data/bin/pugnacious.rb
ADDED
data/lib/pugnacious.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'ray'
|
2
|
+
require_relative 'pugnacious/version'
|
3
|
+
require_relative 'pugnacious/game_map'
|
4
|
+
require_relative 'pugnacious/movable'
|
5
|
+
require_relative 'pugnacious/application'
|
6
|
+
require_relative 'pugnacious/fight_scene'
|
7
|
+
require_relative 'pugnacious/player'
|
8
|
+
require_relative 'pugnacious/molecule'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pugnacious
|
2
|
+
MAP_SIZE = 500
|
3
|
+
MOLECULE_SIZE = 5
|
4
|
+
|
5
|
+
class Application
|
6
|
+
def self.run
|
7
|
+
Ray.game "Pugnacious Juices", :size => [MAP_SIZE, MAP_SIZE] do
|
8
|
+
frames_per_second = 16
|
9
|
+
register { add_hook :quit, method(:exit!) }
|
10
|
+
|
11
|
+
FightScene.bind(self)
|
12
|
+
scenes << :fight_scene
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Pugnacious
|
2
|
+
class FightScene < Ray::Scene
|
3
|
+
scene_name :fight_scene
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@gc_counter = 0
|
7
|
+
#self.frames_per_second = 5
|
8
|
+
@player1 = Player.new(
|
9
|
+
color: Ray::Color.blue,
|
10
|
+
position: [0, 0],
|
11
|
+
control_keys: [:up, :right, :down, :left])
|
12
|
+
|
13
|
+
@player2 = Player.new(
|
14
|
+
color: Ray::Color.red,
|
15
|
+
position: [0, 0],
|
16
|
+
control_keys: [:w, :d, :s, :a])
|
17
|
+
|
18
|
+
@player2.pointer.pos = [300, 300]
|
19
|
+
@player1.pointer.pos = [400, 300]
|
20
|
+
|
21
|
+
@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
|
52
|
+
|
53
|
+
@players = [@player1, @player2]
|
54
|
+
end
|
55
|
+
|
56
|
+
def register
|
57
|
+
always do
|
58
|
+
@players.each do |player|
|
59
|
+
player.control_keys.each do |direction|
|
60
|
+
if holding? direction then player.move direction end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
@molecules.each &:move
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def render(window)
|
69
|
+
@molecules.each { |molecule| window.draw molecule.body}
|
70
|
+
@players.each { |player| window.draw player.pointer }
|
71
|
+
end
|
72
|
+
|
73
|
+
def clean_up
|
74
|
+
@players.each do |player|
|
75
|
+
player = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
@players = nil
|
79
|
+
|
80
|
+
Ray::ImageSet.clear
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pugnacious
|
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
|
+
|
9
|
+
def self.generate_empty_map(number_of_lines, number_of_columns)
|
10
|
+
game_map = []
|
11
|
+
(number_of_columns/MOLECULE_SIZE).times do |l|
|
12
|
+
game_map << []
|
13
|
+
(number_of_lines/MOLECULE_SIZE).times do |c|
|
14
|
+
game_map[l][c] = :empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
game_map
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pugnacious
|
2
|
+
class Molecule
|
3
|
+
include Pugnacious::Movable
|
4
|
+
|
5
|
+
attr_accessor :player, :life, :body, :molecules, :pointer, :position, :game_map, :life, :rival
|
6
|
+
|
7
|
+
MAX_LIFE = 40
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@player = options[:player]
|
11
|
+
@game_map = options[:map]
|
12
|
+
@position = options[:pos]
|
13
|
+
@game_map[@position[0]][@position[1]] = self
|
14
|
+
@body = Ray::Polygon.rectangle([0, 0, MOLECULE_SIZE, MOLECULE_SIZE],
|
15
|
+
Ray::Color.new(100, 100, 0) + @player.color)
|
16
|
+
@body.pos = [@position[0] * MOLECULE_SIZE, @position[1] * MOLECULE_SIZE] || [0, 0]
|
17
|
+
@molecules = options[:molecules]
|
18
|
+
@pointer = @player.pointer
|
19
|
+
@life = MAX_LIFE
|
20
|
+
@rival = options[:rival]
|
21
|
+
end
|
22
|
+
|
23
|
+
def receive_damage()
|
24
|
+
@life -=1
|
25
|
+
if @life <= 0
|
26
|
+
@player = @rival
|
27
|
+
@body.color = Ray::Color.new(100, 100, 0) + @player.color
|
28
|
+
@life = MAX_LIFE
|
29
|
+
@pointer = @player.pointer
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Pugnacious
|
2
|
+
module Movable
|
3
|
+
|
4
|
+
DIRECTIONS = {:north => [0, -1] ,
|
5
|
+
:north_east => [1, -1],
|
6
|
+
:east => [1, 0],
|
7
|
+
:south_east => [1, 1],
|
8
|
+
:south => [0, 1],
|
9
|
+
:south_west => [-1, 1],
|
10
|
+
:west => [-1, 0],
|
11
|
+
:north_west => [-1, -1]}
|
12
|
+
|
13
|
+
def move
|
14
|
+
try_to_go(where_is_the_pointer?) unless where_is_the_pointer? == :here
|
15
|
+
end
|
16
|
+
|
17
|
+
def try_to_go(direction)
|
18
|
+
directions = DIRECTIONS.keys
|
19
|
+
intention_index = directions.find_index(direction)
|
20
|
+
directions.push(:north)
|
21
|
+
|
22
|
+
if can_i_move_there?(direction)
|
23
|
+
move_there(direction)
|
24
|
+
elsif can_i_move_there?(directions[intention_index+1])
|
25
|
+
move_there(directions[intention_index+1])
|
26
|
+
elsif can_i_move_there?(directions[intention_index-1])
|
27
|
+
move_there(directions[intention_index-1])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def can_i_move_there?(direction)
|
32
|
+
xw, yw = DIRECTIONS[direction]
|
33
|
+
|
34
|
+
x = xw + @position[0]
|
35
|
+
y = yw + @position[1]
|
36
|
+
|
37
|
+
if @game_map[x][y] == :empty
|
38
|
+
return true
|
39
|
+
elsif @game_map[x][y].class == Molecule
|
40
|
+
if @game_map[x][y].player != self.player
|
41
|
+
@game_map[x][y].receive_damage()
|
42
|
+
end
|
43
|
+
return false
|
44
|
+
else
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def move_there(direction)
|
50
|
+
xw, yw = DIRECTIONS[direction]
|
51
|
+
|
52
|
+
x = xw + @position[0]
|
53
|
+
y = yw + @position[1]
|
54
|
+
|
55
|
+
@game_map[@position[0]][@position[1]] = :empty
|
56
|
+
@game_map[x][y] = self
|
57
|
+
|
58
|
+
body.pos = [x * MOLECULE_SIZE, y * MOLECULE_SIZE]
|
59
|
+
@position = [x, y]
|
60
|
+
end
|
61
|
+
|
62
|
+
def where_is_the_pointer?
|
63
|
+
if pointer_at_south then return :south end
|
64
|
+
if pointer_at_north then return :north end
|
65
|
+
if pointer_at_east then return :east end
|
66
|
+
if pointer_at_west then return :west end
|
67
|
+
if pointer_at_south_east then return :south_east end
|
68
|
+
if pointer_at_north_east then return :north_east end
|
69
|
+
if pointer_at_south_west then return :south_west end
|
70
|
+
if pointer_at_north_west then return :north_west end
|
71
|
+
if here then return :here end
|
72
|
+
end
|
73
|
+
|
74
|
+
def pointer_at_south
|
75
|
+
@pointer.x == body.x and @pointer.y > body.y
|
76
|
+
end
|
77
|
+
|
78
|
+
def pointer_at_north
|
79
|
+
@pointer.x == body.x and @pointer.y < body.y
|
80
|
+
end
|
81
|
+
|
82
|
+
def pointer_at_east
|
83
|
+
@pointer.x > body.x and @pointer.y == body.y
|
84
|
+
end
|
85
|
+
|
86
|
+
def pointer_at_west
|
87
|
+
@pointer.x < body.x and @pointer.y == body.y
|
88
|
+
end
|
89
|
+
|
90
|
+
def pointer_at_south_east
|
91
|
+
@pointer.x > body.x and @pointer.y > body.y
|
92
|
+
end
|
93
|
+
|
94
|
+
def pointer_at_north_east
|
95
|
+
@pointer.x > body.x and @pointer.y < body.y
|
96
|
+
end
|
97
|
+
|
98
|
+
def pointer_at_south_west
|
99
|
+
@pointer.x < body.x and @pointer.y > body.y
|
100
|
+
end
|
101
|
+
|
102
|
+
def pointer_at_north_west
|
103
|
+
@pointer.x < body.x and @pointer.y < body.y
|
104
|
+
end
|
105
|
+
|
106
|
+
def here
|
107
|
+
@pointer.x == body.x and @pointer.y == body.y
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Pugnacious
|
2
|
+
class Player
|
3
|
+
attr_accessor :pointer, :army, :speed, :control_keys, :color
|
4
|
+
|
5
|
+
SPEED = 10
|
6
|
+
POINTER_SIZE = 10
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@color = options[:color] || Ray::Color.blue
|
10
|
+
position = options[:position] || [200, 200]
|
11
|
+
|
12
|
+
@control_keys = options[:control_keys]
|
13
|
+
@control_keys ||= [:up, :right, :down, :left]
|
14
|
+
|
15
|
+
@pointer = Ray::Polygon.circle(position, POINTER_SIZE, @color , 3, @color)
|
16
|
+
@pointer.filled = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def move(direction)
|
20
|
+
case direction
|
21
|
+
when control_keys_up
|
22
|
+
pointer.y -= SPEED unless (pointer.pos.y -= SPEED) < 0 + POINTER_SIZE
|
23
|
+
when control_keys_right
|
24
|
+
pointer.x += SPEED unless (pointer.pos.x += SPEED) > MAP_SIZE - POINTER_SIZE
|
25
|
+
when control_keys_down
|
26
|
+
pointer.y += SPEED unless (pointer.pos.y += SPEED) > MAP_SIZE - POINTER_SIZE
|
27
|
+
when control_keys_left
|
28
|
+
pointer.x -= SPEED unless (pointer.pos.x -= SPEED) < 0 + POINTER_SIZE
|
29
|
+
end
|
30
|
+
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
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pugnacious_juices
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gonzalo Rodriguez-Baltanas Diaz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ray
|
16
|
+
requirement: &70118925055960 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70118925055960
|
25
|
+
description: It is a clone of Liquid Wars.
|
26
|
+
email: siotopo@gmail.com
|
27
|
+
executables:
|
28
|
+
- pugnacious.rb
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/pugnacious/application.rb
|
33
|
+
- lib/pugnacious/fight_scene.rb
|
34
|
+
- lib/pugnacious/game_map.rb
|
35
|
+
- lib/pugnacious/molecule.rb
|
36
|
+
- lib/pugnacious/movable.rb
|
37
|
+
- lib/pugnacious/player.rb
|
38
|
+
- lib/pugnacious/version.rb
|
39
|
+
- lib/pugnacious.rb
|
40
|
+
- bin/pugnacious.rb
|
41
|
+
homepage: https://github.com/Nerian/Pugnacious-Juices
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Two or more fluids fight for total dominance
|
65
|
+
test_files: []
|