From 161d498dc905f04b595c927309993acdcb4d394c Mon Sep 17 00:00:00 2001 From: Amir Rajan Date: Mon, 3 Aug 2020 18:09:21 -0500 Subject: synced with 1.13 --- docs/docs.html | 151 +++------------------------------------------------------ 1 file changed, 7 insertions(+), 144 deletions(-) (limited to 'docs/docs.html') diff --git a/docs/docs.html b/docs/docs.html index bb15adf..1640d49 100644 --- a/docs/docs.html +++ b/docs/docs.html @@ -28,8 +28,8 @@
  • Using args.state To Store Your Game State
  • Frequently Asked Questions, Comments, and Concerns
  • GTK::Runtime
  • -
  • GTK::Runtime#calcstringbox
  • GTK::Runtime#reset
  • +
  • GTK::Runtime#calcstringbox
  • Array
  • Array#map
  • Array#each
  • @@ -53,26 +53,22 @@
    - -

    DragonRuby Game Toolkit Live Docs

    +

    DragonRuby Game Toolkit Live Docs

    The information contained here is all available via the DragonRuby Console. You can Open the DragonRuby Console by pressing [`] [~] [²] [^] [º] or [§] within your game.

    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") }
     

    -

    Hello World

    Welcome to DragonRuby Game Toolkit. Take the steps below to get started.

    -

    Join the Discord and Subscribe to the News Letter

    Our Discord channel is http://discord.dragonruby.org. @@ -83,7 +79,6 @@ The News Letter will keep you in the loop with regards to current DragonRuby Eve

    Those who use DragonRuby are called Dragon Riders. This identity is incredibly important to us. When someone asks you:

    -

    What game engine do you use? @@ -92,13 +87,11 @@ What game engine do you use?

    Reply with:

    -

    I am a Dragon Rider.

    -

    Watch Some Intro Videos

    Each video is only 20 minutes and all of them will fit into a lunch break. So please watch them: @@ -114,12 +107,10 @@ The second and third videos are not required if you are proficient with Ruby, bu

    You may also want to try this free course provided at http://dragonruby.school.

    -

    Getting Started Tutorial

    This is a tutorial written by Ryan C Gordon (a Juggernaut in the industry who has contracted to Valve, Epic, Activision, and EA... check out his Wikipedia page: https://en.wikipedia.org/wiki/Ryan_C._Gordon).

    -

    Introduction

    Welcome! @@ -136,7 +127,6 @@ 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

    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. @@ -144,7 +134,6 @@ Here's the most important thing you should know: Ruby lets you do some complicat

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

    -

    The Game Loop

    Ok, here are few rules with regards to game development with GTK: @@ -160,7 +149,6 @@ 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
       args.outputs.labels << [580, 400, 'Hello World!']
     end
    @@ -168,12 +156,10 @@ 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

    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
     # named "args". DragonRuby looks for this function and calls it every
     # frame, 60 times a second. "args" is a magic structure with lots of
    @@ -195,7 +181,6 @@ 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

    Now let's spice this up a little. @@ -206,7 +191,6 @@ 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
       args.outputs.labels  << [580, 400, 'Hello World!']
       args.outputs.sprites << [576, 100, 128, 101, 'dragonruby.png']
    @@ -218,7 +202,6 @@ end
     

    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

    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. @@ -229,7 +212,6 @@ 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
       args.state.rotation  ||= 0
       args.outputs.labels  << [580, 400, 'Hello World!' ]
    @@ -240,7 +222,6 @@ end
     

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

    -

    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. @@ -248,7 +229,6 @@ Here's a fun Ruby thing: args.state.rotation ||= 0 is shorthand for

    args.state is a place you can hang your own data and have it survive past the life of the function call. 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

    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. @@ -256,12 +236,10 @@ One thing we decided to do in DragonRuby is not make you worry about delta time:

    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

    Now, let's move that image around.

    -
    def tick args
       args.state.rotation ||= 0
       args.state.x ||= 576
    @@ -286,7 +264,6 @@ 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

    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. @@ -297,7 +274,6 @@ 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
     

    @@ -309,12 +285,10 @@ 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

    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!!

    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. @@ -364,9 +338,7 @@ Now that you've completed the Hello World tutorial. Head over to the `samples` d

  • 14_sprite_limits_static_references: Upper limit for how many sprites can be rendered to the screen using static output collections (which are updated by reference as opposed to by value).
  • 15_collision_limits: How many collisions can be processed across many primitives.
  • 18_moddable_game: How you can make a game where content is authored by the player (modding support).
  • -
  • 19_lowrez_jam_01_hello_world: How to use render_targets to create a low resolution game.
  • -
  • 19_lowrez_jam_02_buttons: How to use render_targets to create a low resolution game.
  • -
  • 19_lowrez_jam_03_space_shooter: How to use render_targets to create a low resolution game.
  • +
  • 19_lowrez_jam: How to use render_targets to create a low resolution game.
  • 20_roguelike_starting_point: A starting point for a roguelike and explores concepts such as line of sight.
  • 20_roguelike_starting_point_two: A starting point for a roguelike where sprites are provided from a tile map/tile sheet.
  • 21_mailbox_usage: How to do interprocess communication.
  • @@ -392,7 +364,6 @@ Now that you've completed the Hello World tutorial. Head over to the `samples` d

    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

    Log into Itch.io and go to https://itch.io/game/new. @@ -408,7 +379,6 @@ 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

    Point your text editor at mygame/metadata/game_metadata.txt and make it look like this: @@ -416,7 +386,6 @@ Point your text editor at mygame/metadata/game_metadata.txt and make it look lik

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

    -
    vid=bob
     vtitle=Bob The Game Developer
     meid=mygame
    @@ -426,12 +395,10 @@ rsion=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

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

    -
    dragonruby-publish --only-package mygame
     

    @@ -446,7 +413,6 @@ 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
     

    @@ -455,17 +421,14 @@ DragonRuby will package _and publish_ your game to itch.io! Tell your friends to

    If you make changes to your game, just re-run dragonruby-publish and it'll update the downloads for you.

    -

    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

    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:

    -

    But that's how we've always done it. @@ -474,7 +437,6 @@ 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.

    -

    Release Often And Quickly

    The biggest mistake game devs make is spending too much time in isolation building their game. Release something, however small, and release it quickly. @@ -485,13 +447,11 @@ Stop worrying about everything being pixel perfect. Don't wait until your game i

    Remember:

    -

    Real artists ship.

    -

    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. @@ -499,7 +459,6 @@ We all aspire to put food on the table doing what we love. Whether it is buildin

    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

    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). @@ -507,17 +466,14 @@ This goes hand in hand with sustainable and ethical monetization. The current st

    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

    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

    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

    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. @@ -525,27 +481,22 @@ We are bombarded by marketing speak day in and day out. We don't do that here. T

    We want DragonRuby to *actually* help you build the game you want to build (as opposed to sell you something piece of demoware that doesn't work).

    -

    How To Determine What Frame You Are On

    There is a property on state called tick_count that is incremented by DragonRuby every time the tick method is called. The following code renders a label that displays the current tick_count.

    -
    def tick args
       args.outputs.labels << [10, 670, "#{args.state.tick_count}"]
     end
     
    -

    How To Get Current Framerate

    Current framerate is a top level property on the Game Toolkit Runtime and is accessible via args.gtk.current_framerate.

    -
    def tick args
       args.outputs.labels << [10, 710, "framerate: #{args.gtk.current_framerate.round}"]
     end
     
    -

    How To Render A Sprite Using An Array

    All file paths should use the forward slash / *not* backslash . Game Toolkit includes a number of sprites in the sprites folder (everything about your game is located in the mygame directory). @@ -556,7 +507,6 @@ The following code renders a sprite with a width and height args.outputs.sprites is used to render a sprite.

    -
    def tick args
       args.outputs.sprites << [
         640 - 50,                 # X
    @@ -567,12 +517,10 @@ The following code renders a sprite with a width and height
    -
     

    More Sprite Properties As An Array

    Here are all the properties you can set on a sprite.

    -
    def tick args
       args.outputs.sprites << [
         100,                       # X
    @@ -588,7 +536,6 @@ Here are all the properties you can set on a sprite.
       ]
     end
     
    -

    Different Sprite Representations

    Using ordinal positioning can get a little unruly given so many properties you have control over. @@ -596,7 +543,6 @@ Using ordinal positioning can get a little unruly given so many properties you h

    You can represent a sprite as a Hash:

    -
    def tick args
       args.outputs.sprites << {
         x: 640 - 50,
    @@ -623,7 +569,6 @@ end
     

    You can represent a sprite as an object:

    -
    # Create type with ALL sprite properties AND primitive_marker
     class Sprite
       attr_accessor :x, :y, :w, :h, :path, :angle, :a, :r, :g, :b,
    @@ -654,7 +599,6 @@ def tick args
                                               h: 50)
     end
     
    -

    How To Render A Label

    args.outputs.labels is used to render labels. @@ -665,24 +609,19 @@ Labels are how you display text. This code will go directly inside of the

    Here is the minimum code:

    -
    def tick args
       #                       X    Y    TEXT
       args.outputs.labels << [640, 360, "I am a black label."]
     end
     
    -

    A Colored Label

    -
    def tick args
       # A colored label
       #                       X    Y    TEXT,                   RED    GREEN  BLUE  ALPHA
       args.outputs.labels << [640, 360, "I am a redish label.", 255,     128,  128,   255]
     end
     
    -

    Extended Label Properties

    -
    def tick args
       # A colored label
       #                       X    Y     TEXT           SIZE  ALIGNMENT  RED  GREEN  BLUE  ALPHA  FONT FILE
    @@ -706,12 +645,10 @@ A SIZE_ENUM of 0 represents "default size". A ne
     

    An ALIGNMENT_ENUM of 0 represents "left aligned". 1 represents "center aligned". 2 represents "right aligned".

    -

    Rendering A Label As A Hash

    You can add additional metadata about your game within a label, which requires you to use a `Hash` instead.

    -
    def tick args
       args.outputs.labels << {
         x:              200,
    @@ -734,12 +671,10 @@ You can add additional metadata about your game within a label, which requires y
       }
     end
     
    -

    Getting The Size Of A Piece Of Text

    You can get the render size of any string using args.gtk.calcstringbox.

    -
    def tick args
       #                             TEXT           SIZE_ENUM  FONT
       w, h = args.gtk.calcstringbox("some string",         0, "font.ttf")
    @@ -755,12 +690,10 @@ You can get the render size of any string using args.gtk.calcstringbox
    -
     

    How To Play A Sound

    Sounds that end .wav will play once:

    -
    def tick args
       # Play a sound every second
       if (args.state.tick_count % 60) == 0
    @@ -771,7 +704,6 @@ end
     

    Sounds that end .ogg is considered background music and will loop:

    -
    def tick args
       # Start a sound loop at the beginning of the game
       if args.state.tick_count == 0
    @@ -782,7 +714,6 @@ end
     

    If you want to play a .ogg once as if it were a sound effect, you can do:

    -
    def tick args
       # Play a sound every second
       if (args.state.tick_count % 60) == 0
    @@ -790,7 +721,6 @@ If you want to play a .ogg once as if it were a sound effect, you c
       end
     end
     
    -

    Using args.state To Store Your Game State

    args.state is a open data structure that allows you to define properties that are arbitrarily nested. You don't need to define any kind of class. @@ -801,7 +731,6 @@ To initialize your game state, use the ||= operator. Any value on t

    To assign a value every frame, just use the = operator, but _make sure_ you've initialized a default value.

    -
    def tick args
       # initialize your game state ONCE
       args.player.x  ||= 0
    @@ -826,14 +755,11 @@ To assign a value every frame, just use the = operator, but _make s
       ]
     end
     
    -

    Frequently Asked Questions, Comments, and Concerns

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

    -

    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. @@ -861,12 +787,10 @@ 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?

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

    -

    Okay... so what is the difference between a language specification and a runtime?

    A runtime is an _implementation_ of a langauge specification. When people say "Ruby," they are usually referring to "the Ruby 3.0+ language specification implemented via the CRuby/MRI Runtime." @@ -874,12 +798,10 @@ A runtime is an _implementation_ of a langauge specification. When people say "R

    But, there are many Ruby Runtimes: CRuby/MRI, JRuby, Truffle, Rubinius, Artichoke, and (last but certainly not least) DragonRuby.

    -

    Okay... what language specification does DragonRuby use then?

    DragonRuby's goal is to be compliant with the ISO/IEC 30170:2012 standard. It's syntax is Ruby 2.x compatible, but also contains semantic changes that help it natively interface with platform specific libraries.

    -

    So... why another runtime?

    The elevator pitch is: @@ -887,7 +809,6 @@ The elevator pitch is:

    DragonRuby is a Multilevel Cross-platform Runtime. The "multiple levels" within the runtime allows us to target platforms no other Ruby can target: PC, Mac, Linux, Raspberry Pi, WASM, iOS, Android, Nintendo Switch, PS4, Xbox, and Scadia.

    -

    What does Multilevel Cross-platform mean?

    There are complexities associated with targeting all the platforms we support. Because of this, the runtime had to be architected in such a way that new platforms could be easily added (which lead to us partitioning the runtime internally): @@ -913,14 +834,11 @@ Levels 1 through 3 are fairly commonplace in many runtime implemenations (with l

    These levels allow us to stay up to date with open source implementations of Ruby; provide fast, native code execution on proprietary platforms; ensure good seperation between these two worlds; and provides a means to add new platforms without going insane.

    -

    Cool cool. So given that I understand everything to this point, can we answer the original question? What is DragonRuby?

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

    -

    Frequent Comments

    -

    But Ruby is dead.

    Let's check the official source for the answer to this question: isrubydead.com: https://isrubydead.com/. @@ -934,12 +852,10 @@ What really matters is _quality/maturity_. Here is the latest (StackOverflow Sur

    Let's stop making this comment shall we?

    -

    But Ruby is slow.

    That doesn't make any sense. A language specification can't be slow... it's a language spec. Sure, an _implementation/runtime_ can be slow though, but then we'd have to talk about which runtime.

    -

    Dynamic langauges are slow.

    They are certainly slower than statically compiled languages. With the processing power and compiler optimizations we have today, dynamic languages like Ruby are _fast enough_. @@ -950,9 +866,7 @@ Unless you are writing in some form of intermediate representation by hand, your

    NOTE: If you _are_ hand writing LLVM IR, we are always open to bringing on new partners with such a skillset. Email us ^_^.

    -

    Frequent Concerns

    -

    DragonRuby is not open source. That's not right.

    The current state of open source is unsustainable. Contributors work for free, most all open source repositories are serverly understaffed, and burnout from core members is rampant. @@ -966,7 +880,6 @@ If you have ideas on how we can do this, email us!

    If the reason above isn't sufficient, then definitely use something else.

    -

    DragonRuby is for pay. You should offer a free version.

    If you can afford to pay for DragonRuby, you should (and will). We don't go around telling writers that they should give us their books for free, and only require payment if we read the entire thing. It's time we stop asking that of software products. @@ -989,7 +902,6 @@ You qualify for a free, unrestricted license to DragonRuby products if any of th

    Just contact Amir at amir.rajan@dragonruby.org with a short explanation of your current situation and he'll set you up. No questions asked.

    -

    But still, you should offer a free version. So I can try it out and see if I like it.

    You can try our [web-based sandbox environment](). But it won't do the runtime justice. Or just come to our [Slack]() or [Discord]() channel and ask questions. We'd be happy to have a one on one video chat with you and show off all the cool stuff we're doing. @@ -997,7 +909,6 @@ You can try our [web-based sandbox environment](). But it won't do the runtime j

    Seriously just buy it. Get a refund if you don't like it. We make it stupid easy to do so.

    -

    I still think you should do a free version. Think of all people who would give it a shot.

    Free isn't a sustainable financial model. We don't want to spam your email. We don't want to collect usage data off of you either. We just want to provide quality toolchains to quality developers (as opposed to a large quantity of developers). @@ -1005,7 +916,6 @@ Free isn't a sustainable financial model. We don't want to spam your email. We d

    The peiple that pay for DragonRuby and make an effort to understand it are the ones we want to build a community around, partner with, and collaborate with. So having that small monetary wall deters entitled individuals that don't value the same things we do.

    -

    What if I build something with DragonRuby, but DragonRuby LLP becomes insolvent.

    That won't happen if the development world stop asking for free stuff and non-trivially compensate open source developers. Look, we want to be able to work on the stuff we love, every day of our lives. And we'll go to great lengths to make that happen. @@ -1013,33 +923,27 @@ That won't happen if the development world stop asking for free stuff and non-tr

    But, in the event that sad day comes, our partnershiop bylaws state that _all_ DragonRuby IP that can be legally open sourced, will be released under a permissive license.

    -

    GTK::Runtime

    The GTK::Runtime class is the core of DragonRuby. It is globally accessible via $gtk.

    - +

    GTK::Runtime#reset

    +

    +This function will reset Kernel.tick_count to 0 and will remove all data from args.state. +

    GTK::Runtime#calcstringbox

    This function returns the width and height of a string.

    -
    def tick args
       args.state.string_size           ||= args.gtk.calcstringbox "Hello World"
       args.state.string_size_font_size ||= args.gtk.calcstringbox "Hello World"
     end
     
    - -

    GTK::Runtime#reset

    -

    -This function will reset Kernel.tick_count to 0 and will remove all data from args.state. -

    -

    Array

    The Array class has been extend to provide methods that will help in common game development tasks. Array is one of the most powerful classes in Ruby and a very fundamental component of Game Toolkit.

    -

    Array#map

    The function given a block returns a new Enumerable of values. @@ -1047,7 +951,6 @@ The function given a block returns a new Enumerable of values.

    Example of using Array#map in conjunction with args.state and args.outputs.sprites to render sprites to the screen.

    -
    def tick args
       # define the colors of the rainbow in ~args.state~
       # as an ~Array~ of ~Hash~es with :order and :name.
    @@ -1079,7 +982,6 @@ Example of using Array#map in conjunction with args.state
    -
     

    Array#each

    The function, given a block, invokes the block for each item in the Array. Array#each is synonymous to foreach constructs in other languages. @@ -1087,7 +989,6 @@ The function, given a block, invokes the block for each item in the Array<

    Example of using Array#each in conjunction with args.state and args.outputs.sprites to render sprites to the screen:

    -
    def tick args
       # define the colors of the rainbow in ~args.state~
       # as an ~Array~ of ~Hash~es with :order and :name.
    @@ -1118,12 +1019,10 @@ Example of using Array#each in conjunction with args.state
    -
     

    Array#reject_nil

    Returns an Enumerable rejecting items that are nil, this is an alias for Array#compact:

    -
    repl do
       a = [1, nil, 4, false, :a]
       puts a.reject_nil
    @@ -1132,19 +1031,16 @@ Returns an Enumerable rejecting items that are nil, th
       # => [1, 4, false, :a]
     end
     
    -

    Array#reject_false

    Returns an `Enumerable` rejecting items that are `nil` or `false`.

    -
    repl do
       a = [1, nil, 4, false, :a]
       puts a.reject_false
       # => [1, 4, :a]
     end
     
    -

    Array#product

    Returns all combinations of values between two arrays. @@ -1152,14 +1048,12 @@ Returns all combinations of values between two arrays.

    Here are some examples of using product. Paste the following code at the bottom of main.rb and save the file to see the results:

    -
    repl do
       a = [0, 1]
       puts a.product
       # => [[0, 0], [0, 1], [1, 0], [1, 1]]
     end
     
    -
    repl do
       a = [ 0,  1]
       b = [:a, :b]
    @@ -1167,12 +1061,10 @@ end
       # => [[0, :a], [0, :b], [1, :a], [1, :b]]
     end
     
    -

    Array#map_2d

    Assuming the array is an array of arrays, Given a block, each 2D array index invoked against the block. A 2D array is a common way to store data/layout for a stage.

    -
    repl do
       stage = [
         [:enemy, :empty, :player],
    @@ -1195,12 +1087,10 @@ Assuming the array is an array of arrays, Given a block, each 2D array index inv
       puts occupied_tiles
     end
     
    -

    Array#include_any?

    Given a collection of items, the function will return true if any of self's items exists in the collection of items passed in:

    -

    Array#any_intersect_rect?

    Assuming the array contains objects that respond to left, right, top, bottom, this method returns true if any of the elements within the array intersect the object being passed in. You are given an optional parameter called tolerance which informs how close to the other rectangles the elements need to be for it to be considered intersecting. @@ -1208,7 +1098,6 @@ Assuming the array contains objects that respond to left, rig

    The default tolerance is set to 0.1, which means that the primitives are not considered intersecting unless they are overlapping by more than 0.1.

    -
    repl do
       # Here is a player class that has position and implement
       # the ~attr_rect~ contract.
    @@ -1264,17 +1153,14 @@ The default tolerance is set to 0.1, which means that the primitive
       puts ""
     end
     
    -

    GTK::Outputs

    Outputs is how you render primitives to the screen. The minimal setup for rendering something to the screen is via a tick method defined in mygame/app/main.rb

    -
    def tick args
       # code goes here
     end
     
    -

    GTK::Outputs#borders

    Add primitives to this collection to render an unfilled solid to the screen. Take a look at the documentation for Outputs#solids. @@ -1285,7 +1171,6 @@ The only difference between the two primitives is where they are added.

    Instead of using args.outputs.solids:

    -
    def tick args
       #                         X    Y  WIDTH  HEIGHT
       args.outputs.solids << [100, 100,   160,     90]
    @@ -1294,29 +1179,24 @@ end
     

    You have to use args.outputs.borders:

    -
    def tick args
       #                           X    Y  WIDTH  HEIGHT
       args.outputs.borders << [100, 100,   160,     90]
     end
     
    -

    GTK::Outputs#solids

    Add primitives to this collection to render a solid to the screen.

    -

    Rendering a solid using an Array

    Creates a solid black rectangle located at 100, 100. 160 pixels wide and 90 pixels tall.

    -
    def tick args
       #                         X    Y  WIDTH  HEIGHT
       args.outputs.solids << [100, 100,   160,     90]
     end
     
    -

    Rendering a solid using an Array with colors and alpha

    The value for the color and alpha is an number between 0 and 255. The alpha property is optional and will be set to 255 if not specified. @@ -1324,18 +1204,15 @@ The value for the color and alpha is an number between 0 and

    Creates a green solid rectangle with an opacity of 50%.

    -
    def tick args
       #                         X    Y  WIDTH  HEIGHT  RED  GREEN  BLUE  ALPHA
       args.outputs.solids << [100, 100,   160,     90,   0,   255,    0,   128]
     end
     
    -

    Rendering a solid using a Hash

    If you want a more readable invocation. You can use the following hash to create a solid. Any parameters that are not specified will be given a default value. The keys of the hash can be provided in any order.

    -
    def tick args
       args.outputs.solids << {
         x:    0,
    @@ -1349,7 +1226,6 @@ If you want a more readable invocation. You can use the following hash to create
       }
     end
     
    -

    Rendering a solid using a Class

    You can also create a class with solid/border properties and render it as a primitive. ALL properties must on the class. *Additionally*, a method called primitive_marker must be defined on the class. @@ -1357,7 +1233,6 @@ You can also create a class with solid/border properties and render it as a prim

    Here is an example:

    -
    # Create type with ALL solid properties AND primitive_marker
     class Solid
       attr_accessor :x, :y, :w, :h, :r, :g, :b, :a
    @@ -1383,12 +1258,10 @@ def tick args
       args.outputs.solids  << Square.new(10, 10, 32)
     end
     
    -

    GTK::Mouse

    The mouse is accessible via args.inputs.mouse:

    -
    def tick args
       # Rendering a label that shows the mouse's x and y position (via args.inputs.mouse).
       args.outputs.labels << [
    @@ -1439,7 +1312,6 @@ The GTK::MousePoint has the following properties.
     

    GTK::OpenEntity is accessible within the DragonRuby's top level tick function via the args.state property.

    -
    def tick args
       args.state.x ||= 100
       args.outputs.labels << [10, 710, "value of x is: #{args.state.x}."]
    @@ -1451,7 +1323,6 @@ The primary benefit of using args.state as opposed to instance vari
     

    For example:

    -
    def tick args
       # intermediate player object does not need to be created
       args.state.player.x ||= 100
    @@ -1463,7 +1334,6 @@ For example:
       ]
     end
     
    -

    GTK::OpenEntity#as_hash

    Returns a reference to the GTK::OpenEntity as a Hash. This property is useful when you want to treat args.state as a Hash and invoke methods such as Hash#each. @@ -1471,7 +1341,6 @@ Returns a reference to the GTK::OpenEntity as a Hash.

    Example:

    -
    def tick args
       args.state.x ||= 100
       args.state.y ||= 100
    @@ -1488,7 +1357,6 @@ Example:
       end
     end
     
    -

    Numeric#frame_index

    This function is helpful for determining the index of frame-by-frame sprite animation. The numeric value self represents the moment the animation started. @@ -1507,7 +1375,6 @@ This function is helpful for determining the index of frame-by-frame sprite an

    Example using variables:

    -
    def tick args
       start_looping_at = 0
       number_of_sprites = 6
    @@ -1533,7 +1400,6 @@ end
     

    Example using named parameters:

    -
    def tick args
       start_looping_at = 0
     
    @@ -1554,17 +1420,14 @@ Example using named parameters:
       ]
     end
     
    -

    Kernel

    Kernel in the DragonRuby Runtime has patches for how standard out is handled and also contains a unit of time in games called a tick.

    -

    Kernel::tick_count

    Returns the current tick of the game. This value is reset if you call $gtk.reset.

    -

    Kernel::global_tick_count

    Returns the current tick of the application from the point it was started. This value is never reset. -- cgit v1.2.3