I just started learning ruby and gosu. The code I am using right now is a reference from someone else code.
This is a 2 player Pong ruby game. The game is working and is able to play. I am trying to set it so that any player reach to the score of 10, the game will stopped and show the message "Player 1/2 wins" and prompt the players whether they want to continue playing.
My problem now is to show the message when one of the player score reach 10 followed by prompting the user if they want to continue.
(Disclaimer this is not my original code, i only use it to learn.)
if @player_1.score == 2
@state = :stopped
@message.draw_text('WIN',100,100,2)
end
if @player_2.score == 2
@state = :stopped
end
This code is inside class Gosu::Window (I can't quite figure out how to put the whole code here since this is my first time)
To show your "WINNER SCREEN" you must manage status also in DRAW method.
This is an example of my code in an RPG Game...
def draw
case @state
when ZOrdinals::GAME
main_draw
when ZOrdinals::MENU
@main_menu.draw
when ZOrdinals::BATTLE
@battle.draw
when ZOrdinals::DEAD
@dead = Dead.new(self) if @dead.nil?
@dead.draw
end
end
And this is the DEAD SCREEN code:
require_relative 'zordinals'
# Death screen
class Dead
def initialize(window)
@window = window
@image = Gosu::Image.new(File.dirname(__FILE__) + '../../images/die.png',
tileable: false)
end
def update; end
def draw
@image.draw((ZOrdinals::SCREEN_WIDTH / 2) - (@image.width / 2),
(ZOrdinals::SCREEN_HEIGHT / 2) - (@image.height / 2),
ZOrdinals::BACKGROUND)
end
end
You can do something like this for your problem...