ruby-pong 0.0.2 → 0.0.3
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.
- data/Gemfile +1 -1
- data/bin/pong +88 -12
- data/lib/ruby-pong.rb +4 -4
- data/lib/ruby-pong/version.rb +1 -1
- metadata +6 -6
data/Gemfile
CHANGED
data/bin/pong
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'gosu'
|
2
3
|
require 'ruby-pong'
|
3
4
|
|
4
5
|
include Pong
|
@@ -11,15 +12,77 @@ ball = Ball.new do
|
|
11
12
|
set_x_position 100
|
12
13
|
set_y_position 200
|
13
14
|
|
14
|
-
set_velocity Arcade::Velocity[
|
15
|
+
set_velocity Arcade::Velocity[7,8]
|
15
16
|
|
16
17
|
on_hit_edge do |edge|
|
17
|
-
|
18
|
-
|
18
|
+
player_paddle = get_object('player_paddle')
|
19
|
+
opponent_paddle = get_object('opponent_paddle')
|
20
|
+
if edge == :top
|
21
|
+
set_y_position 10
|
22
|
+
|
23
|
+
set_velocity velocity.reflect_vertically
|
24
|
+
end
|
25
|
+
|
26
|
+
if edge == :bottom
|
27
|
+
set_y_position 590
|
28
|
+
|
29
|
+
set_velocity velocity.reflect_vertically
|
30
|
+
end
|
31
|
+
|
32
|
+
if edge == :left
|
33
|
+
opponent_paddle.set_score opponent_paddle.score + 1
|
34
|
+
puts "Score: Player: %d, Opponent: %d" % [player_paddle.score, opponent_paddle.score]
|
35
|
+
|
36
|
+
if opponent_paddle.score >= 5
|
37
|
+
puts "Opponent wins!"
|
38
|
+
|
39
|
+
player_paddle.set_score 0
|
40
|
+
opponent_paddle.set_score 0
|
41
|
+
|
42
|
+
set_x_position 400
|
43
|
+
set_y_position 300
|
44
|
+
set_velocity Arcade::Velocity::ZERO
|
45
|
+
else
|
46
|
+
set_x_position 10
|
47
|
+
set_velocity velocity.reflect_horizontally
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if edge == :right
|
52
|
+
player_paddle.set_score player_paddle.score + 1
|
53
|
+
puts "Score: Player: %d, Opponent: %d" % [player_paddle.score, opponent_paddle.score]
|
54
|
+
|
55
|
+
if player_paddle.score >= 5
|
56
|
+
puts "Player wins!"
|
57
|
+
|
58
|
+
player_paddle.set_score 0
|
59
|
+
opponent_paddle.set_score 0
|
60
|
+
|
61
|
+
set_x_position 400
|
62
|
+
set_y_position 300
|
63
|
+
set_velocity Arcade::Velocity::ZERO
|
64
|
+
else
|
65
|
+
set_x_position 790
|
66
|
+
set_velocity velocity.reflect_horizontally
|
67
|
+
end
|
68
|
+
|
19
69
|
end
|
70
|
+
end
|
20
71
|
|
21
|
-
|
22
|
-
|
72
|
+
on_collides_with Paddle do |paddle|
|
73
|
+
if paddle.hit_side == :left or paddle.hit_side == :right
|
74
|
+
# If the ball hit the left or right side of the paddle
|
75
|
+
# bounce away horizontally
|
76
|
+
set_velocity velocity.reflect_horizontally
|
77
|
+
else
|
78
|
+
# If we hit the top or bottom, bounce away vertically
|
79
|
+
set_velocity velocity.reflect_vertically
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
on_keypress Arcade::Keyboard::KeySpace do
|
84
|
+
if velocity.zero?
|
85
|
+
set_velocity Arcade::Velocity[7,8]
|
23
86
|
end
|
24
87
|
end
|
25
88
|
end
|
@@ -44,11 +107,18 @@ player_paddle = Paddle.new do
|
|
44
107
|
end
|
45
108
|
end
|
46
109
|
|
47
|
-
|
48
|
-
|
110
|
+
on_keypress Arcade::Keyboard::KeyD do
|
111
|
+
if self.right < 400
|
112
|
+
move_right 10
|
113
|
+
end
|
114
|
+
end
|
49
115
|
|
50
|
-
|
116
|
+
on_keypress Arcade::Keyboard::KeyA do
|
117
|
+
if self.left > 0
|
118
|
+
move_left 10
|
119
|
+
end
|
51
120
|
end
|
121
|
+
|
52
122
|
end
|
53
123
|
|
54
124
|
opponent_paddle = Paddle.new do
|
@@ -56,7 +126,7 @@ opponent_paddle = Paddle.new do
|
|
56
126
|
|
57
127
|
set_color Arcade::Color::RED
|
58
128
|
|
59
|
-
set_x_position
|
129
|
+
set_x_position 780
|
60
130
|
set_y_position 10
|
61
131
|
|
62
132
|
on_keypress Arcade::Keyboard::KeyUp do
|
@@ -71,10 +141,16 @@ opponent_paddle = Paddle.new do
|
|
71
141
|
end
|
72
142
|
end
|
73
143
|
|
74
|
-
|
75
|
-
|
144
|
+
on_keypress Arcade::Keyboard::KeyRight do
|
145
|
+
if self.right < 800
|
146
|
+
move_right 10
|
147
|
+
end
|
148
|
+
end
|
76
149
|
|
77
|
-
|
150
|
+
on_keypress Arcade::Keyboard::KeyLeft do
|
151
|
+
if self.left > 400
|
152
|
+
move_left 10
|
153
|
+
end
|
78
154
|
end
|
79
155
|
end
|
80
156
|
|
data/lib/ruby-pong.rb
CHANGED
@@ -4,8 +4,8 @@ require 'ruby-pong/version'
|
|
4
4
|
module Pong
|
5
5
|
class Paddle < Arcade::GameObject
|
6
6
|
set_defaults do
|
7
|
-
|
8
|
-
|
7
|
+
self.width = 15
|
8
|
+
self.height = 100
|
9
9
|
|
10
10
|
set_score 0
|
11
11
|
end
|
@@ -19,8 +19,8 @@ module Pong
|
|
19
19
|
|
20
20
|
class Ball < Arcade::GameObject
|
21
21
|
set_defaults do
|
22
|
-
|
23
|
-
|
22
|
+
self.width = 10
|
23
|
+
self.height = 10
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/ruby-pong/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-pong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arcade
|
16
|
-
requirement: &
|
16
|
+
requirement: &70250247521000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70250247521000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70250247520580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70250247520580
|
36
36
|
description: Pong in Ruby, to demonstrate jfarmer's Arcade framework
|
37
37
|
email:
|
38
38
|
- jesse@20bits.com
|