creating game over screen

19 views
Skip to first unread message

anthony

unread,
Mar 9, 2011, 8:46:23 PM3/9/11
to ruby4kids
all right i am done with my game wooohooo!

but i am trying to make a screen when you lose it says "Game Over.
Restart?"
any ideas on how i can do it?

Johnny McNeil

unread,
Mar 9, 2011, 8:54:18 PM3/9/11
to ruby...@googlegroups.com
Simple. Follow the screencast here: http://ruby4kids.com/ruby4kids/videos/pause_game.mov

Then, I would just change it to when the game ends, it will draw the restart thing, and then in the 'else' part of the running 'if' statement, you can have the option of letting someone restart.

anthony

unread,
Mar 12, 2011, 9:09:51 AM3/12/11
to ruby4kids
alright umm... i get what your saying but when i do that i get a
message saying:
my_game.rb:80: syntax error, unexpected keyword_end, expecting $end

so could you show me where i would put it exactly

heres my code:

$: << File.expand_path(File.dirname(__FILE__))
require 'rubygems'
require 'gosu'
require 'player'
require 'ball'


class MyGame < Gosu::Window
def initialize
super(600, 600, false)
@player = Player.new(self)
@balls = 3.times.map {Ball.new(self)}
@running = true
@pause = false
@font = Gosu::Font.new(self, 'system', 32)
@font2 = Gosu::Font.new(self,'system', 32)
end

def button_down(id)
if id == Gosu::Button::KbP
if @pause== false
@pause = true
else
@pause = false
end
end
end


def update
if @pause == false

if @running
if button_down? Gosu::Button::KbLeft
@player.move_left
end

if button_down? Gosu::Button::KbRight
@player.move_right
end

if button_down? Gosu::Button::KbUp
@player.move_up
end

if button_down? Gosu::Button::KbDown
@player.move_down
end

@balls.each {|ball| ball.update}

if @player.hit_by? @balls
stop_game!
end
else
#the game is currently stopped
if button_down? Gosu::Button::KbEscape
restart_game
end
end
end
end

def draw
@player.draw
@balls.each {|ball| ball.draw}
end

def stop_game!
@running = false
end
end

def restart_game
@running = true
@balls.each {|ball| ball.reset!}
end
end

window = MyGame.new
window.show

thank you

Johnny McNeil

unread,
Mar 12, 2011, 12:19:49 PM3/12/11
to ruby...@googlegroups.com
I don't know for sure, but I think that on line 71 or 72 you have an extra 'end' statement. See if when you delete that if it works for you.
Reply all
Reply to author
Forward
0 new messages