-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.pl
More file actions
executable file
·563 lines (520 loc) · 23.1 KB
/
main.pl
File metadata and controls
executable file
·563 lines (520 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
#!/usr/bin/perl
use Carp;
use strict;
use warnings;
use SDL;
use SDL::Video;
use SDLx::App;
use SDLx::Surface;
use SDLx::Sprite;
use SDL::Image;
use SDL::GFX::Rotozoom;
use SDLx::Rect;
use SDL::Event;
use SDL::Events;
use SDLx::Music;
use SDLx::Sound;
use SDL::Mixer::Music;
use SDLx::Text;
#--Define Entities--
use Entity::Player;
use Entity::Enemy qw(createEnemy);
use Entity::data ':all';
use Time::HiRes qw(usleep time);
use Data::Dumper;
use threads;
use threads::shared;
use SDL::Time;
#die() command override so we get a more informitive error (thanks to perl SDL's shite error reporting)
$SIG{ __DIE__ } = sub { print "SDL error: " . SDL::get_error . "\n"; Carp::confess( @_ ) };
my @playerSprites = (["img/player/fighter/down.png","img/player/fighter/left.png","img/player/fighter/right.png","img/player/fighter/behind.png"],
["img/player/tourist/down.png","img/player/tourist/left.png","img/player/tourist/right.png","img/player/tourist/behind.png"],
["img/player/caveman/down.png","img/player/caveman/left.png","img/player/caveman/right.png","img/player/caveman/behind.png"],
["img/player/assassin/down.png","img/player/assassin/left.png","img/player/assassin/right.png","img/player/assassin/behind.png"],
["img/player/knight/down.png","img/player/knight/left.png","img/player/knight/right.png","img/player/knight/behind.png"],
["img/player/wizard/down.png","img/player/wizard/left.png","img/player/wizard/right.png","img/player/wizard/behind.png"]); #Mark all the sprites for possible loading
my $playerSprite = $playerSprites[0]; #Set the default sprite
#--Define Screen width/height
our %resolution = (width => 800, height => 600); #App resolution
our @playerPos = (0,0); #Player Position
#--Define variables--
my $new_event = SDL::Event->new(); #Event handler
my $snd = SDLx::Sound->new(); #Sound object
our $tick; #Ticker for the enemy movement
my $timerTick :shared = 0; #Make sure timerTick is shared between threads
my $timerID; #Timer ID to hold
my $text_box; #Score box
my $score = 0; #Score starts at 0
my $numcoins; #Number of coins in the level, set by level editor
my $newnumcoins; #coins after one or more have been collected
###################### SDL Text Box ###########################
# Add in a text box/location; we'll put text in it later
$text_box = SDLx::Text->new(size=>'16', # font can also be specified
color=>[255,255,255], # [R,G,B]
x=> 20,
y=> 20,
font => 'font/PressStart2P.ttf');
###############################################################
##Main menu text boxes##
my $playMenu = SDLx::Text->new(text=> 'New Game', #New Game menu item
size=>'16',
x=> 266,
y=>533,
color=>[0,0,0],
font => 'font/PressStart2P.ttf',
h_align => 'center');
my $exitMenu = SDLx::Text->new(text=> 'Exit', #Exit menu item
size=>'16',
x=> 533,
y=>533,
color=>[0,0,0],
font => 'font/PressStart2P.ttf',
h_align => 'center');
my $finalScore = SDLx::Text->new(size=>'16',
x=> 400,
y=>533,
color=>[0,0,0],
font => 'font/PressStart2P.ttf',
h_align=> 'center');
#--Load all static images (walls etc)--
my ($wall, $tile, $stairs, $water, $house, $home, $hut, $coin, $downStairs);
my @death = (SDLx::Sprite->new( image => "img/death1.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death2.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death3.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death4.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death5.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death6.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death7.png" ), # loads death screen
SDLx::Sprite->new( image => "img/death8.png" ),
SDLx::Sprite->new( image => "img/death.png" ) # loads death screen
);# loads death screen
my ($upStairsFound, $downStairsFound, $levelDir); #Variables for the "staircheck" system
#set both of these to 1 to prevent an infinite loading loop
$upStairsFound = 1;
$downStairsFound = 1;
$levelDir = 1;
my $level; #holds the current levelnumber
$level = 0; #make sure it's 0 to start with
my $maxLevel = 4; #which level is the last leve
my @ents; #holds all the data hashrefs
our $hackPlusMusic = SDLx::Music->new(); #Music object
$hackPlusMusic->data( #Actual music definitions, handled by level loading
TitleTheme => 'music/Tempting Secrets.ogg',
Level_0 => 'music/Minstrel Guild.ogg',
Level_1 => 'music/Enchanted Valley.ogg',
Level_2 => 'music/Frozen Star.ogg',
Level_3 => 'music/Lightless Dawn.ogg',
Level_4 => 'music/Not As It Seems.ogg',
Level_5 => 'music/Rites.ogg'
);
my $musicData; #Music data will be stored here
my $fadeTime = 0; #Fade timer
my $app = SDLx::App->new( #Create Window
w => $resolution{'width'},
h => $resolution{'height'},
d =>32,
event => $new_event,
title => "Hack Plus ++",
exit_on_quit => 1,
);
@room = (); #holds the room data
my $offset; #holds the drawing offset data
$hackPlusMusic->play($hackPlusMusic->data("TitleTheme"), loops => 1); #Start playing hte title theme
$app->add_show_handler(\&drawMenu); #Add the menu drawing
$app->add_event_handler(\&doMenuThings); #Add the menu event handler
my $syncID = $app->add_show_handler(sub{ $app->sync }); #Save the sync handler to a temporary variable
my $menu = SDLx::Sprite->new( image => "img/main-menu2.png" ); #Our menu sprite
my $playerMenu = SDLx::Sprite->new( image => "img/playerSelect.png" ) or die "Could not load player menu"; #Our player menu sprite
##Menu Variables##
my @selectCoords = (0,0);
my $selectPlayer = 0;
my $selectNum = 0;
my $selectMenu = 0;
##RUN THE GAME##
$app->run();
#--actually start the program--
sub startGame {
$app->remove_all_event_handlers(); #Remove all handlers to prepare to start the game
$app->remove_show_handler($syncID); #Remove the Sync handler so we can put something after it
$timerID = SDL::Time::add_timer(200, 'moveTimer'); #start the timer
$app->add_show_handler(sub {&fadeOut(1.5, @_)}); #Add the fadeout handler, this will automatically start the game after completion
$syncID = $app->add_show_handler(sub { $app->sync} ); #Re-add the sync handler
}
sub drawMenu { #Draw the main menu backdrop.
my ($delta, $app) = @_; #standard draw handler header
$app->draw_rect([0, 0, $resolution{'width'}, $resolution{'height'}], 0x000000); #Blank the screen
my $surface = SDL::GFX::Rotozoom::surface ($menu->surface(), 0, 1.8, SMOOTHING_OFF); #Zoom the backdrop (Will be fixed)
my $sprite = SDLx::Sprite->new( surface => $surface); #Re-parent the sprite to the new surface
$sprite->x(($resolution{'width'} / 2) - $sprite->w() / 2); #Center it
$sprite->y(($resolution{'height'} / 2) - $sprite->h() / 2); #^
$sprite->draw($app); #Draw it to the app
$playMenu->color([150,0,0]) if $selectMenu == 1; #make this red if it's selected
$playMenu->color([0,0,0]) if $selectMenu != 1; #else leave it black
$exitMenu->color([150,0,0]) if $selectMenu == 2; #same here
$exitMenu->color([0,0,0]) if $selectMenu != 2;
$app->draw_rect([0, $playMenu->y() - 4, $resolution{'width'}, $playMenu->h() + 8], 0xFFFFFFFF); #Add the white backgroud
$playMenu->write_to($app); #Draw to the app
$exitMenu->write_to($app); #see above
}
sub doMenuThings {
my ($event, $app)= @_; #Standard event handler header
my @rect = (SDLx::Rect->new($playMenu->x - $playMenu->w / 2, $playMenu->y, $playMenu->w, $playMenu->h),
SDLx::Rect->new($exitMenu->x - $exitMenu->w / 2, $exitMenu->y, $exitMenu->w, $exitMenu->h)); #Selection rectangles based on text location
if ($event->type == SDL_MOUSEBUTTONDOWN) {
if ($event->button_button == SDL_BUTTON_LEFT) { #Did someone click?
foreach my $rectangle (@rect) {
if ($rectangle->collidepoint($event->button_x(), $event->button_y)) { #check if they clicked inside one of the rectangles
if ($selectMenu == 1) { #If they did, and one of these is selected, do the thing
goToPlayerMenu();
}
elsif ($selectMenu == 2) {
exit(0);
}
}
}
}
}
elsif ($event->type == SDL_MOUSEMOTION) { #Else, did the mouse move?
$selectMenu = 0; #If it did, set this to 0 then check our rectangles again
foreach my $num (0 .. $#rect) {
my $rectangle = $rect[$num]; #Get our rectangle
if ($rectangle->collidepoint($event->motion_x(), $event->motion_y())) { #Did we enter a rectangle
$selectMenu = $num + 1; #Yes if we did, select the appropriate menu item
}
}
}
}
sub drawPlayerSelect {
my ($delta, $app) = @_;
#Clear the screen
$app->draw_rect([0, 0, $resolution{'width'}, $resolution{'height'}], 0x000000);
#Draw the players to the screen
my $surface = SDL::GFX::Rotozoom::surface ($playerMenu->surface(), 0, 2, SMOOTHING_OFF); #Do a rotozoom
my $sprite = SDLx::Sprite->new( surface => $surface); #Reparent the surface to $sprite
$sprite->x(($resolution{'width'} / 2) - $sprite->w() / 2); #Set X pos of the player select
$sprite->y(($resolution{'height'} / 2) - $sprite->h() / 2); #Set the Y pos of the player select
$sprite->draw($app);
##TRANSPARENCY HACK##
if ($selectPlayer) {
$surface = $app->surface(); #Get the app's surface
my $blitSurf = SDLx::Surface->new(w => 52, h => 54, d => 32); #Make a new "blitting" surface
$surface = SDL::Video::set_alpha($surface, SDL_SRCALPHA, 60); #Set the app's surface to be transparent at 60% transparency
$app->surface($surface); #Rebind the surface to the app
$blitSurf->draw_rect([0, 0, 52, 54], [255, 255, 255, 60]); #fill blitSurf with semi-transparent color
$blitSurf->blit($app, [0,0,52,54], [$selectCoords[0], $selectCoords[1], 52, 54]); #Blit the blitsurf to the app
}
##END TRANSPARENCY HACK##
my $selectText = SDLx::Text->new->text( "Select Player" ); #Create text
$selectText->font('font/PressStart2P.ttf'); #Our font file
$selectText->size(30); #32 pt font
$selectText->h_align('center'); #Align to center
$selectText->x($resolution{'width'} / 2); #X position is center
$selectText->y(100); #Y position is 100
$selectText->color([0, 0, 0]); #Color is 0x000000 or Black
$app->draw_rect([0, $selectText->y() - 4, $resolution{'width'}, $selectText->h() + 8], 0xFFFFFFFF); #Add the white backgroud
$selectText->write_to($app); #Draw to app
}
sub goToPlayerMenu {
$app->remove_all_handlers(); #Clear out everything
$app->add_show_handler(\&drawPlayerSelect); #Add the player select show handler
$app->add_event_handler(\&playerSelectEvents); #add the player select event handler
$syncID = $app->add_show_handler(sub {$app->sync()}); #re-add our sync
}
sub playerSelectEvents { #Works the same as doMenuThings()
my ($event, $app)= @_;
my @rect = (SDLx::Rect->new(344, 214, 52, 54),
SDLx::Rect->new(404, 214, 52, 54),
SDLx::Rect->new(344, 270, 52, 54),
SDLx::Rect->new(404, 270, 52, 54),
SDLx::Rect->new(344, 328, 52, 54),
SDLx::Rect->new(404, 328, 52, 54)); #Selection rectangles
$selectPlayer = 0;
if ($event->type == SDL_MOUSEBUTTONDOWN) {
if ($event->button_button == SDL_BUTTON_LEFT) {
foreach my $rectangle (@rect) {
if ($rectangle->collidepoint($event->button_x(), $event->button_y)) {
$playerSprite = $playerSprites[$selectNum];
startGame();
}
}
}
}
elsif ($event->type == SDL_MOUSEMOTION) {
my $i;
foreach my $rectangle (@rect) {
if ($rectangle->collidepoint($event->motion_x(), $event->motion_y())) {
$selectPlayer = 1;
$selectNum = $i;
@selectCoords = ($rectangle->x, $rectangle->y);
}
$i++;
}
}
}
sub handleEvents { #Handles the quit event
my ($event, $app) = @_;
if($event->type == SDL_QUIT) { #Self-explanitory
$app->stop();
}
}
sub initWorld { #Initialise the world
my $offset = $_[0]; #get the offset
for my $x (0 .. $#room) { #go through each row
for my $y (0 .. $#{$room[$x]}) { #go through each colum
my $char = $room[$x][$y]; #get the character
if ($char eq 'p' or $char eq 'P') { #init the player if P
Entity::Player::initPlayer($playerSprite, [$x, $y], $offset);
}
if ($char eq 'E') { #init an enemy with the grim reaper skin if E
push(@ents, createEnemy(["img/enemies/grim_reaper/down.png","img/enemies/grim_reaper/left.png","img/enemies/grim_reaper/right.png","img/enemies/grim_reaper/behind.png"], [$x, $y], $offset, 1, $app));
}
if ($char eq 'G') { #init an enemy with the gnome skin if G
push(@ents, createEnemy(["img/enemies/gnome/down.png","img/enemies/gnome/left.png","img/enemies/gnome/right.png","img/enemies/gnome/behind.png"], [$x, $y], $offset, 0, $app));
}
if ($char eq 'O') { #init an enemy with the gnome skin if G
push(@ents, createEnemy(["img/enemies/orc/down.png","img/enemies/orc/left.png","img/enemies/orc/right.png","img/enemies/orc/behind.png"], [$x, $y], $offset, 0, $app));
}
if ($char eq 'I') { #init an enemy with the gnome skin if G
push(@ents, createEnemy(["img/enemies/eye/down.png","img/enemies/eye/left.png","img/enemies/eye/right.png","img/enemies/eye/behind.png"], [$x, $y], $offset, 1, $app));
}
if ($char eq 'C') {
}
}
}
}
sub drawWorld {
my ($delta, $app) = @_;
$upStairsFound = 0; #reset the stairs
$downStairsFound = 0;
$newnumcoins = 0;
for my $x (0 .. $#room) { #Go through each row
for my $y (0 .. $#{$room[$x]}) { #Go through each colunm
my $char = $room[$x][$y]; #get the character
#--determine where our stuff has to blit to--
my $dstx = (($resolution{'width'}/2) - (14)) + ((($x - $playerPos[0])*14) - (($y - $playerPos[1])*14)) -$offset; #long formula ;_;
my $dsty = (($x - $playerPos[0])+($y - $playerPos[1]))*7 + $resolution{"height"} / 2;
#--Image and sprite handling--
if ($char eq '.' ||
$char eq 'p' ||
$char eq 'P') { #Floor drawing, handles the enemies and makes sure the floor is under them
$tile->x($dstx);
$tile->y($dsty);
$tile->draw($app);
}
if ($char eq 'p' || $char eq 'P') {
@playerPos = ($x, $y);
&Entity::Player::showPlayer(0, $app);
}
if ($char eq 'E' || $char eq 'G' || $char eq 'I' || $char eq 'O') {
$tile->x($dstx);
$tile->y($dsty);
$tile->draw($app);
foreach my $entity (@ents) {
my $entPosX = $entity->{_pos}[0];
my $entPosY = $entity->{_pos}[1];
if($entPosX == $x && $entPosY == $y) {
&Entity::Enemy::showEnemy($entity, 0, $app);
}
}
}
elsif ($char eq '#') { #wall drawing
$wall->x($dstx);
$wall->y($dsty - 15);
$wall->draw($app);
}
elsif ($char eq 'w') { #water
$water->x($dstx);
$water->y($dsty - 15);
$water->draw($app);
}
elsif ($char eq 'h') { #house facing south
$house->x($dstx);
$house->y($dsty - 15);
$house->draw($app);
}
elsif ($char eq 'a') { #house facing east
$home->x($dstx);
$home->y($dsty - 15);
$home->draw($app);
}
elsif ($char eq 'b') { #back of the house
$hut->x($dstx);
$hut->y($dsty - 15);
$hut->draw($app);
}
elsif ($char eq 'C') {
$tile->x($dstx);
$tile->y($dsty);
$tile->draw($app);
$coin->x($dstx);
$coin->y($dsty);
$coin->draw($app);
$newnumcoins++;
}
if ($char eq 'u' || $char eq 'd') { #Up stairs
if ($char eq 'u') {
$stairs->x($dstx);
$stairs->y($dsty - 15);
$stairs->draw($app);
}
else {
$downStairs->x($dstx);
$downStairs->y($dsty);
$downStairs->draw($app);
}
$upStairsFound = 1 if $char eq 'u';
$downStairsFound = 1 if $char eq 'd';
}
}
}
$score+= 1*($numcoins-$newnumcoins);
$numcoins=$newnumcoins;
}
sub fadeOut {
my ($time, $s, $app) = @_;
my $blitSurf = SDLx::Surface->new(w => $resolution{'width'}, h => $resolution{'height'}, d => 32);
if ($fadeTime == 0) {
$fadeTime = Time::HiRes::time;
}
my $curTime = Time::HiRes::time;
my $totalTime = $curTime - $fadeTime;
if ($totalTime >= $time) {
$fadeTime = 0;
$app->draw_rect([0,0, $resolution{'width'}, $resolution{'height'}], 0x000000FF);
$app->sync();
$app->remove_all_handlers();
@ents = ();
@room = ();
loadWorld();
initHandlers(1);
}
else {
my $coloTime = $totalTime / $time;
my $alpha = 255 * $coloTime;
my $surface = $app->surface;
$surface = SDL::Video::set_alpha($surface, SDL_SRCALPHA, $alpha);
$app->surface($surface);
$blitSurf->draw_rect([0,0, $resolution{'width'}, $resolution{'height'}], [0,0,0,$alpha]);
$blitSurf->blit($app);
}
}
sub checkWorld { #Check if the stairs have changed
if (!$downStairsFound && $level != $maxLevel) { #if the stairs are gone and we're not at our max level
$app->remove_all_handlers(); #delete the current handlers, they were for the last level
$level++; #We're going further down so our level does the same
$levelDir = 1;
print "Going down!\n";
initHandlers(0); #reload event handlers
}
elsif (!$upStairsFound && $level != 0) { #if the stairs are gone and we're not on level 0
$app->remove_all_handlers();
$level--;
$levelDir = -1;
print "Going up!\n";
initHandlers(0);
}
}
sub loadWorld { #load a world into the $room
$roomArea = '';
open FILE, "worlds/$level.txt"; #open world
while (<FILE>) { #slurp the file into the string
$roomArea .= $_;
}
close FILE;
print $roomArea . "\n";
parseWorld(); #parse the world into the proper array
$hackPlusMusic->play($musicData, loops => 1);
}
sub parseWorld {
my $virtX = 0; #virtual X coordinate
$numcoins = 0;
foreach my $line (split("\n", $roomArea)) { #split each line
my @worldOpts = split(": ", $line); #Check for world options
if ($worldOpts[0] eq "tile_set") { #tileset handling (e.g. tile_set: cave)
print "loading tileset: $worldOpts[1]";
loadTileSet($worldOpts[1]); #load the tileset into memory
}
elsif ($worldOpts[0] eq "music") { #music handling (e.g. music: Level_0)
$musicData = $hackPlusMusic->data($worldOpts[1]);
}
else {
foreach my $char (split("", $line)) { #split line into characters
if ($char eq 'p' and $levelDir != 1) { #check where we need to put the player depending on the world format.
$char = '.';
}
elsif($char eq 'P' and $levelDir != -1) {
$char = '.';
}
elsif($char eq 'C') {
$numcoins++;
}
push @{$room[$virtX]}, $char; #push the character into the world 2d array
$virtX++; #increment virtual X
}
$virtX = 0; #Reset virtual X when we finish a line
}
}
#Compute best-fit##
$offset = 0 #(($resolution{'width'}/2) - 14) - ($#{$room[0]}*14);
}
sub initHandlers { #(re)initialise world events
my $deInitEnemies = shift;
SDL::Time::remove_timer($timerID);
$timerID = SDL::Time::add_timer(200, 'moveTimer');
$app->add_move_handler(sub {if ($timerTick and !$tick) {$timerTick = 0; $tick = 1} else {$tick = 0}});
$app->add_show_handler(sub {$app->draw_rect([0, 0, $resolution{'width'}, $resolution{'height'}], 0x000000)}); #clear the screen
$app->add_event_handler(\&checkWorld) if $deInitEnemies; #load our checkworld handler
initWorld($offset) if $deInitEnemies; #initialise the world entities
$app->add_event_handler(\&handleEvents); #add the event handler
$app->add_event_handler(\&Entity::Player::doPlayerEvents) if $deInitEnemies; #add the player event handler
$app->add_move_handler(\&Entity::Player::movePlayer) if $deInitEnemies; #add the player move handler
#$app->add_show_handler(\&Entity::Player::showPlayer); #etc.. etc..
$app->add_show_handler(\&drawWorld); #draw the world
$app->add_show_handler(sub {&fadeOut(1, @_)}) if !$deInitEnemies;
SDL::Mixer::Music::fade_out_music(1000) if !$deInitEnemies;
$app->add_show_handler(\&zoomApp); #Zoom the entire app's screen
$app->add_show_handler(\&writeScore);
$syncID = $app->add_show_handler(sub {$app->sync}); #draw everything to the screen
drawWorld(0, $app); #resets the stair variables
}
# death screen, grim reaper kills main player
sub death {
SDL::Mixer::Music::fade_out_music(2000); #Manual fadeout calling b/c documentation was for a stub function
$snd->play("music/evilLaugh.ogg");
foreach my $sprite (@death) {
usleep 500000;
$app->draw_rect([0, 0, $resolution{'width'}, $resolution{'height'}], 0x000000);
$sprite->x(($resolution{'width'} / 2) - $sprite->w() / 2);
$sprite->y(($resolution{'height'} / 2) - $sprite->h() / 2);
$sprite->draw($app);
$app->sync;
}
$app->draw_rect([0, $playMenu->y() - 4, $resolution{'width'}, $playMenu->h() + 8], 0xFFFFFFFF); #Add the white backgroud
$finalScore->write_to($app,"Final Score: $score");
$app->sync;
sleep 1;
exit;
}
sub loadTileSet {
my $tileset = shift;
$wall = SDLx::Sprite->new( image => "img/room/$tileset/wall.png" ) or die("Could not load wall image for tileset $tileset!");
$tile = SDLx::Sprite->new( image => "img/room/$tileset/tile.png" ) or die("Could not load tile image for tileset $tileset!");
$stairs = SDLx::Sprite->new( image => "img/room/$tileset/stairs.png" ) or die("Could not load stair image for tileset $tileset!");
$downStairs = SDLx::Sprite->new( image => "img/room/$tileset/downStairs.png") or die("Could not load downstair image for tileset $tileset!");
$water = SDLx::Sprite->new( image => "img/room/$tileset/water.png" ) or die("Could not load water image for tileset $tileset!");
$house = SDLx::Sprite->new( image => "img/room/$tileset/house.png" ) or die("Could not load house image for tileset $tileset!");
$home = SDLx::Sprite->new( image => "img/room/$tileset/house_side.png" ) or die("Could not load house side image for tileset $tileset!");
$hut = SDLx::Sprite->new( image => "img/room/$tileset/house_back.png" ) or die("Could not load house back image for tileset $tileset!");
$coin = SDLx::Sprite->new( image => "img/room/coin.png" ) or
die("Could not load coin image for room!");
}
sub zoomApp {
my ($delta, $app) = @_;
my $surface = SDL::GFX::Rotozoom::surface($app->surface, 0, 2, SMOOTHING_OFF);
$app->draw_rect([0,0,$resolution{'width'}, $resolution{'height'}], 0x000000);
$app->blit_by($surface, [$resolution{'width'} / 2, $resolution{'height'} / 2, $resolution{'width'}, $resolution{'height'},], [0, 0, $resolution{'width'}, $resolution{'height'}]);
}
sub moveTimer {$timerTick = 1; return 150}
sub writeScore {
$text_box->write_to($app,"Coins: ($score)");
}