-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stage.cpp
735 lines (667 loc) · 18.9 KB
/
Stage.cpp
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/* FCII Final Project
Spring 2013
Michael Powers
Brad Stalcup
Sean Murphy
Neal Sheehan
Solara
Stage Implementation file */
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "Stage.h"
#include "Unit.h"
#include <cmath>
#define SCREEN_WIDTH 500
#define SCREEN_HEIGHT 500
#define SCREEN_BPP 32
Stage::Stage()
{
//units.push_back(new Hero(x,y,0,0,0,0,0));
screen = NULL;
background = NULL;
title = NULL;
init();
load_files();
set_clips();
xoffset = 100;
yoffset = 100;
maxBullets = 5; //max number of bullets on screen is 5
currBullets = 0;
}
bool Stage::checkCollisions(Unit* unit)
{
bool collide=false;
for(int i = 0; i<units.size(); i++)
{
if(units[i] == unit)
continue;
else if(unit->isCollided(units[i]))
{
unit->collide(units[i]);
collide=true;
}
}
return(collide);
}
void Stage::perform(double dt, Unit* hero)
{
for(int i = 0; i < units.size(); i++)
{
if(!isOffScreen(units[i]))
{
units[i]->increment(dt); //if it's on screen draw it
}
else
{
if(units[i]->isBullet())
{
units[i]->setHealth(0); //if a bullet goes off screen don't draw it
}
}
if (units[i]->getHealth() <= 0)
{
removeUnit(units[i]);
i--;
}
//checkCollisions(units[i],dt);
checkCollisions(units[i]);
}
adjustUnits();
xoffset = -hero->getx() + SCREEN_WIDTH/2;
yoffset = -hero->gety() + SCREEN_HEIGHT/2;
}
SDL_Surface *Stage::load_image( std::string filename )
{
//Lazyfoo.net
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
//If the image was optimized just fine
if( optimizedImage != NULL)
{
//Map the color key
Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 136, 255);
//Set all pixels of color R 0, G 0 xFF, B 0xFF to be transparent
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
}
}
//Return the optimized image
return optimizedImage;
}
void Stage::apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL, int xo = 0, int yo = 0 )
{
//Lazyfoo.net
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x + xo;
offset.y = y + yo;
//Blit
SDL_BlitSurface( source, clip , destination, &offset );
}
bool Stage::init()
{
//Lazyfoo.net
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Solara", NULL );
//If everything initialized fine
return true;
}
bool Stage::init_fullscreen()
{
//Lazyfoo.net
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_FULLSCREEN);
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Solara", NULL );
//If everything initialized fine
return true;
}
bool Stage::load_files()
{
//Lazyfoo.net
//Load the surfaces
background = load_image( "images/terrain.png");
title = load_image( "images/solaratitle.png" );
slide1 = load_image( "images/Slide1.png" );
slide2 = load_image( "images/Slide2.png" );
slide3 = load_image( "images/Slide3.png" );
slide4 = load_image( "images/Slide4.png" );
slide5 = load_image( "images/Slide5.png" );
slide6 = load_image( "images/Slide6.png" );
slidemike = load_image( "images/SlideMike.png" );
slidebrad = load_image( "images/SlideBrad.png" );
slidesean = load_image( "images/SlideSean.png" );
slidesneal = load_image( "images/SlideSneal.png" );
youwin = load_image( "images/YouWin.png" );
//Error in loading title
if( title == NULL )
{
return false;
}
//If there was an error in loading the terrain
if( background == NULL )
{
return false;
}
//Error in loading slides
if( slide1==NULL || slide2==NULL || slide3==NULL || slide4==NULL || slide5==NULL)
{
return false;
}
//If everything loaded fine
return true;
}
void Stage::set_clips()
{
//sets the clips
//Clip range for terrain
for(int i=0; i<60; ++i)
{
for(int j=0; j<22; ++j)
{
clip_background[i][j].x = 17*i+1;
clip_background[i][j].y = 17*j+1;
clip_background[i][j].w = 16;
clip_background[i][j].h = 16;
}
}
}
void Stage::draw(int r, int g, int b, int rIs, int gIs, int bIs){
//Fill the screen blue
//SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB(screen->format, 102, 178, 255) );
//Make the ocean
int xMin=0,xMax=0,yMin=0,yMax=0;
for(int i = 0; i<areas.size(); i++) {
if(areas[i].x < xMin) xMin = areas[i].x;
if(areas[i].x+areas[i].w > xMax) xMax = areas[i].x+areas[i].w;
if(areas[i].y < yMin) yMin = areas[i].y;
if(areas[i].y+areas[i].h > yMax) yMax = areas[i].y+areas[i].h;
}
for(int i = xMin-SCREEN_WIDTH/2; i < xMax+SCREEN_WIDTH/2; i+=16)
for(int j = yMin-SCREEN_HEIGHT/2; j < yMax+SCREEN_HEIGHT/2; j+=16)
apply_surface(i, j, background, screen, &clip_background[20][16],xoffset,yoffset);
//drawing the terrain sprites based on addArea function
for(int i = 0; i<areas.size(); i++){
for(int x = areas[i].x; x<areas[i].x+areas[i].w; x+=16){
for(int y = areas[i].y; y<areas[i].y+areas[i].h; y+=16){
//draw correct sprite based on location
if(x == areas[i].x){ //left most column of sprites
if(y == areas[i].y){ //top row of sprites
//draw top left corner sprite
apply_surface( x, y, background, screen, &clip_background[3+location[i]*7][1], xoffset, yoffset);
}
else if(y == areas[i].y + areas[i].h - 16){
//draw bottom left sprite
apply_surface( x, y, background, screen, &clip_background[1+location[i]*7][4], xoffset, yoffset);
}
else{
//draw left edge sprite
apply_surface( x, y, background, screen, &clip_background[3+location[i]*7][2], xoffset, yoffset);
}
}
else if(y == areas[i].y){//top row of sprites
if(x == areas[i].x + areas[i].w - 16){
//draw top right sprite
apply_surface( x, y, background, screen, &clip_background[4+location[i]*7][1], xoffset,yoffset);
}
else{
//draw top edge sprite
apply_surface( x, y, background, screen, &clip_background[2+location[i]*7][3], xoffset, yoffset);
}
}
else if(x == areas[i].x+areas[i].w-16){//right most column of sprites
if(y == areas[i].y+areas[i].h-16){//bottom row of sprites
//draw bottom right corner sprite
apply_surface( x, y, background, screen, &clip_background[4+location[i]*7][6], xoffset, yoffset);
}
else{
//draw right edge sprite
apply_surface( x, y, background, screen, &clip_background[4+location[i]*7][5], xoffset, yoffset);
}
}
else if(y == areas[i].y+areas[i].h-16){
//draw bottom edge sprite
apply_surface( x, y, background, screen, &clip_background[5+location[i]*7][4], xoffset, yoffset);
}
else{
//draw regular sprite
apply_surface( x, y, background, screen, &clip_background[2+location[i]*7][2], xoffset, yoffset);
}
}
}
}
//drawing the units
for(int i = 0; i < units.size(); i++)
//if(isInBounds(units[i]->getx()/*minus size?*/, units[i]->gety()))
{
units[i]->draw(screen,xoffset,yoffset);
// cout << "drawing unit at " << units[i]->getx() << ", " << units[i]->gety() << endl;
}
//drawing terrain filler
//drawing powerups
int color=r*1+g*2+b*4;
SDL_Rect border,inside,line1,line2;
for(int i = 0; i < 4; ++i)
{
border.x = SCREEN_WIDTH/4 + i*SCREEN_WIDTH/8;
border.y = SCREEN_HEIGHT*7/8;
border.w = SCREEN_WIDTH/16;
border.h = SCREEN_HEIGHT/16;
inside.x = border.x + 2;
inside.y = border.y + 2;
inside.w = border.w - 4;
inside.h = border.h - 4;
//determine colors
//powerup 1
if(i==0){
//powerup not available
if(!bIs){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,255,255,255) );
SDL_FillRect( screen,&inside, SDL_MapRGB( screen->format,0,0,0) );
}
//powerup on
else if(b==1){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,100,100,255) );
}
//powerup off
else{
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,100,100,255) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,0,0) );
}
//plus sign
line1.x=border.x+border.w+border.w/4+2;
line1.y=border.y+border.h/2;
line1.w=border.w/2;
line1.h=2;
line2.x=border.x+border.w+border.w/2;
line2.y=border.y+border.h/4+1;
line2.w=2;
line2.h=border.h/2;
SDL_FillRect( screen, &line1, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &line2, SDL_MapRGB( screen->format,0,0,0) );
}
//powerup 2
else if(i==1){
//powerup not available
if(!rIs){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,255,255,255) );
SDL_FillRect( screen,&inside, SDL_MapRGB( screen->format,0,0,0) );
}
//powerup on
else if(r==1){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,0,0) );
}
//powerup off
else{
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,255,0,0) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,0,0) );
}
//plus sign
line1.x=border.x+border.w+border.w/4+2;
line1.y=border.y+border.h/2;
line1.w=border.w/2;
line1.h=2;
line2.x=border.x+border.w+border.w/2;
line2.y=border.y+border.h/4+1;
line2.w=2;
line2.h=border.h/2;
SDL_FillRect( screen, &line1, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &line2, SDL_MapRGB( screen->format,0,0,0) );
}
//powerup 3
else if(i==2){
//powerup not available
if(!gIs){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,255,255,255) );
SDL_FillRect( screen,&inside, SDL_MapRGB( screen->format,0,0,0) );
}
//powerup on
else if(g==1){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,255,0) );
}
//powerup off
else{
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,0,255,0) );
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,0,0) );
}
//equals sign
line1.x=border.x+border.w+border.w/4+2;
line1.y=border.y+border.h/3+1;
line1.w=border.w/2;
line1.h=2;
line2.x=border.x+border.w+border.w/4+2;
line2.y=border.y+2*border.h/3-1;
line2.w=border.w/2;
line2.h=2;
SDL_FillRect( screen, &line1, SDL_MapRGB( screen->format,0,0,0) );
SDL_FillRect( screen, &line2, SDL_MapRGB( screen->format,0,0,0) );
}
//powerups total
else if (i==3){
SDL_FillRect( screen, &border, SDL_MapRGB( screen->format,0,0,0) );
/*inside.x=border.x;
inside.y=border.y;
inside.w=border.w;
inside.h=border.h;*/
switch(color){
case 0: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,0,0) ); break;
case 1: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,0,0) ); break;
case 2: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,255,0) ); break;
case 3: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,255,0) ); break;
case 4: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,100,100,255) ); break;
case 5: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,0,255) ); break;
case 6: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,255,255) ); break;
case 7: SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,0,0) );
inside.x+=2; inside.y+=2; inside.w-=4; inside.h-=4;
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,255,0) );
inside.x+=2; inside.y+=2; inside.w-=4; inside.h-=4;
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,0,0,255) );
inside.x+=2; inside.y+=2; inside.w-=4; inside.h-=4;
SDL_FillRect( screen, &inside, SDL_MapRGB( screen->format,255,255,255) );
break;
}
}
}
SDL_Flip(screen);
}
int Stage::addArea(int x, int y, int w, int h, int loc) //adds an area and checks to make sure it is added
{
//sprite type
location.push_back(loc);
SDL_Rect add;
add.x = x-x%16;
add.y = y-y%16;
add.w = w-w%16;
add.h = h-h%16;
areas.push_back(add);
return 1;
}
void Stage::addUnit(Unit* spr){
if(spr->isBullet() && spr->isFromHero() && canFire())
{
currBullets++;
}
units.push_back(spr);
}
int Stage::removeUnit(Unit* unit){
for(int i = 0; i<units.size(); i++)
{
if(units[i] == unit){
if(unit->isBullet() && unit->isFromHero())
currBullets--;
delete unit;
/* delete spr;*/
units.erase(units.begin()+i);
}
}
return 0;
}
int Stage::isInBounds(int x, int y){ //checks if a point is inside any of the areas
int i = 0;
while(i < areas.size())
{
if(x >= areas[i].x && x <= areas[i].x+areas[i].w)
if(y >= areas[i].y && y <= areas[i].y+areas[i].h)
return true;
i++;
}
return false;
// returns int, false == 0, true == 1
}
void Stage::drawTitle(string pic, int isWest, int isSouth, int isEast)
{
if(pic == "title") apply_surface(0,0,title,screen);
if(pic == "slide1") apply_surface(0,0,slide1,screen);
if(pic == "slide2") apply_surface(0,0,slide2,screen);
if(pic == "slide3") apply_surface(0,0,slide3,screen);
if(pic == "slide4") apply_surface(0,0,slide4,screen);
if(pic == "slidemike") apply_surface(0,0,slidemike,screen);
if(pic == "slidebrad") apply_surface(0,0,slidebrad,screen);
if(pic == "slidesean") apply_surface(0,0,slidesean,screen);
if(pic == "slidesneal") apply_surface(0,0,slidesneal,screen);
if(pic == "youwin") apply_surface(0,0,youwin,screen);
if(pic == "slide5"){
apply_surface(0,0,slide5,screen);
SDL_Rect crossOut1,crossOut2;
if(isWest){
crossOut1.x=40;
crossOut1.y=200;
crossOut1.w=130;
crossOut1.h=5;
crossOut2.x=40;
crossOut2.y=228;
crossOut2.w=130;
crossOut2.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
SDL_FillRect(screen, &crossOut2, SDL_MapRGB( screen->format,0,0,0));
}
if(isSouth){
crossOut1.x=195;
crossOut1.y=278;
crossOut1.w=130;
crossOut1.h=5;
crossOut2.x=195;
crossOut2.y=302;
crossOut2.w=130;
crossOut2.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
SDL_FillRect(screen, &crossOut2, SDL_MapRGB( screen->format,0,0,0));
}
if(isEast){
crossOut1.x=330;
crossOut1.y=200;
crossOut1.w=130;
crossOut1.h=5;
crossOut2.x=330;
crossOut2.y=225;
crossOut2.w=130;
crossOut2.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
SDL_FillRect(screen, &crossOut2, SDL_MapRGB( screen->format,0,0,0));
}
}
if(pic == "slide6"){
apply_surface(0,0,slide6,screen);
SDL_Rect crossOut1;
crossOut1.x=40;
crossOut1.y=200;
crossOut1.w=130;
crossOut1.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
crossOut1.x=195;
crossOut1.y=278;
crossOut1.w=130;
crossOut1.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
crossOut1.x=330;
crossOut1.y=200;
crossOut1.w=130;
crossOut1.h=5;
SDL_FillRect(screen, &crossOut1, SDL_MapRGB( screen->format,0,0,0));
}
if( SDL_Flip( screen ) == -1 )
{
return;
}
}
void Stage::clear_screen()
{
SDL_FillRect (screen, &screen->clip_rect, SDL_MapRGB (screen->format, 255, 255, 255));
SDL_Flip(screen);
}
void Stage::clean_up()
{
//Free the surfaces
/* while(units.size())
{
removeUnit(units[0]);
}*/
SDL_FreeSurface( background );
SDL_FreeSurface(title);
SDL_FreeSurface(slide1);
SDL_FreeSurface(slide2);
SDL_FreeSurface(slide3);
SDL_FreeSurface(slide4);
SDL_FreeSurface(slide5);
SDL_FreeSurface(slide6);
SDL_FreeSurface(slidemike);
SDL_FreeSurface(slidebrad);
SDL_FreeSurface(slidesean);
SDL_FreeSurface(slidesneal);
SDL_FreeSurface(youwin);
//Quit SDL
SDL_Quit();
}
void Stage::adjustUnits()
{
bool topleft,topright,botleft,botright;
for(int i = 0; i<units.size(); i++)
{
// cout << "Needing to adjust unit" << endl;
if(units[i]->isBullet())
{
if(!isInBounds(units[i]->getx(), units[i]->gety()))
{
// cout << "subtracting from hero's current bullets" << endl;
units[i]->setHealth(0);
continue;
}
else if(isOffScreen(units[i]))
{
units[i]->setHealth(0);
continue;
}
}
else
{
topleft = topright = botleft = botright = 1;
//if topleft is in bounds
//if top right is in bounds
//if bottom left is in bounds
//if bottom right is in bounds
for(int j =0; j<sqrt(((units[i]->getx()*units[i]->getx())+(units[i]->gety()*units[i]->gety())));j++)
{
if(isInBounds(units[i]->getx(),units[i]->gety()))
topleft = 0;
if(isInBounds(units[i]->getx()+SPRWIDTH,units[i]->gety()))
topright = 0;
if(isInBounds(units[i]->getx(),units[i]->gety()+SPRLENGTH))
botleft = 0;
if(isInBounds(units[i]->getx()+SPRWIDTH,units[i]->gety()+SPRLENGTH))
botright = 0;
if(topright || botright || botleft || topleft)
{
if(topright)
{
if(botright)
{
units[i]->setx(units[i]->getx()-1);
}
if(topleft)
{
units[i]->sety(units[i]->gety()+1);
}
if(!botright && !topleft)
{
units[i]->setx(units[i]->getx()-1);
units[i]->sety(units[i]->gety()+1);
}
}
else if(topleft)
{
if(botleft)
{
units[i]->setx(units[i]->getx()+1);
}
else
{
units[i]->setx(units[i]->getx()+1);
units[i]->sety(units[i]->gety()+1);
}
}
else if(botright)
{
if(botleft)
{
units[i]->sety(units[i]->gety()-1);
}
else
{
units[i]->sety(units[i]->gety()-1);
units[i]->setx(units[i]->getx()-1);
}
}
else
{
units[i]->sety(units[i]->gety()-1);
units[i]->setx(units[i]->getx()+1);
}
}
else
break;
}
}
}
}
int Stage::getoffsetx()
{
return xoffset;
}
int Stage::getoffsety()
{
return yoffset;
}
bool Stage::canFire()
{
return (currBullets<maxBullets);
}
bool Stage::isOffScreen(Unit* unit)
{
if(unit->getx() < -xoffset-50)
return true;
else if(unit->getx() > -xoffset+SCREEN_WIDTH+50)
return true;
else if(unit->gety() < -yoffset-50)
return true;
else if(unit->gety() > -yoffset+SCREEN_HEIGHT+50)
return true;
//not off screen
return false;
}