rubyhop 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +16 -0
- data/README.txt +45 -0
- data/Rakefile +9 -0
- data/bin/rubyhop +3 -0
- data/lib/background.png +0 -0
- data/lib/gameover.mp3 +0 -0
- data/lib/hoop.png +0 -0
- data/lib/hop.mp3 +0 -0
- data/lib/music.mp3 +0 -0
- data/lib/rubyguy-dead.png +0 -0
- data/lib/rubyguy-fall.png +0 -0
- data/lib/rubyguy-rise.png +0 -0
- data/lib/rubyhop.rb +139 -0
- data/test/test_rubyhop.rb +8 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 885bdcfecc5b74165cd85c830b8ab624ab3726e3
|
4
|
+
data.tar.gz: 2b3a5bf532ff2755c1e63e8027da8bdea01d5633
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 339f2480beb2895335f8b378d9c4dd4304cd91858bf1aff6e76b8de3b7806e93953befc9fff6248b867c06e2de4be81119d44de606f0484c4a94dfe3a768c797
|
7
|
+
data.tar.gz: 196c79a3278fae8bebc37be2f5292dbedc7a36fba79a9656e199f6dee32fa1c37419ef533de3e823973ca32f8aa22c87c2fc967dcd905da6f22047003f5da8ad
|
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
bin/rubyhop
|
7
|
+
lib/background.png
|
8
|
+
lib/gameover.mp3
|
9
|
+
lib/hoop.png
|
10
|
+
lib/hop.mp3
|
11
|
+
lib/music.mp3
|
12
|
+
lib/rubyguy-dead.png
|
13
|
+
lib/rubyguy-fall.png
|
14
|
+
lib/rubyguy-rise.png
|
15
|
+
lib/rubyhop.rb
|
16
|
+
test/test_rubyhop.rb
|
data/README.txt
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= rubyhop
|
2
|
+
|
3
|
+
http://blowmage.com/rubyhop
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Super awesome Ruby-themed game
|
8
|
+
|
9
|
+
$ gem install rubyhop
|
10
|
+
$ rubyhop
|
11
|
+
|
12
|
+
== DEVELOPERS:
|
13
|
+
|
14
|
+
After checking out the source, run:
|
15
|
+
|
16
|
+
$ gem install hoe
|
17
|
+
$ rake newb
|
18
|
+
|
19
|
+
This task will install any missing dependencies, run the tests/specs,
|
20
|
+
and generate the RDoc.
|
21
|
+
|
22
|
+
== LICENSE:
|
23
|
+
|
24
|
+
(The MIT License)
|
25
|
+
|
26
|
+
Copyright (c) 2014 Mike Moore
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
29
|
+
a copy of this software and associated documentation files (the
|
30
|
+
'Software'), to deal in the Software without restriction, including
|
31
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
32
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
33
|
+
permit persons to whom the Software is furnished to do so, subject to
|
34
|
+
the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be
|
37
|
+
included in all copies or substantial portions of the Software.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
41
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
42
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
43
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
44
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
45
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/rubyhop
ADDED
data/lib/background.png
ADDED
Binary file
|
data/lib/gameover.mp3
ADDED
Binary file
|
data/lib/hoop.png
ADDED
Binary file
|
data/lib/hop.mp3
ADDED
Binary file
|
data/lib/music.mp3
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/rubyhop.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require "gosu"
|
2
|
+
|
3
|
+
def get_my_file file
|
4
|
+
"#{File.dirname(__FILE__)}/#{file}"
|
5
|
+
end
|
6
|
+
|
7
|
+
class Player
|
8
|
+
attr_accessor :x, :y
|
9
|
+
def initialize window
|
10
|
+
@window = window
|
11
|
+
@alive = true
|
12
|
+
# position
|
13
|
+
@x = window.width/2
|
14
|
+
@y = window.height/2
|
15
|
+
@velocity = 0.0
|
16
|
+
@gravity = -0.25
|
17
|
+
@hop = 7.5
|
18
|
+
# sounds
|
19
|
+
@sound = Gosu::Sample.new @window, get_my_file("hop.mp3")
|
20
|
+
@gameover = Gosu::Sample.new @window, get_my_file("gameover.mp3")
|
21
|
+
# images
|
22
|
+
@rise = Gosu::Image.new window, get_my_file("rubyguy-rise.png")
|
23
|
+
@fall = Gosu::Image.new window, get_my_file("rubyguy-fall.png")
|
24
|
+
@dead = Gosu::Image.new window, get_my_file("rubyguy-dead.png")
|
25
|
+
end
|
26
|
+
def hop
|
27
|
+
if @alive
|
28
|
+
@sound.play
|
29
|
+
@velocity += @hop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def die!
|
33
|
+
if @alive
|
34
|
+
# Set velocity to one last hop
|
35
|
+
@velocity = 5.0
|
36
|
+
@gameover.play
|
37
|
+
@alive = false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def update
|
41
|
+
@velocity += @gravity
|
42
|
+
@y -= @velocity
|
43
|
+
if @alive && (@y < 32 || @y > @window.height - 32)
|
44
|
+
|
45
|
+
end
|
46
|
+
if @y > 5000
|
47
|
+
# kick out to loading screen to try again?
|
48
|
+
@window.close
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def draw
|
52
|
+
image.draw @x - 32, @y - 32, 1000 - @x
|
53
|
+
end
|
54
|
+
def image
|
55
|
+
if @alive
|
56
|
+
if @velocity >= 0
|
57
|
+
@rise
|
58
|
+
else
|
59
|
+
@fall
|
60
|
+
end
|
61
|
+
else
|
62
|
+
@dead
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Hoop
|
68
|
+
attr_accessor :x, :y
|
69
|
+
def initialize window
|
70
|
+
@window = window
|
71
|
+
@hoop = Gosu::Image.new window, get_my_file("hoop.png")
|
72
|
+
# center of screen
|
73
|
+
@movement = 2
|
74
|
+
@x = @y = 0
|
75
|
+
reset_position!
|
76
|
+
end
|
77
|
+
def reset_position!
|
78
|
+
@x += 1200
|
79
|
+
@y = rand 150..500
|
80
|
+
end
|
81
|
+
def miss player
|
82
|
+
if (@x - player.x).abs < 12 &&
|
83
|
+
(@y - player.y).abs > 72
|
84
|
+
# the player missed the hoop
|
85
|
+
return true
|
86
|
+
end
|
87
|
+
false
|
88
|
+
end
|
89
|
+
def update
|
90
|
+
reset_position! if @x < -200
|
91
|
+
@movement += 0.003
|
92
|
+
@x -= @movement
|
93
|
+
end
|
94
|
+
def draw
|
95
|
+
@hoop.draw @x - 66, @y - 98, 1000 - @x
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class RubyhopGame < Gosu::Window
|
100
|
+
VERSION = "1.0.0"
|
101
|
+
def initialize width=800, height=600, fullscreen=false
|
102
|
+
super
|
103
|
+
self.caption = "Ruby Hop"
|
104
|
+
@music = Gosu::Song.new self, get_my_file("music.mp3")
|
105
|
+
@music.play true
|
106
|
+
@background = Gosu::Image.new self, get_my_file("background.png")
|
107
|
+
@player = Player.new self
|
108
|
+
@hoops = 6.times.map { Hoop.new self }
|
109
|
+
init_hoops!
|
110
|
+
end
|
111
|
+
|
112
|
+
def init_hoops!
|
113
|
+
hoop_start = 600
|
114
|
+
@hoops.each do |hoop|
|
115
|
+
hoop_start += 200
|
116
|
+
hoop.reset_position!
|
117
|
+
hoop.x = hoop_start
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def button_down id
|
122
|
+
close if id == Gosu::KbEscape
|
123
|
+
@player.hop if id == Gosu::KbSpace
|
124
|
+
end
|
125
|
+
|
126
|
+
def update
|
127
|
+
@player.update
|
128
|
+
@hoops.each do |hoop|
|
129
|
+
hoop.update
|
130
|
+
@player.die! if hoop.miss @player
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def draw
|
135
|
+
@background.draw 0, 0, 0
|
136
|
+
@player.draw
|
137
|
+
@hoops.each &:draw
|
138
|
+
end
|
139
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyhop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Moore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hoe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.8'
|
41
|
+
description: |-
|
42
|
+
Super awesome Ruby-themed game
|
43
|
+
|
44
|
+
$ gem install rubyhop
|
45
|
+
$ rubyhop
|
46
|
+
email:
|
47
|
+
- mike@blowmage.com
|
48
|
+
executables:
|
49
|
+
- rubyhop
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- History.txt
|
53
|
+
- Manifest.txt
|
54
|
+
- README.txt
|
55
|
+
files:
|
56
|
+
- ".autotest"
|
57
|
+
- ".gemtest"
|
58
|
+
- History.txt
|
59
|
+
- Manifest.txt
|
60
|
+
- README.txt
|
61
|
+
- Rakefile
|
62
|
+
- bin/rubyhop
|
63
|
+
- lib/background.png
|
64
|
+
- lib/gameover.mp3
|
65
|
+
- lib/hoop.png
|
66
|
+
- lib/hop.mp3
|
67
|
+
- lib/music.mp3
|
68
|
+
- lib/rubyguy-dead.png
|
69
|
+
- lib/rubyguy-fall.png
|
70
|
+
- lib/rubyguy-rise.png
|
71
|
+
- lib/rubyhop.rb
|
72
|
+
- test/test_rubyhop.rb
|
73
|
+
homepage: http://blowmage.com/rubyhop
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- "--main"
|
80
|
+
- README.txt
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: rubyhop
|
95
|
+
rubygems_version: 2.2.0
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Super awesome Ruby-themed game $ gem install rubyhop $ rubyhop
|
99
|
+
test_files:
|
100
|
+
- test/test_rubyhop.rb
|