forked from littlebalup/Zelda3T
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bouclier.cpp
105 lines (91 loc) · 2.6 KB
/
Bouclier.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
/*
Zelda Time to Triumph
Copyright (C) 2007-2009 Vincent Jouillat
Please send bugreports with examples or suggestions to www.zeldaroth.fr
*/
#include "Bouclier.h"
#include "Common.h"
Bouclier::Bouclier(SDL_Surface* img, int id) : image(img), type(id) {
SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(image->format,0,0,255));
zone = NULL;
}
Bouclier::~Bouclier() {
if (image != NULL) {
SDL_FreeSurface(image);
}
if (zone != NULL) {
delete zone;
}
}
void Bouclier::draw(SDL_Surface* screen, int x, int y, ZoneRect* z, int direction) {
setZone(z);
if (type == 2) {
switch (direction) {
case N :
zone->getZone()->x--; zone->getZone()->y-=2;
zone->getZone()->w+=3; zone->getZone()->h+=2;
break;
case S :
zone->getZone()->x-=2; zone->getZone()->y-=2;
zone->getZone()->w+=3; zone->getZone()->h+=2;
x+=3;
break;
case O :
case E :
x+=6;
zone->getZone()->y--; zone->getZone()->h+=2;
break;
}
}
if (type == 3 || type == 4) {
switch (direction) {
case N :
zone->getZone()->x-=2; zone->getZone()->y-=4;
zone->getZone()->w+=5; zone->getZone()->h+=5;
break;
case S :
zone->getZone()->x-=3; zone->getZone()->y-=4;
zone->getZone()->w+=5; zone->getZone()->h+=5;
x+=5;
break;
case O :
case E :
x+=10;
zone->getZone()->y--; zone->getZone()->h+=4;
break;
}
}
if (type == 10) {
switch (direction) {
case N :
zone->getZone()->x--;
zone->getZone()->w+=2; zone->getZone()->h++;
break;
case S :
zone->getZone()->x--; zone->getZone()->y--;
zone->getZone()->w+=2; zone->getZone()->h++;
x+=2;
break;
case O :
case E :
x+=4;
zone->getZone()->h++;
break;
}
}
SDL_Rect src;
src.x = x;
src.y = y;
src.w = zone->getZone()->w;
src.h = zone->getZone()->h;
SDL_Rect dst;
dst.x = zone->getZone()->x;
dst.y = zone->getZone()->y;
SDL_BlitSurface(image, &src, screen, &dst);
}
void Bouclier::setZone(ZoneRect* z) {
if (zone != NULL) {
delete zone;
}
zone = z;
}