ruby-pong 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +6 -0
- data/Rakefile +2 -0
- data/bin/pong +84 -0
- data/lib/ruby-pong.rb +18 -0
- data/lib/ruby-pong/version.rb +3 -0
- data/ruby-pong.gemspec +21 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jesse Farmer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/pong
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'ruby-pong'
|
4
|
+
|
5
|
+
include Pong
|
6
|
+
|
7
|
+
$main_window = Arcade::GameWindow.new(800, 600)
|
8
|
+
|
9
|
+
ball = Ball.new do
|
10
|
+
set_name 'pong_ball'
|
11
|
+
|
12
|
+
set_x_position 100
|
13
|
+
set_y_position 200
|
14
|
+
|
15
|
+
set_velocity Arcade::Velocity[5,7]
|
16
|
+
|
17
|
+
on_hit_edge do |edge|
|
18
|
+
if edge == :top or edge == :bottom
|
19
|
+
self.velocity = self.velocity.reflect_vertically
|
20
|
+
end
|
21
|
+
|
22
|
+
if edge == :left or edge == :right
|
23
|
+
self.velocity = self.velocity.reflect_horizontally
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
player_paddle = Paddle.new do
|
29
|
+
set_name 'player_paddle'
|
30
|
+
|
31
|
+
set_color Arcade::Color::WHITE
|
32
|
+
|
33
|
+
set_x_position 10
|
34
|
+
set_y_position 10
|
35
|
+
|
36
|
+
on_keypress Arcade::Keyboard::KeyW do
|
37
|
+
if self.top > 0
|
38
|
+
move_up 10
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
on_keypress Arcade::Keyboard::KeyS do
|
43
|
+
if self.bottom < 600
|
44
|
+
move_down 10
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
on_collides_with Ball do |ball|
|
49
|
+
ball.velocity = ball.velocity.reflect_horizontally
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
opponent_paddle = Paddle.new do
|
54
|
+
set_name 'opponent_paddle'
|
55
|
+
|
56
|
+
set_color Arcade::Color::RED
|
57
|
+
|
58
|
+
set_x_position $main_window.width - config.width - 10
|
59
|
+
set_y_position 10
|
60
|
+
|
61
|
+
on_keypress Arcade::Keyboard::KeyUp do
|
62
|
+
if self.top > 0
|
63
|
+
move_up 10
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
on_keypress Arcade::Keyboard::KeyDown do
|
68
|
+
if self.bottom < 600
|
69
|
+
move_down 10
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
on_collides_with Ball do |ball|
|
74
|
+
ball.velocity = ball.velocity.reflect_horizontally
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
$main_window.register player_paddle
|
80
|
+
$main_window.register opponent_paddle
|
81
|
+
$main_window.register ball
|
82
|
+
|
83
|
+
|
84
|
+
$main_window.show
|
data/lib/ruby-pong.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'arcade'
|
2
|
+
require 'ruby-pong/version'
|
3
|
+
|
4
|
+
module Pong
|
5
|
+
class Paddle < Arcade::GameObject
|
6
|
+
set_defaults do
|
7
|
+
set_width 15
|
8
|
+
set_height 100
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Ball < Arcade::GameObject
|
13
|
+
set_defaults do
|
14
|
+
set_width 10
|
15
|
+
set_height 10
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/ruby-pong.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ruby-pong/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jesse Farmer"]
|
6
|
+
gem.email = ["jesse@20bits.com"]
|
7
|
+
gem.description = "Pong in Ruby, to demonstrate jfarmer's Arcade framework"
|
8
|
+
gem.summary = "Pong in Ruby, to demonstrate jfarmer's Arcade framework. See http://github.com/jfarmer/arcade"
|
9
|
+
gem.homepage = "http://github.com/jfarmer/ruby-pong"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ruby-pong"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Pong::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'arcade'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-pong
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jesse Farmer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: arcade
|
16
|
+
requirement: &70309449714980 !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: *70309449714980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70309449713840 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70309449713840
|
36
|
+
description: Pong in Ruby, to demonstrate jfarmer's Arcade framework
|
37
|
+
email:
|
38
|
+
- jesse@20bits.com
|
39
|
+
executables:
|
40
|
+
- pong
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- bin/pong
|
50
|
+
- lib/ruby-pong.rb
|
51
|
+
- lib/ruby-pong/version.rb
|
52
|
+
- ruby-pong.gemspec
|
53
|
+
homepage: http://github.com/jfarmer/ruby-pong
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.17
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Pong in Ruby, to demonstrate jfarmer's Arcade framework. See http://github.com/jfarmer/arcade
|
77
|
+
test_files: []
|