-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLimitMovingRect.cc~
More file actions
892 lines (790 loc) · 19 KB
/
LimitMovingRect.cc~
File metadata and controls
892 lines (790 loc) · 19 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
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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>
#include <string>
using namespace std;
//Motion changer function
void loadKeyStat(void);
void changeDirection(int* vectorDirect);
void moveUpward(void);
void moveDownward(void);
void moveLeftward(void);
void moveRightward(void);
bool LimitInitialiseAll(void);
void LimitUpdateAll(void);
void lineJumpRect(int* directVector);
void inclinedJumpRect(int* directVector, char inclinePhase);
int multiKeyPressHandler(void);
void duckPositionRect(void);
void rollDuckedRect(char rollSide);
void mapKeyStatToKeyTable(void);
void loadImageToTexture(std::string pathImage);
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int incrementer = 1;
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screen = NULL;
//The screen Renderer
SDL_Renderer* screenRenderer = NULL;
//Texture wrapper class
class LTexture
{
public:
//Initializes variables
LTexture();
//Deallocates memory
~LTexture();
//Loads image at specified path
bool loadFromFile( std::string path );
//Deallocates texture
void free();
//Renders texture at given point
void render( int x, int y, SDL_Rect* clip = NULL );
//Gets image dimensions
int getWidth();
int getHeight();
private:
//The actual hardware texture
SDL_Texture* mTexture;
//Image dimensions
int mWidth;
int mHeight;
};
LTexture::LTexture()
{
//Initialize
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
LTexture::~LTexture()
{
//Deallocate
free();
}
bool LTexture::loadFromFile( std::string path )
{
//Get rid of preexisting texture
free();
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
screen = IMG_Load( path.c_str() );
if( loadedSurface == NULL )
{
printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
}
else
{
//Color key image
SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) );
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface( screenRenderer, loadedSurface );
if( newTexture == NULL )
{
printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
}
else
{
//Get image dimensions
mWidth = loadedSurface->w;
mHeight = loadedSurface->h;
}
//Get rid of old loaded surface
//SDL_FreeSurface( loadedSurface );
}
//Return success
mTexture = newTexture;
return mTexture != NULL;
}
void LTexture::free()
{
//Free texture if it exists
if( mTexture != NULL )
{
SDL_DestroyTexture( mTexture );
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
}
void LTexture::render( int x, int y, SDL_Rect* clip )
{
//Set rendering space and render to screen
SDL_Rect renderQuad = { x, y, mWidth, mHeight };
//Set clip rendering dimensions
if( clip != NULL )
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;
}
//Render to screen
SDL_RenderCopy( screenRenderer, mTexture, clip, &renderQuad );
}
int LTexture::getWidth()
{
return mWidth;
}
int LTexture::getHeight()
{
return mHeight;
}
//The texture for caveman
//LTexture* playerTexture = NULL;
//The texture for background
LTexture* screenTexture;
//The image Rectangle for png file
SDL_Rect* imageRect = NULL;
//The player Rectangle on screen
SDL_Rect* playerRect = NULL;
//The image rectangle for scree
SDL_Rect* screenImageRect = NULL;
//keyboard statistics table
const Uint8* keyStat;
//Color variables
Uint32 color;
Uint32 color2;
//Duck down variable
bool isDuck = false;
//Roll key status
bool rollKeyDown = false;
//Duck key status
bool duckKeyDown = false;
//motion diimageRection variable
char motionFace = '\0';
//Type of key press
enum keyTypePressed
{
KEY_PRESS_SURFACE_DEFAULT,
KEY_PRESS_SURFACE_UP,
KEY_PRESS_SURFACE_DOWN,
KEY_PRESS_SURFACE_LEFT,
KEY_PRESS_SURFACE_RIGHT,
KEY_PRESS_SURFACE_SPACE,
KEY_PRESS_SURFACE_RCTRL,
KEY_PRESS_SURFACE_R,
KEY_PRESS_SURFACE_TOTAL
};
//Multi key press array
bool keyPressTable[KEY_PRESS_SURFACE_TOTAL];
//Key press surfaces constants
enum KeyPressSurfaces
{
DIRECT_VECTOR_SURFACE_DEFAULT,
DIRECT_VECTOR_SURFACE_UP,
DIRECT_VECTOR_SURFACE_DOWN,
DIRECT_VECTOR_SURFACE_LEFT,
DIRECT_VECTOR_SURFACE_RIGHT,
DIRECT_VECTOR_SURFACE_JUMP,
DIRECT_VECTOR_SURFACE_JUMPL,
DIRECT_VECTOR_SURFACE_JUMPR,
DIRECT_VECTOR_SURFACE_DUCK,
DIRECT_VECTOR_SURFACE_LROLL,
DIRECT_VECTOR_SURFACE_RROLL
};
int main( int argc, char* args[] )
{
int keyDirectValue = 0;
bool running = true;
const int FPS = 30;
Uint32 start;
keyStat = SDL_GetKeyboardState(NULL);
if(LimitInitialiseAll() == 0)
{
cout << "Terminate due to above Errors\n";
return 0;
}
else
{
color = SDL_MapRGB(screen->format, 0xff,0xff,0xff);
color2 = SDL_MapRGB(screen->format, 0,0,0);
while(running)
{
start = SDL_GetTicks();
if(SDL_QuitRequested())
{
running = false;
continue;
}
loadKeyStat();
keyDirectValue = multiKeyPressHandler();
changeDirection(&keyDirectValue);
LimitUpdateAll();
//SDL_Delay(1);
if(1000/FPS > SDL_GetTicks()-start)
{
SDL_Delay((1000/FPS)-(SDL_GetTicks()-start));
}
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0;
}
}
void loadKeyStat(void)
{
SDL_PumpEvents();
mapKeyStatToKeyTable();
}
void changeDirection(int* vectorDirect)
{
switch(*vectorDirect)
{
case DIRECT_VECTOR_SURFACE_UP:
{
moveUpward();
break;
}
case DIRECT_VECTOR_SURFACE_DOWN:
{
moveDownward();
break;
}
case DIRECT_VECTOR_SURFACE_LEFT:
{
moveLeftward();
break;
}
case DIRECT_VECTOR_SURFACE_RIGHT:
{
moveRightward();
break;
}
case DIRECT_VECTOR_SURFACE_JUMP:
{
lineJumpRect(vectorDirect);
break;
}
case DIRECT_VECTOR_SURFACE_JUMPL:
{
inclinedJumpRect(vectorDirect, 'l');
break;
}
case DIRECT_VECTOR_SURFACE_JUMPR:
{
inclinedJumpRect(vectorDirect, 'r');
break;
}
case DIRECT_VECTOR_SURFACE_DUCK:
{
duckPositionRect();
break;
}
case DIRECT_VECTOR_SURFACE_LROLL:
{
rollDuckedRect('l');
break;
}
case DIRECT_VECTOR_SURFACE_RROLL:
{
rollDuckedRect('r');
}
case DIRECT_VECTOR_SURFACE_DEFAULT:
{
break;
}
}
}
void moveUpward(void)
{
if((imageRect->y/* + imageRect->h*/) > 0)
{
imageRect->y -= incrementer;
}
else
{
if((imageRect->x/* + imageRect->w*/) > 0)
{
imageRect->x -= imageRect->w;
imageRect->y = SCREEN_HEIGHT;
}
else
{
imageRect->y = SCREEN_HEIGHT - imageRect->h;
imageRect->x = SCREEN_WIDTH - imageRect->w;
}
}
}
void moveDownward(void)
{
if((imageRect->y + imageRect->h) < SCREEN_HEIGHT)
{
imageRect->y += incrementer;
}
else
{
if((imageRect->x + imageRect->w) < SCREEN_WIDTH)
{
imageRect->x += imageRect->w;
imageRect->y = 0;
}
else
{
imageRect->y = 0;
imageRect->x = 0;
}
}
}
void moveLeftward(void)
{
if((imageRect->x/* + imageRect->w*/) > 0)
{
imageRect->x -= incrementer;
}
else
{
if((imageRect->y/* + imageRect->h*/) > imageRect->h)
{
imageRect->x = SCREEN_WIDTH - imageRect->w;
imageRect->y -= imageRect->h;
}
else
{
imageRect->y = SCREEN_HEIGHT - imageRect->h;
imageRect->x = SCREEN_WIDTH - imageRect->w;
}
}
}
void moveRightward(void)
{
if((imageRect->x + imageRect->w) < SCREEN_WIDTH)
{
imageRect->x += incrementer;
}
else
{
if((imageRect->y + imageRect->h) < SCREEN_HEIGHT)
{
imageRect->x = 0;
imageRect->y += imageRect->h;
}
else
{
imageRect->y = 0;
imageRect->x = 0;
}
}
}
bool LimitInitialiseAll(void)
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create renderer for window
screenRenderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
if( screenRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( screenRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_mage Error: %s\n", IMG_GetError() );
success = false;
}
else
{
//SDL_FillRect( screen, NULL, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
imageRect = new SDL_Rect;
imageRect->x = 0;
imageRect->y = 0;
imageRect->w = 20;
imageRect->h = 20;
}
}
}
}
return success;
}
/*
int LimitInitialiseAll(void)
{
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
return 0;
}
else
{
//Create window
window = SDL_CreateWindow( "Limit Moving Rect", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
cout << "Window could not be created! SDL_Error: " << SDL_GetError() << endl;
return 0;
}
else
{
//Get window surface
screen = SDL_GetWindowSurface( window );
if(screen == NULL)
{
cout << "Screen could not be generated ! SDL Error : " << SDL_GetError() << endl;
return 0;
}
else
{
SDL_FillRect( screen, NULL, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
imageRect = new SDL_Rect;
imageRect->x = 0;
imageRect->y = 0;
imageRect->w = 20;
imageRect->h = 20;
return 1;
}
}
}
}
*/
void LimitUpdateAll(void)
{
/*SDL_FillRect(screen, &screen->clip_imageRect, color);
SDL_FillRect(screen, imageRect, color2);
SDL_UpdateWindowSurface( window );*/
screenTexture->loadFromFile(RectOperations/prehistoric.png);//SDL_RenderCopy(screenRenderer, screenTexture, surfaceRect->clip_imageRect, surfaceRect->clip_imageRect);
screenTexture->render(0, 0, screen->clip_rect);
SDL_RenderCopy(screenRenderer, screenTexture, imageRect, screenImageRect);
SDL_RenderPresent(screenRenderer);
}
void loadImageToTexture(std::string pathImage)
{
}
void lineJumpRect(int* directVector)
{
bool running = true;
int yPositionRect = imageRect->y;
if(yPositionRect > imageRect->h)
{
(*directVector) = DIRECT_VECTOR_SURFACE_UP;
while(running)
{
changeDiimageRection(directVector);
if(imageRect->y == (yPositionRect - imageRect->h))
{
(*directVector) = DIRECT_VECTOR_SURFACE_DOWN;
}
else if(imageRect->y == yPositionRect)
{
running = false;
}
LimitUpdateAll();
SDL_Delay(5);
}
}
}
void inclinedJumpRect(int* directVector, char inclinePhase)
{
bool running = true;
int yPositionRect = imageRect->y;
int xPositionRect = imageRect->x;
bool UP = true;
if(yPositionRect > imageRect->h)
{
switch(inclinePhase)
{
case 'l':
{
while(running)
{
if(xPositionRect > (2*(imageRect->w)))
{
(*directVector) = DIRECT_VECTOR_SURFACE_LEFT;
changeDiimageRection(directVector);
LimitUpdateAll();
if((imageRect->x == (xPositionRect - (2*(imageRect->w)))))
{
running = false;
}
else if(!UP)
{
(*directVector) = DIRECT_VECTOR_SURFACE_DOWN;
changeDiimageRection(directVector);
LimitUpdateAll();
}
else
{
(*directVector) = DIRECT_VECTOR_SURFACE_UP;
changeDiimageRection(directVector);
LimitUpdateAll();
if(imageRect->y == (yPositionRect - imageRect->h))
{
UP = false;
}
}
SDL_Delay(5);
}
else
{
running = false;
}
}
}
break;
case 'r':
{
while(running)
{
if(xPositionRect < (SCREEN_WIDTH - (2*(imageRect->w))))
{
(*directVector) = DIRECT_VECTOR_SURFACE_RIGHT;
changeDiimageRection(directVector);
LimitUpdateAll();
if((imageRect->x == (xPositionRect + (2*(imageRect->w)))))
{
running = false;
}
else if(!UP)
{
(*directVector) = DIRECT_VECTOR_SURFACE_DOWN;
changeDiimageRection(directVector);
LimitUpdateAll();
}
else
{
(*directVector) = DIRECT_VECTOR_SURFACE_UP;
changeDiimageRection(directVector);
LimitUpdateAll();
if(imageRect->y == (yPositionRect - imageRect->h))
{
UP = false;
}
}
SDL_Delay(5);
}
else
{
running = false;
}
}
}
break;
}
}
}
int multiKeyPressHandler(void)
{
if((keyPressTable[KEY_PRESS_SURFACE_SPACE]) & (keyPressTable[KEY_PRESS_SURFACE_LEFT]) & !isDuck)
{
keyPressTable[KEY_PRESS_SURFACE_SPACE] = false;
keyPressTable[KEY_PRESS_SURFACE_LEFT] = false;
return DIRECT_VECTOR_SURFACE_JUMPL;
}
else if((keyPressTable[KEY_PRESS_SURFACE_SPACE]) & (keyPressTable[KEY_PRESS_SURFACE_RIGHT]) & !isDuck)
{
keyPressTable[KEY_PRESS_SURFACE_SPACE] = false;
keyPressTable[KEY_PRESS_SURFACE_RIGHT] = false;
return DIRECT_VECTOR_SURFACE_JUMPR;
}
else if((keyPressTable[KEY_PRESS_SURFACE_R]) & (motionFace == 'l') & isDuck)
{
keyPressTable[KEY_PRESS_SURFACE_R] = false;
return DIRECT_VECTOR_SURFACE_LROLL;
}
else if((keyPressTable[KEY_PRESS_SURFACE_R]) & (motionFace == 'r') & isDuck)
{
keyPressTable[KEY_PRESS_SURFACE_R] = false;
return DIRECT_VECTOR_SURFACE_RROLL;
}
else if(keyPressTable[KEY_PRESS_SURFACE_SPACE] & !isDuck)
{
keyPressTable[KEY_PRESS_SURFACE_SPACE] = false;
return DIRECT_VECTOR_SURFACE_JUMP;
}
else if(keyPressTable[KEY_PRESS_SURFACE_RCTRL])
{
keyPressTable[KEY_PRESS_SURFACE_RCTRL] = false;
return DIRECT_VECTOR_SURFACE_DUCK;
}
else if(keyPressTable[KEY_PRESS_SURFACE_LEFT])
{
keyPressTable[KEY_PRESS_SURFACE_LEFT] = false;
return DIRECT_VECTOR_SURFACE_LEFT;
}
else if(keyPressTable[KEY_PRESS_SURFACE_RIGHT])
{
keyPressTable[KEY_PRESS_SURFACE_RIGHT] = false;
return DIRECT_VECTOR_SURFACE_RIGHT;
}
else if(keyPressTable[KEY_PRESS_SURFACE_UP])
{
keyPressTable[KEY_PRESS_SURFACE_UP] = false;
return DIRECT_VECTOR_SURFACE_UP;
}
else if(keyPressTable[KEY_PRESS_SURFACE_DOWN])
{
//keyPressTable[KEY_PRESS_SURFACE_DOWN] = false;
return DIRECT_VECTOR_SURFACE_DOWN;
}
else
{
//keyPressTable[KEY_PRESS_SURFACE_DEFAULT] = false;
return DIRECT_VECTOR_SURFACE_DEFAULT;
}
}
void duckPositionRect(void)
{
if(!isDuck)
{
imageRect->y += ((imageRect->h)/2);
imageRect->h = ((imageRect->h)/2);
isDuck = true;
}
else
{
imageRect->y -= imageRect->h;
imageRect->h += imageRect->h;
isDuck = false;
}
}
void rollDuckedRect(char rollSide)
{
if(((imageRect->x + imageRect->w) <= (SCREEN_WIDTH - (2*(imageRect->w)))) && isDuck)
{
switch(rollSide)
{
case 'r':
{
imageRect->x = (imageRect->x + imageRect->w - imageRect->h);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x + imageRect->w);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x + imageRect->w - imageRect->h);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x + imageRect->w);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
}
break;
case 'l':
{
imageRect->x = (imageRect->x - imageRect->w + imageRect->h);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x - imageRect->w);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x - imageRect->w + imageRect->h);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
LimitUpdateAll();
SDL_Delay(10);
imageRect->x = (imageRect->x - imageRect->w);
imageRect->y = (imageRect->y + imageRect->h - imageRect->w);
imageRect->w += imageRect->h;
imageRect->h = imageRect->w - imageRect->h;
imageRect->w = imageRect->w - imageRect->h;
}
break;
}
}
}
void mapKeyStatToKeyTable(void)
{
if(keyStat[SDL_SCANCODE_UP] == 1)
keyPressTable[KEY_PRESS_SURFACE_UP] = true;
else if(keyStat[SDL_SCANCODE_UP] == 0)
keyPressTable[KEY_PRESS_SURFACE_UP] = false;
if(keyStat[SDL_SCANCODE_DOWN] == 1)
keyPressTable[KEY_PRESS_SURFACE_DOWN] = true;
else if(keyStat[SDL_SCANCODE_DOWN] == 0)
keyPressTable[KEY_PRESS_SURFACE_DOWN] = false;
if(keyStat[SDL_SCANCODE_LEFT] == 1)
{
keyPressTable[KEY_PRESS_SURFACE_LEFT] = true;
motionFace = 'l';
}
else if(keyStat[SDL_SCANCODE_LEFT] == 0)
keyPressTable[KEY_PRESS_SURFACE_LEFT] = false;
if(keyStat[SDL_SCANCODE_RIGHT] == 1)
{
keyPressTable[KEY_PRESS_SURFACE_RIGHT] = true;
motionFace = 'r';
}
else if(keyStat[SDL_SCANCODE_RIGHT] == 0)
keyPressTable[KEY_PRESS_SURFACE_RIGHT] = false;
if((keyStat[SDL_SCANCODE_R] == 1) & rollKeyDown)
{
keyPressTable[KEY_PRESS_SURFACE_R] = false;
rollKeyDown = false;
}
else if((keyStat[SDL_SCANCODE_R] == 0) & !rollKeyDown)
{
keyPressTable[KEY_PRESS_SURFACE_R] = true;
rollKeyDown = true;
}
if(keyStat[SDL_SCANCODE_SPACE] == 1)
keyPressTable[KEY_PRESS_SURFACE_SPACE] = true;
else if(keyStat[SDL_SCANCODE_SPACE] == 0)
keyPressTable[KEY_PRESS_SURFACE_SPACE] = false;
if((keyStat[SDL_SCANCODE_RCTRL] == 1))
{
keyPressTable[KEY_PRESS_SURFACE_RCTRL] = false;
duckKeyDown = true;
}
else if((keyStat[SDL_SCANCODE_RCTRL] == 0) & duckKeyDown)
{
keyPressTable[KEY_PRESS_SURFACE_RCTRL] = true;
duckKeyDown = false;
}
}