Created
August 6, 2011 08:55
-
-
Save djanatyn/1129191 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use SDL; | |
use SDLx::App; | |
use SDL::Event; | |
use SDL::Events; | |
my $app = SDLx::App->new(width => 600, | |
height => 480); | |
my $event = SDL::Event->new(); | |
my $v_x = 0; my $xpos = 5; | |
my $v_y = 0; my $ypos = 5; | |
my $quit = 0; | |
sub press_key { | |
my $_ = SDL::Events::get_key_name( $event->key_sym ); | |
if (/up/) { $v_y = -1; } | |
if (/down/) { $v_y = +1; } | |
if (/left/) { $v_x = -1; } | |
if (/right/) { $v_x = +1; } | |
if (/q/) { $quit = 1; } | |
} | |
sub release_key { | |
my $_ = SDL::Events::get_key_name( $event->key_sym ); | |
if (/up/) { $v_y = 0; } | |
if (/down/) { $v_y = 0; } | |
if (/left/) { $v_x = 0; } | |
if (/right/) { $v_x = 0; } | |
} | |
sub process_events { | |
SDL::Events::pump_events(); | |
while ( SDL::Events::poll_event($event) ) { | |
press_key() if $event->type == SDL_KEYDOWN; | |
release_key() if $event->type == SDL_KEYUP; | |
} | |
} | |
while (!$quit) { | |
process_events; | |
$xpos += $v_x; | |
$ypos += $v_y; | |
$app->draw_rect( [$xpos,$ypos,10,10], [255,255,0,255] ); | |
$app->update(); | |
# wait for a little bit | |
# OH WAIT I DON'T KNOW HOW TO DO THAT YET | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment