Skip to content

Instantly share code, notes, and snippets.

@KohaAloha
Created April 18, 2014 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KohaAloha/11051483 to your computer and use it in GitHub Desktop.
Save KohaAloha/11051483 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
use lib 'blib/arch';
use lib 'lib';
use Collision::2D ':all';
use SDL;
use SDL::Video;
use SDL::Surface;
use SDL::Event;
use SDL::Events;
use SDL::Rect;
use SDL::Color;
use SDL::GFX::Primitives;
use Carp;
=comment
use SDL::Time;
use Data::Dumper;
=cut
croak 'Cannot init video ' . SDL::get_error()
if ( SDL::init(SDL_INIT_VIDEO) == -1 );
my $app = SDL::Video::set_video_mode( 800, 500, 32, SDL_SWSURFACE );
croak 'Cannot init video mode 800x500x32: ' . SDL::get_error() if !($app);
my $event = SDL::Event->new();
my $cont = 1;
my $crate = {
x => 100,
y => 100,
w => 100,
h => 100
};
my $w = $crate->{w};
my $h = $crate->{h};
my $csurf = SDL::Surface->new( SDL_SWSURFACE, $w, $h, 32, 0, 0, 0, 255 );
SDL::Video::fill_rect(
$csurf,
SDL::Rect->new( 0, 0, $w, $h ),
# SDL::Video::map_RGB( $app->format, 255 ,0 , 0 )
SDL::Video::map_RGB( $app->format, 255 ,0 , 255 )
# SDL::Video::map_RGB( $app->format, 0 ,0 , 255 )
);
#Our level game loop
while ($cont) {
while ( SDL::Events::poll_event($event) )
{ #Get all events from the event queue in our event
if ( $event->type == SDL_QUIT ) { $cont = 0 }
}
SDL::Video::blit_surface(
$csurf,
SDL::Rect->new( 0, 0, $crate->{w}, $crate->{h} ),
$app,
SDL::Rect->new( $crate->{x}, $crate->{y}, $crate->{w}, $crate->{h},
)
);
SDL::Video::flip($app);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment