Simple typing game with DragonRuby

Previously, I wrote an article I played with DragonRuby GTK (Game Toolkit).

I get tired of posting Hello, World on Qiita (!), But this time I'm still touching it.

Suddenly, I wanted to make a typing game, so I made a simple one for the practice.

What I made

tor.gif

The text will be displayed and you just need to enter it. There is no time over, that's it.

You can play with your web browser from this link. https://tnantoka.github.io/typing-on-rails/

The source code is on GitHub. https://github.com/tnantoka/typing-on-rails

I borrowed the text to type from the sample code in Rails Guides (https://guides.rubyonrails.org/), so it's named ** Typing on Rails **.

Tips

Basically, I can make it with the contents of I played with DragonRuby GTK (Game Toolkit). Some of them were not written, so make a note of them.

Change the background color

You can change it by setting [R, G, B] to ʻoutputs.background_color`.

#Red! !! !!
outputs.background_color = [255, 0, 0]

Take a list of pressed keys

I can get the input status with ʻinputs.keyboard.key_up.space` that I used last time. This time I tried to implement it by looking at the list of keys.

You can get the entered keys with ʻinputs.keyboard.key_down.truthy_keys`.

#Enter a
[:char, :raw_key, :a]

# A(Shift +a) Enter
[:char, :raw_key, :a, :shift]

# Command + Shift +Enter a
[:char, :raw_key, :a, :shift, :meta]

Label size differs depending on the font

You can specify -10 to 10 for size_enum of Label, but even if you specify the same 10, the size will be quite different depending on the font.

For example, if you arrange the following four fonts side by side ...

Screen Shot 2020-06-20 at 14.10.57.png

It will be like this.

It seems that you need to adjust size_enum depending on the font you use.

Published game does not work

When I published the packaged build on GitHub pages, it didn't work.

The cause is

Server reported failure downloading 'app/.main.rb.swp'!

Was the error. Git will be ignored by .gitignore, but of course DragonRuby will not ignore it ...

If you look at builds / typing-on-rails-html5-0.1 / manifest.json, you may notice that it contains unnecessary files. (The .swp file this time was also included)

Summary

I made it in less than 200 lines. (Although I haven't counted the amount of Primitives.rb I made last time) It's easy.

Recommended Posts

Simple typing game with DragonRuby
I made a simple typing game with tkinter in Python
I played with DragonRuby GTK (Game Toolkit)
[Python] Make a simple maze game with Pyxel
Programming education game with SenseHAT
How to make a simple Flappy Bird game with pygame
[Python] Make a simple maze game with Pyxel-Make enemies appear-
Balloon splitting game with pygame
Simple synonym dictionary with sudachipy
Simple classification model with neural network
Creating a simple app with flask
Othello game development made with Python
Automate simple tasks with Python Part0
Solving game theory with combinatorial optimization
Sugoroku game and addition game with python