Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Showcase / Tron 3000
- By jose Date 2009-05-01 10:58
I've developed a game using this great library. Thanks Julian for developing Ruby Gosu.

Its name is Tron 3000, and it's available at for Windows, Mac & Linux.

This is a deathmatch-style remake of classic Tron game, for multiple players on the same computer, or for playing against artificial intelligence players. Controls are so simple. There are lots of items to pick up, which make the game very addictive:
  - Green bubbles provide weapons, which can be used using the "fire" button. There are missiles available, and so on.
  - Red bubbles provide temporal skills, such as high speed.
  - Blue bubbles have immediate effects, such as cleaning the screen.
Everytime an opponent is killed, you get one point, but if you kill yourself, you'll lose one point! The player with more points wins.

As the game starts, a demo game is played background. You can change video resolution and go fullscreen in the "options" menu. In order to play, you have to create some players in the "players" menu, either human or AI players. Then you're ready to start a new game!

For the geeks, the game allows creating new weapons or AI profiles by including new extensions under the 'extensions' folder, such as:
- tron3000
  - extensions
    - new_extension           (name for the extension)
      - art
        - audio
          * new_item.wav      (sound played when picking the item -- optional)
        - graphics
          * new_item.png      (icon for the item -- optional)
      - code
        - items
          * new_item.rb       (code for the item)

Items are quite easy to code. The following example defines a skill which removes the trail that is left after a player (by redefining the "trail" method that Motorbike class uses):

Skill do
  def trail; end

The next example creates an action which clears all the screen. Like in the previous one, code is executed under the Motorbike class:

Action do
  def pick_action

Check more items under tron3000/code/items. If you also want to add a new AI profile to your extension, just create it like tron3000/extensions/new_extensions/code/bots/my_new_killer_bot.rb and you'll be able to select it when creating new players during the game. Check the existing AI profile at tron3000/code/bots/machine.rb. After you have created an extension, you can activate it in the "extensions" menu of the game.

A frequently asked question about Gosu is how to draw on textures, so you can check my implementation at tron3000/code/core/arena.rb, although it is pure OpenGL for some reasons. Game performance is just OK, so I hope Ruby 1.9 improves it, though I've not tried it yet. So Gosu for Ruby 1.9 would be very appreciated :) Also, the Linux version doesn't work on my Ubuntu since the day I added sound support... maybe there's a problem with SDL library.

I hope you like the game.

Enjoy it!!
- By philomory Date 2009-05-01 14:22
This looks really awesome. Extendable AI? Very, very cool.
- By philomory Date 2009-05-01 15:02
Incidentally, for what it's worth, using Ruby 1.9 approximately doubles my frame rate.
- By jose Date 2009-05-01 15:18
Thanks, philomory! Regarding Ruby 1.9, I've been forced to reduce computations in the AI to optimize speed. Ruby 1.9 would allow building more complex behaviour and cleverer enemies :)
- By jlnr (dev) Date 2009-05-03 09:32
Amazing stuff! Very very polished. Will need to look at the source code in places :)

And I just downloaded Ruby 1.9.1 to give my "universal" RubyGem another try.
- By jlnr (dev) Date 2009-05-05 01:48
You should be able to test your game with Ruby 1.9 using the files from this posting ( for Windows, .app wrapper for OS X):

I wanted to test it on Windows with your game, but I couldn't get the ruby-opengl gem installed :(

(Still looking forward to testing the computer enemies, with only two human players it's too easy to just keep firing :) )
- By jose Date 2009-05-06 08:22
Thanks Julian!! I'll try the Ruby 1.9 version as soon as I can. Anyway, right now you should already be able to play against computer players. In the game, just go to the "players" menu, pick a player to edit it, and switch from "human" to "machine". You can play against 3 computer players. Ruby 1.9 will just allow to develop more complex enemies, with more calculations (I hope).

Also, regarding the code, for your interest there are two files that could be used in other games quite easily:
  - code/core/attributes.rb: an extension of whytheluckystiff's Dwemthy's array. It allows to declare classes with attributes quite cleanly.
  - code/core/behaviours.rb: allows to dynamically include and deinclude modules in an object (not just a class), which is quite useful in games in which players can pick up items which change their skills.

Allows easily defining attributes through an initial constant or a block of code that is run to initialize the object. When defining an attribute x, the following methods are added:
- accessor methods x and x=
- initial_x, which returns the value of x when the object was created
- default_x, which returns the value of x that is set by default to objects of its class

Some examples:

class Enemy
  include Attributes   # just include this line to enable the module on any class

  health  100          # define some attributes for our enemy. health, health=, initial_health and default_health, attack, atack=, ... are defined
  attack  10
  defense 10

enemy =          # => 100 -= 5     # => 95          # => 95
enemy.initial_health  # => 100

wounded_enemy = :health=>70    # Initial attributes can be set at creation time
wounded_enemy.default_health  # => 100   # but the defaults don't change
wounded_enemy.initial_health  # => 70    # Only the initial value changes -= 5     # => 65

Attributes' default values can be changed in subclasses:
class Monster < Enemy
  attack    15
  defense { rand(20) }  # in this case, a block of code is passed, which will go to "default_defense" method

monster =
monster.default_defense   # => 5
monster.default_defense   # => 13  (the default defense is random!)
monster.initial_defense   # => 14
monster.initial_defense   # => 14   (but the initial defense was set when the monster was born)
monster.defense           # => 14
monster.defense -= 5      # => 9

Also, including Attributes also allows to include any module in the class by just typing its name, without the "include" word (e.g, just "mod" instead of "include Mod").

All this together, here's an example of a homing missile in Tron 3000, available at code/items/missile_pack.rb:

class HomingMissile < Entity
  homing      # Same as "include Homing; include Explosive; include Projectile"
  projectile  # This is quite a natural definition: a homing missile is just a homing explosive projectile

  image   :missile
  sound   :missile
  factor  0.75
  flare { :follow=>self, :factor=>0.5 }

  def update
    @speed += 1 if @speed < 30   # Adds some acceleration to the projectile. Note that "speed" attribute was defined in "projectile"

Allows to dynamically include and deinclude modules in objects (not just classes). This is nice in games in which players can pick up items that add skills or change their behaviour.

To enable it, just include the Behaviours module in the class whose objects require dynamic changes:

class Enemy
  include Behaviours
  include Attributes

  health 100
  attack 10
  defense 10

module Strength
  def attack
    super * 2

enemy =
enemy.attack   # => 10

# Now pick an item that improves attack
enemy.extend(Strength) # => #<Module:0x12d552c>
enemy.attack   # => 20

# Drop the item and go back to normal state
enemy.unextend(Strength)  # => ["attack"]
enemy.attack   # => 10

It's great that Ruby allows these things :)

I hope this is useful stuff, cheers!
Up Topic Gosu / Gosu Showcase / Tron 3000

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill