Skip to content

EnterName and HighScore GameStates not working as expected #59

@RyanPadveen

Description

@RyanPadveen

I get a black screen. Am I using these GameStates correctly?

require 'rubygems' rescue nil
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), "..", "..", "lib")
require 'chingu'
include Gosu
include Chingu

class Game < Chingu::Window
  def initialize
    super
  end
  def setup
    switch_game_state(MainState)
  end
end

class MainState < Chingu::GameState
  def initialize
    super
    $name = "Player"
    $points = 500
    $high_score_list = Chingu::HighScoreList.load(:size => 10)
    $window.push_game_state(GameStates::EnterName.new(:callback => method(:got_name)))
  end

  def got_name(name)
    $name = name
    $newscore = $high_score_list.add({name: $name, score:   $points})
    puts "Got name: #{name}"
    pop_game_state
    $window.switch_game_state(HighScores)
  end
end

class HighScores < Chingu::GameState
  def initialize
    super
    create_text
  end

  def create_text
    $high_score_list.each_with_index do |high_score, index|
      y = index * 25 + 100
      Text.create(high_score[:name], :x => 200, :y => y, :size => 20)
      Text.create(high_score[:score], :x => 400, :y => y, :size => 20)
    end
  end
end

Game.new.show

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions