From 00e85147c9a1dd35a0857f361e5833a1c25f4a0a Mon Sep 17 00:00:00 2001 From: Amir Rajan Date: Sat, 10 Apr 2021 03:51:14 -0500 Subject: Synced from DRGTK 2.10. --- docs/docs.html | 34903 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 24516 insertions(+), 10387 deletions(-) (limited to 'docs/docs.html') diff --git a/docs/docs.html b/docs/docs.html index 8fafcb1..39d0086 100644 --- a/docs/docs.html +++ b/docs/docs.html @@ -1,208 +1,56 @@ DragonRuby Game Toolkit Documentation - +

Table Of Contents

+
  • DragonRuby Game Toolkit Live Docs
  • +
  • Hello World
  • +
  • Join the Discord and Subscribe to the News Letter
  • +
  • Watch Some Intro Videos
  • +
  • Getting Started Tutorial
  • +
  • Deploying To Itch.io
  • +
  • Deploying To Mobile Devices
  • +
  • DragonRuby's Philosophy
  • +
  • Frequently Asked Questions, Comments, and Concerns
  • +
  • RECIPIES:
  • +
  • DOCS: GTK::Runtime
  • +
  • SUMMARY: def tick args; end;
  • +
  • DOCS: GTK::Runtime#reset
  • +
  • DOCS: GTK::Runtime#calcstringbox
  • +
  • DOCS: GTK::Runtime#write_file
  • +
  • DOCS: Array
  • +
  • DOCS: Array#map
  • +
  • DOCS: Array#each
  • +
  • DOCS: Array#reject_nil
  • +
  • DOCS: Array#reject_false
  • +
  • DOCS: Array#product
  • +
  • DOCS: Array#map_2d
  • +
  • DOCS: Array#include_any?
  • +
  • DOCS: Array#any_intersect_rect?
  • +
  • DOCS: GTK::Args#audio
  • +
  • DOCS: GTK::Outputs
  • +
  • DOCS: GTK::Outputs#solids
  • +
  • DOCS: GTK::Outputs#borders
  • +
  • DOCS: GTK::Outputs#screenshots
  • +
  • DOCS: GTK::Mouse
  • +
  • DOCS: GTK::MousePoint
  • +
  • DOCS: GTK::OpenEntity
  • +
  • DOCS: GTK::OpenEntity#as_hash
  • +
  • DOCS: Numeric#frame_index
  • +
  • DOCS: Numeric#elapsed_time
  • +
  • DOCS: Numeric#elapsed?
  • +
  • DOCS: Numeric#created?
  • +
  • DOCS: Kernel
  • +
  • DOCS: Kernel::tick_count
  • +
  • DOCS: Kernel::global_tick_count
  • +
  • DOCS: Geometry
  • +
  • DOCS: GTK::Geometry#scale_rect
  • +
  • Source Code
  • +

    DragonRuby Game Toolkit Live Docs

    @@ -211,8 +59,8 @@ The information contained here is all available via the DragonRuby Console. You

    To search docs you can type docs_search "SEARCH TERM" or if you want to get fancy you can provide a lambda to filter documentation:

    -
    docs_search { |entry| (entry.include? "Array") && (!entry.include? "Enumerable") }
    -
    +
    docs_search { |entry| (entry.include? "Array") && (!entry.include? "Enumerable") }
    +

    @@ -262,7 +110,7 @@ You may also want to try this free course provided at https://en.wikipedia.org/wiki/Ryan_C._Gordon).

    -

    Introduction

    +

    Introduction

    Welcome!

    @@ -278,14 +126,14 @@ Did you not know that? Did you think you couldn't write a game because you're a

    Here, we're going to be programming in a language called "Ruby." In the interest of full disclosure, I (Ryan Gordon) wrote the C parts of this toolkit and Ruby looks a little strange to me (Amir Rajan wrote the Ruby parts, discounting the parts I mangled), but I'm going to walk you through the basics because we're all learning together, and if you mostly think of yourself as someone that writes C (or C++, C#, Objective-C), PHP, or Java, then you're only a step behind me right now.

    -

    Prerequisites

    +

    Prerequisites

    Here's the most important thing you should know: Ruby lets you do some complicated things really easily, and you can learn that stuff later. I'm going to show you one or two cool tricks, but that's all.

    Do you know what an if statement is? A for-loop? An array? That's all you'll need to start.

    -

    The Game Loop

    +

    The Game Loop

    Ok, here are few rules with regards to game development with GTK:

    @@ -300,18 +148,18 @@ That's an entire video game in one run-on sentence.

    Here's that function. You're going to want to put this in mygame/app/main.rb, because that's where we'll look for it by default. Load it up in your favorite text editor.

    -
    def tick args
    +
    def tick args
       args.outputs.labels << [580, 400, 'Hello World!']
     end
    -
    +

    Now run dragonruby ...did you get a window with "Hello World!" written in it? Good, you're officially a game developer!

    -

    Breakdown Of The tick Method

    +

    Breakdown Of The tick Method

    mygame/app/main.rb, is where the Ruby source code is located. This looks a little strange, so I'll break it down line by line. In Ruby, a '#' character starts a single-line comment, so I'll talk about this inline.

    -
    # This "def"ines a function, named "tick," which takes a single argument
    +
    # This "def"ines a function, named "tick," which takes a single argument
     # named "args". DragonRuby looks for this function and calls it every
     # frame, 60 times a second. "args" is a magic structure with lots of
     # information in it. You can set variables in there for your own game state,
    @@ -328,11 +176,11 @@ def tick args
       # args.outputs.labels)
       args.outputs.labels << [580, 400, 'Hello World!']
     end
    -
    +

    Once your tick function finishes, we look at all the arrays you made and figure out how to draw it. You don't need to know about graphics APIs. You're just setting up some arrays! DragonRuby clears out these arrays every frame, so you just need to add what you need _right now_ each time.

    -

    Rendering A Sprite

    +

    Rendering A Sprite

    Now let's spice this up a little.

    @@ -342,18 +190,18 @@ We're going to add some graphics. Each 2D image in DragonRuby is called a "sprit

    There's a "dragonruby.png" file included, just to get you started. Let's have it draw every frame with our text:

    -
    def tick args
    +
    def tick args
       args.outputs.labels  << [580, 400, 'Hello World!']
       args.outputs.sprites << [576, 100, 128, 101, 'dragonruby.png']
     end
    -
    +

    (Pro Tip: you don't have to restart DragonRuby to test your changes; when you save main.rb, DragonRuby will notice and reload your program.)

    That .sprites line says "add a sprite to the list of sprites we're drawing, and draw it at position (576, 100) at a size of 128x101 pixels". You can find the image to draw at dragonruby.png.

    -

    Coordinate System and Virtual Canvas

    +

    Coordinate System and Virtual Canvas

    Quick note about coordinates: (0, 0) is the bottom left corner of the screen, and positive numbers go up and to the right. This is more "geometrically correct," even if it's not how you remember doing 2D graphics, but we chose this for a simpler reason: when you're making Super Mario Brothers and you want Mario to jump, you should be able to add to Mario's y position as he goes up and subtract as he falls. It makes things easier to understand.

    @@ -363,17 +211,17 @@ Also: your game screen is _always_ 1280x720 pixels. If you resize the window, we

    Ok, now we have an image on the screen, let's animate it:

    -
    def tick args
    +
    def tick args
       args.state.rotation  ||= 0
       args.outputs.labels  << [580, 400, 'Hello World!' ]
       args.outputs.sprites << [576, 100, 128, 101, 'dragonruby.png', args.state.rotation]
       args.state.rotation  -= 1
     end
    -
    +

    Now you can see that this function is getting called a lot!

    -

    Game State

    +

    Game State

    Here's a fun Ruby thing: args.state.rotation ||= 0 is shorthand for "if args.state.rotation isn't initialized, set it to zero." It's a nice way to embed your initialization code right next to where you need the variable.

    @@ -383,18 +231,18 @@ Here's a fun Ruby thing: args.state.rotation ||= 0 is shorthand for

    In this case, the current rotation of our sprite, which is happily spinning at 60 frames per second. If you don't specify rotation (or alpha, or color modulation, or a source rectangle, etc), DragonRuby picks a reasonable default, and the array is ordered by the most likely things you need to tell us: position, size, name.

    -

    There Is No Delta Time

    +

    There Is No Delta Time

    One thing we decided to do in DragonRuby is not make you worry about delta time: your function runs at 60 frames per second (about 16 milliseconds) and that's that. Having to worry about framerate is something massive triple-AAA games do, but for fun little 2D games? You'd have to work really hard to not hit 60fps. All your drawing is happening on a GPU designed to run Fortnite quickly; it can definitely handle this.

    Since we didn't make you worry about delta time, you can just move the rotation by 1 every time and it works without you having to keep track of time and math. Want it to move faster? Subtract 2.

    -

    Handling User Input

    +

    Handling User Input

    Now, let's move that image around.

    -
    def tick args
    +
    def tick args
       args.state.rotation ||= 0
       args.state.x ||= 576
       args.state.y ||= 100
    @@ -414,11 +262,11 @@ Now, let's move that image around.
     
       args.state.rotation -= 1
     end
    -
    +

    Everywhere you click your mouse, the image moves there. We set a default location for it with args.state.x ||= 576, and then we change those variables when we see the mouse button in action. You can get at the keyboard and game controllers in similar ways.

    -

    Coding On A Raspberry Pi

    +

    Coding On A Raspberry Pi

    We have only tested DragonRuby on a Raspberry Pi 3, Models B and B+, but we believe it _should_ work on any model with comparable specs.

    @@ -428,8 +276,8 @@ If you're running DragonRuby Game Toolkit on a Raspberry Pi, or trying to run a

    You're probably running a desktop environment: menus, apps, web browsers, etc. This is okay! Launch the terminal app and type:

    -
    do raspi-config
    -
    +
    do raspi-config
    +

    It'll ask you for your password (if you don't know, try "raspberry"), and then give you a menu of options. Find your way to "Advanced Options", then "GL Driver", and change this to "GL (Full KMS)" ... not "fake KMS," which is also listed there. Save and reboot. In theory, this should fix the problem.

    @@ -439,51 +287,15 @@ If you're _still_ having problems and have a Raspberry Pi 2 or better, go back t

    Note that you can also run DragonRuby without X11 at all: if you run it from a virtual terminal it will render fullscreen and won't need the "Full KMS" option. This might be attractive if you want to use it as a game console sort of thing, or develop over ssh, or launch it from RetroPie, etc.

    -

    Conclusion

    +

    Conclusion

    There is a lot more you can do with DragonRuby, but now you've already got just about everything you need to make a simple game. After all, even the most fancy games are just creating objects and moving them around. Experiment a little. Add a few more things and have them interact in small ways. Want something to go away? Just don't add it to args.output anymore.

    -

    IMPORTANT: Go through all of the sample apps! Study them thoroughly!! No really, you should definitely do this!

    -

    -Now that you've completed the Hello World tutorial. Head over to the `samples` directory. It is very very important that you study the sample apps thoroughly! Go through them in order. Here is a short description of each sample app. -

    -

    Guided Samples

    -
      -
    1. samples/00_learn_ruby_optional: This directory contains sample apps that will help you learn the language.
    2. -
    3. samples/01_rendering_basics: This set of samples will show you how to render basic primitives such as labels, solids, borders, lines, sprites, and how to play sounds.
    4. -
    5. samples/02_input_basics: This set of samples show you how to accept input from the mouse, keyboard, and controllers.
    6. -
    7. samples/03_rendering_sprites: This set of samples shows you all the different ways to render sprites (including how to use a sprite sheet).
    8. -
    9. samples/04_physics_and_collision: This set of samples shows how to do various types of collisions and physics.
    10. -
    11. samples/05_mouse: This set of samples show more advanced usages of the mouse.
    12. -
    13. samples/06_save_load: This set of samples show how to save and load game data.
    14. -
    15. samples/07_advanced_rendering: This set of samples show how to programmatically render sprites using render targets.
    16. -
    17. samples/08_tweening_lerping_easing_functions: This set of samples show how to perform animations.
    18. -
    19. samples/09_performance: This set of samples show how to handle performance issues when a large number of sprites on the screen.
    20. -
    21. samples/10_advanced_debugging: This set of samples show how advanced debugging techniques and testing techniques.
    22. -
    23. samples/11_http: This set of samples show how use http.
    24. -
    -

    Sample Games

    -

    -There are samples that contain the path samples/99_*. The sample apps that are prefixed with 99_ show non-trivial implemementations for a real game: -

    -
      -
    1. 3D Cube: Shows how to do faux 3D in DragonRuby.
    2. -
    3. Dueling Starships: A two player top-down versus game where each player controls a ship.
    4. -
    5. Flappy Dragon: DragonRuby's clone of Flappy Bird.
    6. -
    7. Pong: A simple implementation of the game Pong.
    8. -
    9. Snakemoji: The classic game of Snake but with all of the code written using emojis (sometimes you just have to have a little fun).
    10. -
    11. Solar System: A simulation of our solar system.
    12. -
    13. Crafting Starting Point: A starting point for those that want to build a crafting game.
    14. -
    15. Dev Tools: A set of sample apps that show how you can extend DragonRuby's Console, starting point for a tile editor, and a starting point for a paint app.
    16. -
    17. LOWREZ: Sample apps that show how to render at different resolutions.
    18. -
    19. RPG: Various sample apps that show how to create narrative, topdown, tactical grid-based, and roguelike RPGs.
    20. -
    21. Platformers: Various sample apps that show how to create different kinds of physics/collision based platformers.
    22. -

    Deploying To Itch.io

    Once you've built your game, you're all set to deploy! Good luck in your game dev journey and if you get stuck, come to the Discord channel!

    -

    Creating Your Game Landing Page

    +

    Creating Your Game Landing Page

    Log into Itch.io and go to https://itch.io/game/new.

    @@ -498,28 +310,28 @@ Log into Itch.io and go to https://itch.io/ga

    You can fill out all the other options later.

    -

    Update Your Game's Metadata

    +

    Update Your Game's Metadata

    Point your text editor at mygame/metadata/game_metadata.txt and make it look like this:

    NOTE: Remove the # at the beginning of each line.

    -
    devid=bob
    +
    devid=bob
     devtitle=Bob The Game Developer
     gameid=mygame
     gametitle=My Game
     version=0.1
    -
    +

    The devid property is the username you use to log into Itch.io. The devtitle is your name or company name (it can contain spaces). The gameid is the Project URL value. The gametitle is the name of your game (it can contain spaces). The version can be any major.minor number format.

    -

    Building Your Game For Distribution

    +

    Building Your Game For Distribution

    Open up the terminal and run this from the command line:

    -
    ./dragonruby-publish --only-package mygame
    -
    +
    ./dragonruby-publish --only-package mygame
    +

    (if you're on Windows, don't put the "./" on the front. That's a Mac and Linux thing.)

    @@ -532,8 +344,8 @@ For the HTML version of your game after you upload it. Check the checkbox labele

    For subsequent updates you can use an automated deployment to Itch.io:

    -
    ./dragonruby-publish mygame
    -
    +
    ./dragonruby-publish mygame
    +

    DragonRuby will package _and publish_ your game to itch.io! Tell your friends to go to your game's very own webpage and buy it!

    @@ -550,16 +362,16 @@ To deploy to iOS, you need to have a Mac running MacOS Catalina, an iOS device,

    To deploy to Android, you need to have an Android emulator/device, and a environment that is able to run Android SDK. dragonruby-publish will create an APK for you. From there, you can sign the APK and install it to your device. The signing and installation procedure varies from OS to OS. Here's an example of what the command might look like:

    -
    > adb logcat -e mygame # you'll want to run this in a separate terminal
    +
    > adb logcat -e mygame # you'll want to run this in a separate terminal
     > keytool -genkey -v -keystore mygame.keystore -alias mygame -keyalg RSA -keysize 2048 -validity 10000
     > apksigner sign --ks mygame.keystore mygame-android.apk
     > adb install mygame-android.apk
    -
    +

    DragonRuby's Philosophy

    The following tenants of DragonRuby are what set us apart from other game engines. Given that Game Toolkit is a relatively new engine, there are definitely features that are missing. So having a big check list of "all the cool things" is not this engine's forte. This is compensated with a strong commitment to the following principals.

    -

    Challenge The Status Quo

    +

    Challenge The Status Quo

    Game engines of today are in a local maximum and don't take into consideration the challenges of this day and age. Unity and GameMaker specifically rot your brain. It's not sufficient to say:

    @@ -571,51 +383,49 @@ But that's how we've always done it.

    It's a hard pill to swallow, but forget blindly accepted best practices and try to figure out the underlying motivation for a specific approach to game development. Collaborate with us.

    -

    Continuity of Design

    +

    Continuity of Design

    -There is a programming idiom in software called "the pit of success". The term normalizes up front pain as a necessity in the (hopes that the investment will yield dividends "when you become successful"). This results in more "Enterprise TM" code upfront, and makes it more difficult to get started when you are new to programming. +There is a programming idiom in software called "The Pit of Success". The term normalizes upfront pain as a necessity/requirement in the hopes that the investment will yield dividends "when you become successful" or "when the code becomes more complicated". This approach to development is strongly discouraged by us. It leads to over-architected and unnecessary code; creates barriers to rapid prototyping and shipping a game; and overwhelms beginners who are new to the engine or programming in general.

    -DragonRuby's philosophy is to provide a spectrum across the "make it fast" vs "make it right" spectrum and provide incremental, intuitive transitions between points on that spectrum. This is captured in how render primitives can be represented as tuples/arrays, hashes, open structs/entities, and then finally classes (as opposed to forcing devs to use classes upfront). +DragonRuby's philosophy is to provide multiple options across the "make it fast" vs "make it right" spectrum, with incremental/intuitive transitions between the options provided. A concrete example of this philosophy would be render primitives: the spectrum of options allows renderable constructs take the form of tuples/arrays (easy to pickup, simple, and fast to code/prototype with), hashes (a little more work, but gives you the ability to add additional properties), open and string entities (more work than hashes, but yields cleaner apis), and finally - if you really need full power/flexibility in rendering - classes (which take the most amount of code and programming knowledge to create).

    -

    Release Often And Soon

    +

    Release Early and Often

    -The biggest mistake game devs make is spending too much time in isolation building their game. Release something, however small, and release it quickly. +The biggest mistake game devs make is spending too much time in isolation building their game. Release something, however small, and release it soon.

    Stop worrying about everything being pixel perfect. Don't wait until your game is 100% complete. Build your game publicly and iterate. Post in the #show-and-tell channel in the community Discord. You'll find a lot of support and encouragement there.

    -Remember: +Real artists ship. Remember that.

    -
    -

    -Real artists ship. -

    -
    -

    Sustainable And Ethical Monetization

    +

    Sustainable And Ethical Monetization

    We all aspire to put food on the table doing what we love. Whether it is building games, writing tools to support game development, or anything in between.

    Charge a fair amount of money for the things you create. It's expected and encouraged within the community. Give what you create away for free to those that can't afford it.

    -

    Sustainable And Ethical Open Source

    +

    +If you are gainfully employed, pay full price for the things you use. If you do end up getting something at a discount, pay the difference "forward" to someone else. +

    +

    Sustainable And Ethical Open Source

    This goes hand in hand with sustainable and ethical monetization. The current state of open source is not sustainable. There is an immense amount of contributor burnout. Users of open source expect everything to be free, and few give back. This is a problem we want to fix (we're still trying to figure out the best solution).

    So, don't be "that guy" in the Discord that says "DragonRuby should be free and open source!" You will be personally flogged by Amir.

    -

    People Over Entities

    +

    People Over Entities

    We prioritize the endorsement of real people over faceless entities. This game engine, and other products we create, are not insignificant line items of a large company. And you aren't a generic "commodity" or "corporate resource". So be active in the community Discord and you'll reap the benefits as more devs use DragonRuby.

    -

    Building A Game Should Be Fun And Bring Happiness

    +

    Building A Game Should Be Fun And Bring Happiness

    We will prioritize the removal of pain. The aesthetics of Ruby make it such a joy to work with, and we want to capture that within the engine.

    -

    Real World Application Drives Features

    +

    Real World Application Drives Features

    We are bombarded by marketing speak day in and day out. We don't do that here. There are things that are really great in the engine, and things that need a lot of work. Collaborate with us so we can help you reach your goals. Ask for features you actually need as opposed to anything speculative.

    @@ -626,8 +436,8 @@ We want DragonRuby to *actually* help you build the game you want to build (as o

    Here are questions, comments, and concerns that frequently come up.

    -

    Frequently Asked Questions

    -

    What is DragonRuby LLP?

    +

    Frequently Asked Questions

    +

    What is DragonRuby LLP?

    DragonRuby LLP is a partnership of four devs who came together with the goal of bringing the aesthetics and joy of Ruby, everywhere possible.

    @@ -652,7 +462,7 @@ NOTE: We leave the "A DragonRuby LLP Product" off of this one because that just

    NOTE: Devs who use DragonRuby are "Dragon Riders/Riders of Dragons". That's a bad ass identifier huh?

    -

    What is DragonRuby?

    +

    What is DragonRuby?

    The response to this question requires a few subparts. First we need to clarify some terms. Specifically _language specification_ vs _runtime_.

    @@ -703,7 +513,7 @@ These levels allow us to stay up to date with open source implementations of Rub

    DragonRuby is a Ruby runtime implementation that takes all the lessons we've learned from MRI/CRuby, and merges it with the latest and greatest compiler and OSS technologies.

    -

    How is DragonRuby different than MRI?

    +

    How is DragonRuby different than MRI?

    DragonRuby supports a subset of MRI apis. Our target is to support all of mRuby's standard lib. There are challenges to this given the number of platforms we are trying to support (specifically console).

    @@ -718,11 +528,11 @@ You can use DragonRuby's Console within the game to inspect object and execute s
    • Any code you write in there will be executed when you change the file. You can organize different pieces of code using the repl method:
    -
    repl do
    +
    repl do
       puts "hello world"
       puts 1 + 1
     end
    -
    +
    -- cgit v1.2.3