Steroids

A proof from the 80s

Tadeusz Sośnierz (tadzik) @ PLPW 2014

"When I grow up, I want to make games!"

Never wrote any

lessmilk.com and a "New game every week"

I can do that!

I can write an engine too

Already working things? Meh

What is steroids?

  • A game development framework
  • Modelled after phaser.js (sort of)
  • SDL2 under the hood

Disclamer: I'm not a game developer

  • I learn on my own mistakes
  • There are probably many design mistakes in Steroids
  • I keep breaking it every now and then, so not quite stable

If you're feeling adventurous...

Glory is for early adopters

What's with this the Perl 6 thing again?

Real life performance test

  • No graphs, but "can it handle 60fps"?
  • Turns out that it can
  • It's the algorithms that are slowing it down, not Rakudo

To ship Perl (6) products

We're good at libraries, but not at products

The goal:

Have a game framework that abstracts the tricky stuff and allows you to ship products

Games so far

The good parts


States

class Main is Steroids::State {
    method create { ... }
    method update($dt) { ... }
    method keypressed { ... }
    method gamepad    { ... }
}

class Menu is Steroids::State { ... }

given Steroids::Game.new {
    .add_state('menu', { Menu.new });
    .add_state('main', { Main.new });
    .change_state('menu');
    .start;
}
                    
  • High-level, declarative code
  • No game loop!
  • "Goal: have a game framework that abstracts the tricky stuff (...)"

Basic sprites

method create {
    self.load_bitmap('background', 'assets/background.png');
    self.load_bitmap('runner', 'assets/runner.png');

    self.add_sprite('background', 0, 0);
    $!runner = self.add_sprite('runner', 50, GROUNDLEVEL);
}
                    

Basic physics

my $bullet = self.add_sprite('laser', $x, $y);
$bullet.velocity = [0, -15];
$bullet.when({ .collides_with(any(@!invaders)) }, {
    # boom!
}
$bullet.when({ .y + .h < 0 }, {
    self.remove_sprite($bullet);
});

                    

Disclamer: collision detection (currently) sucks

box2d binding planned

Spritesheets and animations

$!player = self.load_spritesheet('player', 'assets/player.png', 48, 56, 12);
...
if ($!player.velocity[0] < 0) {
    self.remove_animation($!anim) if $!anim;
    $!anim = self.add_animation($!player, 0..2, 200, True);
}

                    

Text rendering

self.load_font('default', 'assets/font.ttf', 48);
my $t = self.add_text('(S)tart a new game', 'default',
                      Steroids::Colour.white, $x, $y));
                    

But what about drawing stuff?

  • draw() method is optional
  • Steroids gives you one for free that works Well Enough™
  • You usually won't need it, I never did
  • Disclamer: it sucks :( (it redraws everything on every frame)

Input processing

method keypressed($k) {
    if $k eq 'S' {
        self.reset_state('main');
        self.change_state('main');
    } elsif $k == 81 {
        self.quit;
    }
}
                    

Input processing

method gamepad($e) {
    return unless $e.type eq 'button_down';
    if $e.button eq 'START' {
        self.reset_state('main');
        self.change_state('main');
    } elsif $e.button eq 'BACK' {
        self.quit;
    }
}
                    

Input processing

method update($dt) {
    my $analog = $pad.analog_percentage(self.gamepads[0].analog_left_x);
    if self.is_pressed("Left") or $pad.dpad_position("Left") {
        $!player.x -= 15;
    } elsif self.is_pressed("Right") or $pad.dpad_position("Right") {
        $!player.x += 15;
    } elsif $analog.abs > 0.1 {
        $!player.x += Int(15 * $analog);
    }
}
                    

Live demo!

The bad parts


Goal: have a game framework that (...) allows you to ship products


Setup the enviromenment for Steroids with this one simple command!

git clone git://github.com/tadzik/rakudobrew.git ~/.rakudobrew
    && export PATH=$HOME/.rakudobrew/bin:$PATH && rakudobrew build moar
    && rakudobrew build-panda && panda install NativeCall
                    

I wish I was kidding

What if SDL2 is not installed?

Deployment sucks

  • You can't really bundle rakudo with your Perl 6 code
  • This _could_ work with Rakudo/JVM and .jars
  • Some work being done by FROGGS++ to be able to bundle (byte)code with a MoarVM binary

Error handling? What is that

prints and segfaults are all you ever need

(kidding, but that's the way it is now)

Memory management?

GC will take care of it right? (hint: no, it won't)

Not production ready, no matter how liberal you are

So why would you want to use it?

  • You can already create fun stuff easily
  • It's fun to be an early adopter
  • It's easy to contribute when things are incomplete
  • (And achieve fame and glory)

Learn moar

  • http://ttjjss.wordpress.com/tag/steroids/
  • https://github.com/tadzik/steroids
  • Come to the hackathon after lunch! (I'll be there)

Questions?

Criticism?

Tomatoes?

Thank you!