Permalink
Browse files

refactors restart, game doesn't stop

  • Loading branch information...
1 parent 490d20b commit 378ef9266e9061949d8e36308f8cb8c5e7a79b2f @benfb committed Jul 5, 2012
Showing with 17 additions and 46 deletions.
  1. +1 −8 lib/ball.rb
  2. +2 −8 lib/fifty_ball.rb
  3. +1 −8 lib/hundred_ball.rb
  4. +11 −14 lib/spritedodge.rb
  5. +2 −8 lib/ten_ball.rb
View
9 lib/ball.rb
@@ -1,4 +1,5 @@
class Ball
+ attr_accessor :x, :y
def initialize(game_window)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "img/ball.png", true)
@@ -23,14 +24,6 @@ def draw_rot
@icon.draw_rot(@x,@y,2, @rotation += 3, 0.5, 0.5, 1, 1)
end
- def x
- @x
- end
-
- def y
- @y
- end
-
def reset
@y = 0
@x = rand(@game_window.width)
View
10 lib/fifty_ball.rb
@@ -1,4 +1,6 @@
class Fifty_Ball
+ attr_accessor :x, :y
+
def initialize(game_window)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "img/fifty_ball.png", true)
@@ -19,14 +21,6 @@ def draw
@icon.draw_rot(@x,@y,3, 0, 0.5, 0.5)
end
- def x
- @x
- end
-
- def y
- @y
- end
-
def reset
@y = 0
@x = rand(@game_window.width)
View
9 lib/hundred_ball.rb
@@ -1,4 +1,5 @@
class Hundred_Ball
+ attr_accessor :x, :y
def initialize(game_window)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "img/hundred_ball.png", true)
@@ -19,14 +20,6 @@ def draw
@icon.draw_rot(@x,@y,3,0,0.5,0.5)
end
- def x
- @x
- end
-
- def y
- @y
- end
-
def reset
@y = 0
@x = rand(@game_window.width)
View
25 lib/spritedodge.rb
@@ -30,7 +30,7 @@ def initialize
@get_sound = Gosu::Sample.new(self, "sound/get.wav")
@bgnumber = rand(5)
@background_image = Gosu::Image.new(self, "bg/#{@bgnumber}.png", true)
- @scores = []
+ @scores = [nil]
@score = 0
@health = 100
end
@@ -47,6 +47,9 @@ def button_down(id)
@running = false
close
end
+ if id == Gosu::Button::KbR
+ restart_game
+ end
end
def update
@@ -58,7 +61,7 @@ def update
if button_down? Gosu::Button::KbRight
@player1.move_right
end
-
+
@balls.each {|ball| ball.update}
@ten_balls.each {|ten_ball| ten_ball.update}
@@ -68,39 +71,33 @@ def update
@hundred_balls.each {|hundred_ball| hundred_ball.update}
if @player1.hit_by? @balls
- @health -= 10
+ @health -= 20
@hit_sound.play(vol=0.5, speed=1, looping=false)
- @hit = true
- stop_game
- @hit = false
end
if @player1.hit_by_good? @ten_balls
@score += 10
@get_sound.play(vol=0.5, speed=1, looping=false)
- stop_game
+ #stop_game
end
if @player1.hit_by_good? @fifty_balls
@score += 50
@get_sound.play(vol=0.5, speed=1, looping=false)
- stop_game
+ #stop_game
end
if @player1.hit_by_good? @hundred_balls
@score += 100
@get_sound.play(vol=0.5, speed=1, looping=false)
- stop_game
+ #stop_game
end
else
# The game is currently stopped
if button_down? Gosu::Button::KbSpace
refresh_game
end
- if button_down? Gosu::Button::KbR
- restart_game
- end
end
end
@@ -149,7 +146,7 @@ def restart_game
end
end
+window = SpriteDodge.new
+window.show
end
-window = SpriteDodge.new
-window.show
View
10 lib/ten_ball.rb
@@ -1,4 +1,6 @@
class Ten_Ball
+ attr_accessor :x, :y
+
def initialize(game_window)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "img/ten_ball.png", true)
@@ -19,14 +21,6 @@ def draw
@icon.draw_rot(@x,@y,3,0,0.5,0.5)
end
- def x
- @x
- end
-
- def y
- @y
- end
-
def reset
@y = 0
@x = rand(@game_window.width)

0 comments on commit 378ef92

Please sign in to comment.