MinecraftU / 2021-computer-adventures

Repository for our 2021 Computer Adventures Ruby project!
0 stars 0 forks source link

Display leaderboard on start and game over screens #70

Closed jamespeilunli closed 3 years ago

jamespeilunli commented 3 years ago

closes #67 closes #69

By passing a formatted string with the leaderboard text to Text.new from Ruby2D, we can display the leaderboard on the start screen and game over screen. To avoid repetition, this code is put into the display_leaderboard method.

jamespeilunli commented 3 years ago

Should be good.

dealingwith commented 3 years ago

Not sure what's happening, I'm getting this shortly after the game over screen renders:

Error: (TTF_OpenFont) Couldn't open AzeretMono-Light.ttf
Traceback (most recent call last):
    10: from tetris.rb:249:in `<main>'
     9: from /Users/danielmiller/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/ruby2d-0.10.0/lib/ruby2d/dsl.rb:39:in `show'
     8: from /Users/danielmiller/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/ruby2d-0.10.0/lib/ruby2d/window.rb:619:in `show'
     7: from /Users/danielmiller/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/ruby2d-0.10.0/lib/ruby2d/window.rb:619:in `ext_show'
     6: from /Users/danielmiller/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/ruby2d-0.10.0/lib/ruby2d/window.rb:563:in `update_callback'
     5: from tetris.rb:198:in `block in <main>'
     4: from tetris.rb:66:in `display_leaderboard'
     3: from tetris.rb:66:in `each'
     2: from tetris.rb:67:in `block in display_leaderboard'
     1: from tetris.rb:67:in `new'
/Users/danielmiller/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/ruby2d-0.10.0/lib/ruby2d/text.rb:24:in `initialize': Text `DWM      200   1` cannot be created (Ruby2D::Error)

My only thought was the permissions on the actual font file weren't right, but they're ok. We might have to just try another font.

jamespeilunli commented 3 years ago

If you can, find a monospace (because then space characters wouldn't be the same width as other characters and my string formatting wouldn't work) font that you like and works for you. I found that Google Fonts is quite useful.

dealingwith commented 3 years ago

Ok I worked a little bit more on this tonight. I changed the font to a different one I downloaded from Google Fonts. At first I misspelled the file name and I got an error immediately when I tried to run the program. So it's looking for the font file immediately. But I still got the Error: (TTF_OpenFont) Couldn't open ShareTechMono-Regular.ttf error when it attempted to write the leaderboard.

dealingwith commented 3 years ago

Then I changed the scoreboard font to that same font and it works fine. So it's something specific about the use of the font in the spot added in this PR.

dealingwith commented 3 years ago

It's probably something to do with how the Text object is used here:

leaderboard_text << Text.new

dealingwith commented 3 years ago

Hmm, maybe not, that's used on the landing screen leaderboard without issue.

dealingwith commented 3 years ago

head scratch

dealingwith commented 3 years ago

This was the issue:

https://stackoverflow.com/questions/40617651/cannot-change-the-maximum-open-files-per-process-with-sysctl/40617652#40617652