Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 146 lines (116 sloc) 3.382 kB
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
1 #!/usr/bin/perl -w
2 use strict;
3
b4b586d @zpmorgan mainly tile stuff
authored
4 #found some tiles at http://www.ironstarmedia.co.uk/2010/10/free-game-assets-13-prototype-mine-tileset/
5 # and some musics at http://www.ironstarmedia.co.uk/resources/free-game-assets/browse/music
6
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
7 use SDL;
8 use SDLx::App;
9 use SDLx::Sprite::Animated;
10 use SDL::Event;
11 use SDL::Events;
12
940c198 @zpmorgan music
authored
13 use SDLx::Sound;
14
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
15 use Viewport;
16 use Level;
17 use Entity;
18 use Carp;
19
20
21 my %pressed;
22 my $quit = 0;
23
24 my $app = SDLx::App->new(
25 title => 'Application Title',
26 width => 640,
27 height => 480,
28 depth => 32
29 );
30
b4b586d @zpmorgan mainly tile stuff
authored
31 my $tiles_surf = SDLx::Surface->load('cave-tiles32.png');
b2e465e @zpmorgan do terrain without using sprites
authored
32 my $rock_surf = SDLx::Surface->new( width => 32, height => 32, color=>0x000000FF);
33 my $air_surf = SDLx::Surface->new( width => 32, height => 32, color=>0x000000FF );
b4b586d @zpmorgan mainly tile stuff
authored
34 my $rock_clip = SDL::Rect->new( 32,32,32,32);
35 my $air_clip = SDL::Rect->new(160,0,32,32);
b2e465e @zpmorgan do terrain without using sprites
authored
36 my $rect32 = SDL::Rect->new(0,0,32,32);
37 $tiles_surf->blit( $rock_surf, $rock_clip, $rect32 );
38 $tiles_surf->blit( $air_surf, $air_clip, $rect32 );
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
39
40 my $tiletypes = {
b2e465e @zpmorgan do terrain without using sprites
authored
41 green => {color => 0x00ff00ff},
42 #rocks => {color => 0x00ff00ff},
43 rock => {surface => $rock_surf},
44 red => {color => 0xff0000ff},
45 air => {surface => $air_surf, solid=>0},
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
46 };
47
48
49 my $level = Level->new(
fb060f3 @zpmorgan now it's not so slow
authored
50 size => 120,
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
51 tilesize => 32,
52 tiletypes => $tiletypes,
fb060f3 @zpmorgan now it's not so slow
authored
53 #~ tiles => \@leveldata,
59cb83a @zpmorgan moving viewport
authored
54 default_tile => 'air',
fb060f3 @zpmorgan now it's not so slow
authored
55 default_space => 'air',
b4b586d @zpmorgan mainly tile stuff
authored
56 default_solid => 'rock',
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
57 );
59cb83a @zpmorgan moving viewport
authored
58
fb060f3 @zpmorgan now it's not so slow
authored
59 #~ $level->generate_terrain;
59cb83a @zpmorgan moving viewport
authored
60
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
61 $level->init_collision_grid;
62
63 my $viewport = $level->basic_viewport (app => $app, level => $level,
fb060f3 @zpmorgan now it's not so slow
authored
64 w=>500, h=>400, surf_x => 32, surf_y=> 32);
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
65
66 my $sprite = SDLx::Sprite::Animated->new(
67 name => 'cryptopod',
68 image => 'cryptopod.png',
69 rect => SDL::Rect->new( 0, 0, 16, 32 ),
70 ticks_per_frame => 4,
71 );
72
73 $sprite->set_sequences(
74 move => [ [ 0, 0 ], [ 1, 0 ] ],
75 );
76
77 $sprite->sequence('move');
78 $sprite->start();
79
80 my $cryptopod = new Entity(
81 x => 3,
82 y => 3,
83 sprite => $sprite,
8ee8cc9 @zpmorgan better jumping dynamics and such
authored
84 w => .5,
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
85 h => 1,
86 );
87 $level->add_entity($cryptopod);
59cb83a @zpmorgan moving viewport
authored
88 $viewport->track($cryptopod);
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
89
af84e81 @zpmorgan converted mod track to ogg
authored
90
940c198 @zpmorgan music
authored
91 my $snd = SDLx::Sound->new();
92 # load and play a sound
af84e81 @zpmorgan converted mod track to ogg
authored
93 my $play = $snd->play('hallucinations.ogg');
94 #Hallucinations track from :
95 # http://modarchive.org/index.php?request=view_by_moduleid&query=58827
96 # Artist unknown :\
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
97
98 $app->add_event_handler(
99 sub {
100 my ($event,$app) = @_;
940c198 @zpmorgan music
authored
101 exit if $event->type == SDL_QUIT || $quit;
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
102
940c198 @zpmorgan music
authored
103 my $key = $event->key_sym;
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
104 my $name = SDL::Events::get_key_name($key) if $key;
105
940c198 @zpmorgan music
authored
106 if ( $event->type == SDL_KEYDOWN ) {
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
107 $pressed{$name} = 1;
108 }
940c198 @zpmorgan music
authored
109 elsif ( $event->type == SDL_KEYUP ) {
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
110 $pressed{$name} = 0;
111 }
112 }
113 );
114
115
116 $app->add_show_handler(
117 sub {
118
119 #moving left ot right?
120 if ($pressed{right} and ! $pressed{left}){
121 $cryptopod->xv(.2);
122 }
123 elsif ($pressed{left} and ! $pressed{right}){
124 $cryptopod->xv(-.2);
125 }
126 else {
127 $cryptopod->xv(0);
128 }
129
130 # jumping?
131 if ($pressed{up} and $cryptopod->status eq 'walking'){
132 $cryptopod->yv(-.3);
133 $cryptopod->{y} -= .001;
117ce43 @zpmorgan slightly harder to get stuck
authored
134 $cryptopod->set_freefall;
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
135 }
136 $cryptopod->do;
216d4b1 @zpmorgan somebody else's problem
authored
137 $app->draw_rect( [ 0, 0, $app->w, $app->h ], 0x000000FF );
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
138 $viewport->draw();
b2e465e @zpmorgan do terrain without using sprites
authored
139 $rock_surf->blit ($app, $rect32, $rect32);
6f971c0 @zpmorgan Just some logic that I spewed from my fingertips.
authored
140 }
141 );
142 $app->add_show_handler( sub { $app->update(); } );
143
144
145 $app->run();
Something went wrong with that request. Please try again.