ruby-pong 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pong.gemspec
4
- gemspec
4
+ gemspec
data/bin/pong CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rubygems'
3
2
  require 'ruby-pong'
4
3
 
5
4
  include Pong
@@ -13,12 +12,12 @@ ball = Ball.new do
13
12
  set_y_position 200
14
13
 
15
14
  set_velocity Arcade::Velocity[5,7]
16
-
15
+
17
16
  on_hit_edge do |edge|
18
17
  if edge == :top or edge == :bottom
19
18
  self.velocity = self.velocity.reflect_vertically
20
19
  end
21
-
20
+
22
21
  if edge == :left or edge == :right
23
22
  self.velocity = self.velocity.reflect_horizontally
24
23
  end
@@ -27,16 +26,16 @@ end
27
26
 
28
27
  player_paddle = Paddle.new do
29
28
  set_name 'player_paddle'
30
-
29
+
31
30
  set_color Arcade::Color::WHITE
32
-
31
+
33
32
  set_x_position 10
34
33
  set_y_position 10
35
-
34
+
36
35
  on_keypress Arcade::Keyboard::KeyW do
37
36
  if self.top > 0
38
37
  move_up 10
39
- end
38
+ end
40
39
  end
41
40
 
42
41
  on_keypress Arcade::Keyboard::KeyS do
@@ -46,18 +45,20 @@ player_paddle = Paddle.new do
46
45
  end
47
46
 
48
47
  on_collides_with Ball do |ball|
48
+ get_object('opponent_paddle').score!
49
+
49
50
  ball.velocity = ball.velocity.reflect_horizontally
50
51
  end
51
52
  end
52
53
 
53
54
  opponent_paddle = Paddle.new do
54
55
  set_name 'opponent_paddle'
55
-
56
+
56
57
  set_color Arcade::Color::RED
57
-
58
- set_x_position $main_window.width - config.width - 10
58
+
59
+ set_x_position $main_window.width - self.width - 10
59
60
  set_y_position 10
60
-
61
+
61
62
  on_keypress Arcade::Keyboard::KeyUp do
62
63
  if self.top > 0
63
64
  move_up 10
@@ -71,14 +72,14 @@ opponent_paddle = Paddle.new do
71
72
  end
72
73
 
73
74
  on_collides_with Ball do |ball|
75
+ get_object('player_paddle').score!
76
+
74
77
  ball.velocity = ball.velocity.reflect_horizontally
75
78
  end
76
79
  end
77
80
 
78
-
79
81
  $main_window.register player_paddle
80
82
  $main_window.register opponent_paddle
81
83
  $main_window.register ball
82
84
 
83
-
84
- $main_window.show
85
+ $main_window.show
data/lib/ruby-pong.rb CHANGED
@@ -6,6 +6,14 @@ module Pong
6
6
  set_defaults do
7
7
  set_width 15
8
8
  set_height 100
9
+
10
+ set_score 0
11
+ end
12
+
13
+ def score!
14
+ set_score(self.score + 1).tap do |score|
15
+ puts "%s scored! It now has %d points." % [self.name, score]
16
+ end
9
17
  end
10
18
  end
11
19
 
@@ -1,3 +1,3 @@
1
1
  module Pong
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
4
+ version: 0.0.2
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-04-26 00:00:00.000000000 Z
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arcade
16
- requirement: &70309449714980 !ruby/object:Gem::Requirement
16
+ requirement: &70162674271220 !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: *70309449714980
24
+ version_requirements: *70162674271220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70309449713840 !ruby/object:Gem::Requirement
27
+ requirement: &70162674270760 !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: *70309449713840
35
+ version_requirements: *70162674270760
36
36
  description: Pong in Ruby, to demonstrate jfarmer's Arcade framework
37
37
  email:
38
38
  - jesse@20bits.com