SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Game
Development
With Perl and SDL



       - press start -
Perl
SDL
Perl
SDL
Perl
SDL
Simple DirectMedia Layer
low level access
Video
Audio
Input Devices
cross-platform
Multimedia App


                    libSDL


DirectX   GDI    framebuffer Xlib   Quartz

                                             ...
MS Windows            Linux         OS X
LGPL v2
Round 1   . . .




 F IGH T          !
1:1 API
use   strict;
use   warnings;
use   SDL;
use   SDL::Video;
use   SDL::Surface;
use   SDL::Rect;

SDL::init(SDL_INIT_VIDEO);
my ($screen_w, $screen_h) = (800, 600);
my $screen = SDL::Video::set_video_mode(
                $screen_w,
                $screen_h,
                32,
                SDL_ANYFORMAT
);

my $blue = SDL::Video::map_RGB($screen->format(), 0, 0, 255);
SDL::Video::fill_rect(
              $screen,
              SDL::Rect->new(15, 15, 100, 100),
              $blue
);
SDL::Video::update_rect($screen, 0, 0, $screen_w, $screen_h);

sleep 5; # so we have time to see!
Too low level
Not Perlish at all!
SDLx::* Sugar
use strict;
use warnings;

use SDLx::App;

my $app = SDLx::App->new(
        width => 800,
        height => 600,
);

$app->draw_rect(
        [15, 15, 100, 100], # rect
        [0,0,255,255],      # blue
);

$app->update;

sleep 5; # so we have time to see!
The Game Loop
while ( $running ) {
    get_events();
    update_game();
    render_scene();
}
while( $running ) {
    $loops = 0;
    while(
           get_tick_count() > $next_game_tick
           && $loops < $MAX_FRAMESKIP
    ) {
        get_events();
        update_game();

        $next_game_tick += $SKIP_TICKS;
        $loops++;
    }
    $interpolation = (     get_tick_count()
                         + $SKIP_TICKS - $next_game_tick
                     )
                     / $SKIP_TICKS;

    render_scene( $interpolation );
}
SDLx::App->run;
use SDLx::App;

my $app = SDLx::App->new;

$app->add_move_handler( &update );

$app->add_event_handler( &player_1 );
$app->add_event_handler( &player_2 );

$app->add_show_handler( &scene );

$app->run;
Avenger
Avenger
sugary syntax
use Avenger title => 'My Game';

update { ... };

show { ... };

event 'key_down' => sub { ... };

event 'mouse_left' => sub { ... };

start;
Box2D
integration
use Avenger title => 'My Game';
world->gravity( 0, -100 );

my $player = world->create_dynamic( x => 30, y => 100 );
my $floor = world->create_static(
                y => 50,
                w => app->w -100 ,
                h => 10,
);

update { world->update };

show {
    app->clear( [0, 0, 0, 255] );
    app->draw_rect( $floor->rect, [0, 255, 0, 255] );
    app->draw_rect( $player->rect, [255, 50, 0, 255] );
    app->update;
};

start;
Simple games, easy.
Complex games, possible!
use Avenger;
use MyGame;

start 'MainScreen';
package MyGame::MainScreen;
use Avenger;

load { ... };

unload { ... };

update { ... };

event { ... };

show { ... };

1;
Other SDLx Goodies
my $menu = SDLx::Widget::Menu->new;

$menu->items(
    'New Game'    =>   sub   {   ...   },
    'Load Game'   =>   sub   {   ...   },
    'Options'     =>   sub   {   ...   },
    'Quit'        =>   sub   {   ...   },
);

show { $menu->render( app ) };
my $text = SDLx::Text->new(
    font    => '/path/to/my/font.ttf',
    color   => 'white',
    h_align => 'center',
    shadow => 1,
    bold    => 1,
);

$text->write_to(
   app,
   'All your base are belong to us.'
);
my $music = SDLx::Music->new;

$music->data(
   intro => {
      loops   => 3,
      fade_in => 0.5,
      volume => 72,
   },
   gameover => {
      finished => sub { print 'Done!' },
   },
);

$music->play( 'intro' );
my $sprite = SDLx::Sprite::Animated->new;

$sprite->load( 'hero.png' )->start;

show { $sprite->draw( app ) };
HUGE TODO LIST!
github.com/PerlGameDev


    #sdl   (irc.perl.org)


sdl-devel-subscribe@perl.org


           @SDLPerl
Thank You
For Playing !

  garu@cpan.org
     @garu_rj

Weitere ähnliche Inhalte

Was ist angesagt?

Start to Finish: Porting to BlackBerry 10
Start to Finish: Porting to BlackBerry 10Start to Finish: Porting to BlackBerry 10
Start to Finish: Porting to BlackBerry 10
ardiri
 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
Duy Tan Geek
 

Was ist angesagt? (13)

The Ring programming language version 1.10 book - Part 132 of 212
The Ring programming language version 1.10 book - Part 132 of 212The Ring programming language version 1.10 book - Part 132 of 212
The Ring programming language version 1.10 book - Part 132 of 212
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
The Ring programming language version 1.5.4 book - Part 87 of 185
The Ring programming language version 1.5.4 book - Part 87 of 185The Ring programming language version 1.5.4 book - Part 87 of 185
The Ring programming language version 1.5.4 book - Part 87 of 185
 
67WS Seminar Event
67WS Seminar Event67WS Seminar Event
67WS Seminar Event
 
The Ring programming language version 1.9 book - Part 130 of 210
The Ring programming language version 1.9 book - Part 130 of 210The Ring programming language version 1.9 book - Part 130 of 210
The Ring programming language version 1.9 book - Part 130 of 210
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Start to Finish: Porting to BlackBerry 10
Start to Finish: Porting to BlackBerry 10Start to Finish: Porting to BlackBerry 10
Start to Finish: Porting to BlackBerry 10
 
Getting Real With Connected Devices Presentation
Getting Real With Connected Devices PresentationGetting Real With Connected Devices Presentation
Getting Real With Connected Devices Presentation
 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 
Maker Movement
Maker MovementMaker Movement
Maker Movement
 
Flappy bird
Flappy birdFlappy bird
Flappy bird
 

Andere mochten auch (16)

Perl Moderno, dia1
Perl Moderno, dia1Perl Moderno, dia1
Perl Moderno, dia1
 
C language in our world 2015
C language in our world 2015C language in our world 2015
C language in our world 2015
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)
 
White tigress 05
White tigress 05White tigress 05
White tigress 05
 
Chninkel 03
Chninkel  03Chninkel  03
Chninkel 03
 
Explorers of the Moon
Explorers of the MoonExplorers of the Moon
Explorers of the Moon
 
Chninkel 01
Chninkel  01Chninkel  01
Chninkel 01
 
03 the hypnotist
03 the hypnotist03 the hypnotist
03 the hypnotist
 
02 The W Group
02 The W Group02 The W Group
02 The W Group
 
Red Rachkam's Treasure
Red Rachkam's TreasureRed Rachkam's Treasure
Red Rachkam's Treasure
 
White tigress 03
White tigress 03White tigress 03
White tigress 03
 
White tigress 04
White tigress 04White tigress 04
White tigress 04
 
White tigress 02
White tigress 02White tigress 02
White tigress 02
 
White tigress 01
White tigress 01White tigress 01
White tigress 01
 
Lianza 2 Comics For Libraries
Lianza 2 Comics For LibrariesLianza 2 Comics For Libraries
Lianza 2 Comics For Libraries
 

Ähnlich wie Game Development with SDL and Perl

building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
Masahiro Nagano
 
R57shell
R57shellR57shell
R57shell
ady36
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
De CRUD Ă  DDD pas Ă  pas
De CRUD Ă  DDD pas Ă  pasDe CRUD Ă  DDD pas Ă  pas
De CRUD Ă  DDD pas Ă  pas
Charles Desneuf
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15
종인 전
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
Taras Kalapun
 

Ähnlich wie Game Development with SDL and Perl (20)

C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
distill
distilldistill
distill
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
 
R57shell
R57shellR57shell
R57shell
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
De CRUD Ă  DDD pas Ă  pas
De CRUD Ă  DDD pas Ă  pasDe CRUD Ă  DDD pas Ă  pas
De CRUD Ă  DDD pas Ă  pas
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Samrt attendance system using fingerprint
Samrt attendance system using fingerprintSamrt attendance system using fingerprint
Samrt attendance system using fingerprint
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15
 
Server side data sync for mobile apps with silex
Server side data sync for mobile apps with silexServer side data sync for mobile apps with silex
Server side data sync for mobile apps with silex
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
logic321
logic321logic321
logic321
 

Mehr von garux

Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao MooseOrientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
garux
 

Mehr von garux (14)

Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
 
Seja um Perl Core Hacker - ĂŠ (muito) mais fĂĄcil do que vocĂŞ pensa
Seja um Perl Core Hacker - ĂŠ (muito) mais fĂĄcil do que vocĂŞ pensaSeja um Perl Core Hacker - ĂŠ (muito) mais fĂĄcil do que vocĂŞ pensa
Seja um Perl Core Hacker - ĂŠ (muito) mais fĂĄcil do que vocĂŞ pensa
 
Perl Moderno, dia5
Perl Moderno, dia5Perl Moderno, dia5
Perl Moderno, dia5
 
Perl Moderno, dia4
Perl Moderno, dia4Perl Moderno, dia4
Perl Moderno, dia4
 
Perl Moderno, dia3
Perl Moderno, dia3Perl Moderno, dia3
Perl Moderno, dia3
 
Perl Moderno, dia2
Perl Moderno, dia2Perl Moderno, dia2
Perl Moderno, dia2
 
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao MooseOrientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
 
Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)
 
Jogos em Perl
Jogos em PerlJogos em Perl
Jogos em Perl
 
Logging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perlLogging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perl
 
Novidades no Perl 5.10
Novidades no Perl 5.10Novidades no Perl 5.10
Novidades no Perl 5.10
 
Desenvolvimento RĂĄpido de Programas Linha de Comando
Desenvolvimento RĂĄpido de Programas Linha de ComandoDesenvolvimento RĂĄpido de Programas Linha de Comando
Desenvolvimento RĂĄpido de Programas Linha de Comando
 

KĂźrzlich hochgeladen

Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
call girls kolkata
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
Monica Sydney
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
call girls kolkata
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
DipikaDelhi
 

KĂźrzlich hochgeladen (20)

Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girls
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyHire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
 
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
 
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
 
Tapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all UsersTapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all Users
 
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call GirlsGenuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
 
Kailashahar Call Girl Whatsapp Number 📞 8617370543 | Girls Number for Friend...
Kailashahar  Call Girl Whatsapp Number 📞 8617370543 | Girls Number for Friend...Kailashahar  Call Girl Whatsapp Number 📞 8617370543 | Girls Number for Friend...
Kailashahar Call Girl Whatsapp Number 📞 8617370543 | Girls Number for Friend...
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
 
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
 
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls AgencyHire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
 
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book nowUnnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
 
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
 
Escorts Service Model mount abu 👉 Just CALL ME: 8617370543 💋 Call Out Call Bo...
Escorts Service Model mount abu 👉 Just CALL ME: 8617370543 💋 Call Out Call Bo...Escorts Service Model mount abu 👉 Just CALL ME: 8617370543 💋 Call Out Call Bo...
Escorts Service Model mount abu 👉 Just CALL ME: 8617370543 💋 Call Out Call Bo...
 
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyHire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
 

Game Development with SDL and Perl

  • 1. Game Development With Perl and SDL - press start -
  • 11. Multimedia App libSDL DirectX GDI framebuffer Xlib Quartz ... MS Windows Linux OS X
  • 13. Round 1 . . . F IGH T !
  • 15. use strict; use warnings; use SDL; use SDL::Video; use SDL::Surface; use SDL::Rect; SDL::init(SDL_INIT_VIDEO); my ($screen_w, $screen_h) = (800, 600); my $screen = SDL::Video::set_video_mode( $screen_w, $screen_h, 32, SDL_ANYFORMAT ); my $blue = SDL::Video::map_RGB($screen->format(), 0, 0, 255); SDL::Video::fill_rect( $screen, SDL::Rect->new(15, 15, 100, 100), $blue ); SDL::Video::update_rect($screen, 0, 0, $screen_w, $screen_h); sleep 5; # so we have time to see!
  • 19. use strict; use warnings; use SDLx::App; my $app = SDLx::App->new( width => 800, height => 600, ); $app->draw_rect( [15, 15, 100, 100], # rect [0,0,255,255], # blue ); $app->update; sleep 5; # so we have time to see!
  • 21. while ( $running ) { get_events(); update_game(); render_scene(); }
  • 22. while( $running ) { $loops = 0; while( get_tick_count() > $next_game_tick && $loops < $MAX_FRAMESKIP ) { get_events(); update_game(); $next_game_tick += $SKIP_TICKS; $loops++; } $interpolation = ( get_tick_count() + $SKIP_TICKS - $next_game_tick ) / $SKIP_TICKS; render_scene( $interpolation ); }
  • 23.
  • 25. use SDLx::App; my $app = SDLx::App->new; $app->add_move_handler( &update ); $app->add_event_handler( &player_1 ); $app->add_event_handler( &player_2 ); $app->add_show_handler( &scene ); $app->run;
  • 29. use Avenger title => 'My Game'; update { ... }; show { ... }; event 'key_down' => sub { ... }; event 'mouse_left' => sub { ... }; start;
  • 31. use Avenger title => 'My Game'; world->gravity( 0, -100 ); my $player = world->create_dynamic( x => 30, y => 100 ); my $floor = world->create_static( y => 50, w => app->w -100 , h => 10, ); update { world->update }; show { app->clear( [0, 0, 0, 255] ); app->draw_rect( $floor->rect, [0, 255, 0, 255] ); app->draw_rect( $player->rect, [255, 50, 0, 255] ); app->update; }; start;
  • 32. Simple games, easy. Complex games, possible!
  • 34. package MyGame::MainScreen; use Avenger; load { ... }; unload { ... }; update { ... }; event { ... }; show { ... }; 1;
  • 36. my $menu = SDLx::Widget::Menu->new; $menu->items( 'New Game' => sub { ... }, 'Load Game' => sub { ... }, 'Options' => sub { ... }, 'Quit' => sub { ... }, ); show { $menu->render( app ) };
  • 37. my $text = SDLx::Text->new( font => '/path/to/my/font.ttf', color => 'white', h_align => 'center', shadow => 1, bold => 1, ); $text->write_to( app, 'All your base are belong to us.' );
  • 38. my $music = SDLx::Music->new; $music->data( intro => { loops => 3, fade_in => 0.5, volume => 72, }, gameover => { finished => sub { print 'Done!' }, }, ); $music->play( 'intro' );
  • 39. my $sprite = SDLx::Sprite::Animated->new; $sprite->load( 'hero.png' )->start; show { $sprite->draw( app ) };
  • 41. github.com/PerlGameDev #sdl (irc.perl.org) sdl-devel-subscribe@perl.org @SDLPerl
  • 42. Thank You For Playing ! garu@cpan.org @garu_rj