Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- ####################################################
- # Images File to download
- # http://i.imgur.com/pKC0it6.jpg - bg.jpg
- # http://i.imgur.com/QBDWhIl.png - standing.png
- # http://i.imgur.com/rku5CFE.png - skill1.png
- # http://i.imgur.com/AzuQc5a.png - running.png
- # http://i.imgur.com/wHnWfln.png - back.png
- ####################################################
- use strict;
- use warnings;
- use Carp;
- use SDL;
- use SDLx::App;
- use SDL::Event;
- use SDL::Events;
- use SDL::Image;
- use SDL::Audio;
- use SDL::Mixer;
- use SDLx::Sprite;
- use SDLx::Sprite::Animated;
- use SDL::Mixer::Samples;
- use SDL::Mixer::Channels;
- use SDL::Mixer::Music;
- SDL::init(SDL_INIT_AUDIO);
- my $app=SDLx::App->new(
- w=>500,
- h=>500,
- title=>'Sonic',
- dt=>0.02,
- );
- my $map_pos=0;
- my $background=SDL::Image::load('rect.jpg');
- my $background_rect; = SDL::Rect->new(0,0,
- $background->w,
- $background->h,
- );
- my $quit=0;
- my $sprite = SDLx::Sprite::Animated->new(
- image => "standing.png",
- step_x => 56.33333333333333,
- step_y => 1,
- rect => SDL::Rect->new(40,410,56.33333333333333,55),
- ticks_per_frame => 10,
- type => "circular",
- );
- my $skill1=SDLx::Sprite::Animated->new(
- image => "skill1.png",
- step_x => 56.23529411764706,
- step_y => 1,
- rect => SDL::Rect->new(40,410,56.23529411764706,70),
- ticks_per_frame => 6,
- type => "circular",
- );
- my $running = SDLx::Sprite::Animated->new(
- image => "running.png",
- step_x => 54.81818181818182,
- step_y => 1,
- rect => SDL::Rect->new(40,410,54.81818181818182,57),
- ticks_per_frame => 10,
- type => "circular",
- );
- my $back = SDLx::Sprite::Animated->new(
- image => "back.png",
- step_x => 54.81818181818182,
- step_y => 1,
- rect => SDL::Rect->new(40,410,54.81818181818182,57),
- ticks_per_frame => 10,
- type => "circular",
- );
- my $bg=SDLx::Sprite::Animated->new(
- image => "bg.jpg",
- step_x => 500,
- step_y => 1,
- rect => SDL::Rect->new(0,0,500,500),
- ticks_per_frame => 6,
- type => "circular",
- );
- SDL::Events::enable_key_repeat( 1, 5 );
- $skill1->step_y(0);
- $running->step_y(0);
- $bg->step_y(0);
- $sprite->step_y(0);
- $sprite->start;
- $back->clip->w(0);$back->clip->h(0);
- $running->clip->w(0);$running->clip->h(0);
- $skill1->clip->w(0);$skill1->clip->h(0);
- $back->type('reverse');
- my $mov_x=10;
- #############
- my $skill=0;
- my $duration=0;
- #############
- sub get_events{
- my $event=SDL::Event->new();
- #$event->set_key_repeat(10,10);
- SDL::Events::pump_events();
- while(SDL::Events::poll_event($event)){
- $quit=1 if $event->type==SDL_QUIT;
- if($event->type==SDL_KEYDOWN){
- if($event->key_sym==SDLK_d){
- &walking;
- }
- if($event->key_sym==SDLK_a){
- &backWalk;
- }
- if($event->key_sym==SDLK_j){
- $skill=1
- }
- }
- if($event->type==SDL_KEYUP){
- &idle;
- }
- }
- }
- sub check{
- if($skill==1){
- $duration++;
- if($duration!=100){
- $skill1->clip->w(56.23529411764706);$skill1->clip->h(70);
- $running->clip->w(0);$running->clip->h(0);
- $sprite->clip->w(0);$sprite->clip->h(0);
- $skill1->start;
- }
- if($duration==100){
- $skill1->clip->w(0);$skill1->clip->h(0);
- $skill=0;$duration=0;
- $skill1->reset;
- &idle;
- }
- }
- sub walking{
- $running->start;
- if($mov_x<=222){
- $mov_x++;
- }
- if($mov_x>=222 and $map_pos!=302){
- $map_pos+=2;
- }
- if($map_pos==302){
- $mov_x++;
- }
- #print "$mov_x\n";
- print "$map_pos\n";
- $bg->clip->x($map_pos);
- $running->clip->w(54.81818181818182);$running->clip->h(57);
- $sprite->clip->w(0);$sprite->clip->h(0);
- }
- sub backWalk{
- $back->start;
- if($mov_x<=222){
- $mov_x--;
- }
- if($mov_x>=222 and $map_pos==-2){
- $map_pos-=2;
- }
- if($map_pos==302){
- $mov_x--;
- }
- #print "$mov_x\n";
- print "$map_pos\n";
- $bg->clip->x($map_pos);
- $back->clip->w(54.81818181818182);$back->clip->h(57);
- $sprite->clip->w(0);$sprite->clip->h(0);
- $running->clip->w(0);$running->clip->h(0);
- }
- sub idle{
- $sprite->clip->w(56.33333333333333);$sprite->clip->h(55);
- $running->clip->w(0);$running->clip->h(0);
- #$fight->clip->w(0);$fight->clip->h(0);
- }
- }
- sub render{
- SDL::Video::blit_surface($background, $background_rect, $app, $background_rect );
- $bg->draw($app);
- $sprite->draw($app);
- $running->draw($app);
- $skill1->draw($app);
- $back->draw($app);
- $running->rect(SDL::Rect->new($mov_x,410,192,162));
- $skill1->rect(SDL::Rect->new($mov_x,410,192,162));
- $sprite->rect(SDL::Rect->new($mov_x,410,192,162));
- $back->rect(SDL::Rect->new($mov_x,410,192,162));
- SDL::Video::update_rects($app, $background);
- $app->delay(2);
- $app->update();
- }
- while(!$quit){
- get_events();
- check();
- render();
- }
Advertisement
Add Comment
Please, Sign In to add comment