rubyhop 1.0.0 → 1.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubyhop.rb +25 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 885bdcfecc5b74165cd85c830b8ab624ab3726e3
4
- data.tar.gz: 2b3a5bf532ff2755c1e63e8027da8bdea01d5633
3
+ metadata.gz: f3a7bd3e2a2d85f16e6554902f36a25ce939a603
4
+ data.tar.gz: f5eac8301dbc469bd5f4fcd1cf5ad1aa20021ee3
5
5
  SHA512:
6
- metadata.gz: 339f2480beb2895335f8b378d9c4dd4304cd91858bf1aff6e76b8de3b7806e93953befc9fff6248b867c06e2de4be81119d44de606f0484c4a94dfe3a768c797
7
- data.tar.gz: 196c79a3278fae8bebc37be2f5292dbedc7a36fba79a9656e199f6dee32fa1c37419ef533de3e823973ca32f8aa22c87c2fc967dcd905da6f22047003f5da8ad
6
+ metadata.gz: ccf0c6b7733f1d431509398cce633582cfcdc40ca1d88a544ba83b3a5831040f10c918bfcbb8c3fb22b677a8fc4313f6e9488d7e48a300cf937a40d6ddae1ad3
7
+ data.tar.gz: 2d3a1a8cb3f33865d9c73ffa45151fc4fd3ec6cdd32774f3f23c654cade645272ff2ee4b70a6ee53b251a964676321d896a5d7205757f67ba539ebb727bfc7f3
data/lib/rubyhop.rb CHANGED
@@ -5,7 +5,7 @@ def get_my_file file
5
5
  end
6
6
 
7
7
  class Player
8
- attr_accessor :x, :y
8
+ attr_accessor :x, :y, :alive
9
9
  def initialize window
10
10
  @window = window
11
11
  @alive = true
@@ -65,18 +65,14 @@ class Player
65
65
  end
66
66
 
67
67
  class Hoop
68
- attr_accessor :x, :y
68
+ attr_accessor :x, :y, :active
69
69
  def initialize window
70
70
  @window = window
71
71
  @hoop = Gosu::Image.new window, get_my_file("hoop.png")
72
72
  # center of screen
73
73
  @movement = 2
74
74
  @x = @y = 0
75
- reset_position!
76
- end
77
- def reset_position!
78
- @x += 1200
79
- @y = rand 150..500
75
+ @active = true
80
76
  end
81
77
  def miss player
82
78
  if (@x - player.x).abs < 12 &&
@@ -87,7 +83,6 @@ class Hoop
87
83
  false
88
84
  end
89
85
  def update
90
- reset_position! if @x < -200
91
86
  @movement += 0.003
92
87
  @x -= @movement
93
88
  end
@@ -97,7 +92,7 @@ class Hoop
97
92
  end
98
93
 
99
94
  class RubyhopGame < Gosu::Window
100
- VERSION = "1.0.0"
95
+ VERSION = "1.1.0"
101
96
  def initialize width=800, height=600, fullscreen=false
102
97
  super
103
98
  self.caption = "Ruby Hop"
@@ -107,17 +102,30 @@ class RubyhopGame < Gosu::Window
107
102
  @player = Player.new self
108
103
  @hoops = 6.times.map { Hoop.new self }
109
104
  init_hoops!
105
+ @score = 0
110
106
  end
111
107
 
112
108
  def init_hoops!
109
+ @hoops.each do |hoop|
110
+ hoop.y = 325
111
+ end
113
112
  hoop_start = 600
114
113
  @hoops.each do |hoop|
114
+ reset_hoop! hoop
115
115
  hoop_start += 200
116
- hoop.reset_position!
117
116
  hoop.x = hoop_start
118
117
  end
119
118
  end
120
119
 
120
+ def reset_hoop! hoop
121
+ idx = @hoops.index hoop
122
+ prev = @hoops[idx - 1]
123
+ new_y = ((prev.y-150..prev.y+125).to_a & (150..500).to_a).sample
124
+ hoop.x += 1200
125
+ hoop.y = new_y
126
+ hoop.active = true
127
+ end
128
+
121
129
  def button_down id
122
130
  close if id == Gosu::KbEscape
123
131
  @player.hop if id == Gosu::KbSpace
@@ -127,7 +135,14 @@ class RubyhopGame < Gosu::Window
127
135
  @player.update
128
136
  @hoops.each do |hoop|
129
137
  hoop.update
138
+ reset_hoop!(hoop) if hoop.x < -200
130
139
  @player.die! if hoop.miss @player
140
+ # increase score and flag as inactive
141
+ if hoop.active && @player.alive && hoop.x < @player.x
142
+ @score += 1
143
+ hoop.active = false
144
+ self.caption = "Ruby Hop: #{@score}"
145
+ end
131
146
  end
132
147
  end
133
148
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-08 00:00:00.000000000 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc