- [x] Gestion direction collision en fonction des verifs de collide()

This commit is contained in:
xdrm-brackets 2016-03-17 23:18:52 +01:00
parent 09cc1952f1
commit f6e8d0ec23
14 changed files with 364 additions and 402 deletions

View File

@ -1,345 +1,382 @@
WINDOW CREATED
RENDERER CREATED
INDEX: grass10 AT 0
(-32,576) -> (32, 32)
(-32,512) -> (32, 32)
INDEX: grass11 AT 1
(0,576) -> (32, 32)
(0,512) -> (32, 32)
INDEX: grass12 AT 2
(32,576) -> (32, 32)
(32,512) -> (32, 32)
INDEX: grass13 AT 3
(64,576) -> (32, 32)
(64,512) -> (32, 32)
INDEX: grass14 AT 4
(96,576) -> (32, 32)
(96,512) -> (32, 32)
INDEX: grass15 AT 5
(128,576) -> (32, 32)
(128,512) -> (32, 32)
INDEX: grass16 AT 6
(160,576) -> (32, 32)
(160,512) -> (32, 32)
INDEX: grass17 AT 7
(192,576) -> (32, 32)
(192,512) -> (32, 32)
INDEX: grass18 AT 8
(224,576) -> (32, 32)
(224,512) -> (32, 32)
INDEX: grass19 AT 9
(256,576) -> (32, 32)
(256,512) -> (32, 32)
INDEX: grass110 AT 10
(288,576) -> (32, 32)
(288,512) -> (32, 32)
INDEX: grass111 AT 11
(320,576) -> (32, 32)
(320,512) -> (32, 32)
INDEX: grass112 AT 12
(352,576) -> (32, 32)
(352,512) -> (32, 32)
INDEX: grass113 AT 13
(384,576) -> (32, 32)
(384,512) -> (32, 32)
INDEX: grass114 AT 14
(416,576) -> (32, 32)
(416,512) -> (32, 32)
INDEX: grass115 AT 15
(448,576) -> (32, 32)
(448,512) -> (32, 32)
INDEX: grass116 AT 16
(480,576) -> (32, 32)
(480,512) -> (32, 32)
INDEX: grass117 AT 17
(512,576) -> (32, 32)
(512,512) -> (32, 32)
INDEX: grass118 AT 18
(544,576) -> (32, 32)
(544,512) -> (32, 32)
INDEX: grass119 AT 19
(576,576) -> (32, 32)
(576,512) -> (32, 32)
INDEX: grass120 AT 20
(608,576) -> (32, 32)
(608,512) -> (32, 32)
INDEX: grass121 AT 21
(640,576) -> (32, 32)
(640,512) -> (32, 32)
INDEX: grass122 AT 22
(672,576) -> (32, 32)
(672,512) -> (32, 32)
INDEX: grass123 AT 23
(704,576) -> (32, 32)
(704,512) -> (32, 32)
INDEX: grass124 AT 24
(736,576) -> (32, 32)
(736,512) -> (32, 32)
INDEX: grass125 AT 25
(768,576) -> (32, 32)
(768,512) -> (32, 32)
INDEX: grass126 AT 26
(800,576) -> (32, 32)
(800,512) -> (32, 32)
INDEX: grass127 AT 27
(832,576) -> (32, 32)
(832,512) -> (32, 32)
INDEX: grass128 AT 28
(864,576) -> (32, 32)
(864,512) -> (32, 32)
INDEX: grass129 AT 29
(896,576) -> (32, 32)
(896,512) -> (32, 32)
INDEX: grass130 AT 30
(928,576) -> (32, 32)
(928,512) -> (32, 32)
INDEX: grass131 AT 31
(960,576) -> (32, 32)
(960,512) -> (32, 32)
INDEX: grass132 AT 32
(992,576) -> (32, 32)
(992,512) -> (32, 32)
INDEX: grass133 AT 33
(1024,576) -> (32, 32)
(1024,512) -> (32, 32)
INDEX: grass134 AT 34
(-32,608) -> (32, 32)
(-32,544) -> (32, 32)
INDEX: grass135 AT 35
(0,608) -> (32, 32)
(0,544) -> (32, 32)
INDEX: grass136 AT 36
(32,608) -> (32, 32)
(32,544) -> (32, 32)
INDEX: grass137 AT 37
(64,608) -> (32, 32)
(64,544) -> (32, 32)
INDEX: grass138 AT 38
(96,608) -> (32, 32)
(96,544) -> (32, 32)
INDEX: grass139 AT 39
(128,608) -> (32, 32)
(128,544) -> (32, 32)
INDEX: grass140 AT 40
(160,608) -> (32, 32)
(160,544) -> (32, 32)
INDEX: grass141 AT 41
(192,608) -> (32, 32)
(192,544) -> (32, 32)
INDEX: grass142 AT 42
(224,608) -> (32, 32)
(224,544) -> (32, 32)
INDEX: grass143 AT 43
(256,608) -> (32, 32)
(256,544) -> (32, 32)
INDEX: grass144 AT 44
(288,608) -> (32, 32)
(288,544) -> (32, 32)
INDEX: grass145 AT 45
(320,608) -> (32, 32)
(320,544) -> (32, 32)
INDEX: grass146 AT 46
(352,608) -> (32, 32)
(352,544) -> (32, 32)
INDEX: grass147 AT 47
(384,608) -> (32, 32)
(384,544) -> (32, 32)
INDEX: grass148 AT 48
(416,608) -> (32, 32)
(416,544) -> (32, 32)
INDEX: grass149 AT 49
(448,608) -> (32, 32)
(448,544) -> (32, 32)
INDEX: grass150 AT 50
(480,608) -> (32, 32)
(480,544) -> (32, 32)
INDEX: grass151 AT 51
(512,608) -> (32, 32)
(512,544) -> (32, 32)
INDEX: grass152 AT 52
(544,608) -> (32, 32)
(544,544) -> (32, 32)
INDEX: grass153 AT 53
(576,608) -> (32, 32)
(576,544) -> (32, 32)
INDEX: grass154 AT 54
(608,608) -> (32, 32)
(608,544) -> (32, 32)
INDEX: grass155 AT 55
(640,608) -> (32, 32)
(640,544) -> (32, 32)
INDEX: grass156 AT 56
(672,608) -> (32, 32)
(672,544) -> (32, 32)
INDEX: grass157 AT 57
(704,608) -> (32, 32)
(704,544) -> (32, 32)
INDEX: grass158 AT 58
(736,608) -> (32, 32)
(736,544) -> (32, 32)
INDEX: grass159 AT 59
(768,608) -> (32, 32)
(768,544) -> (32, 32)
INDEX: grass160 AT 60
(800,608) -> (32, 32)
(800,544) -> (32, 32)
INDEX: grass161 AT 61
(832,608) -> (32, 32)
(832,544) -> (32, 32)
INDEX: grass162 AT 62
(864,608) -> (32, 32)
(864,544) -> (32, 32)
INDEX: grass163 AT 63
(896,608) -> (32, 32)
(896,544) -> (32, 32)
INDEX: grass164 AT 64
(928,608) -> (32, 32)
(928,544) -> (32, 32)
INDEX: grass165 AT 65
(960,608) -> (32, 32)
(960,544) -> (32, 32)
INDEX: grass166 AT 66
(992,608) -> (32, 32)
(992,544) -> (32, 32)
INDEX: grass167 AT 67
(1024,608) -> (32, 32)
(1024,544) -> (32, 32)
INDEX: grass168 AT 68
(-32,640) -> (32, 32)
(-32,576) -> (32, 32)
INDEX: grass169 AT 69
(0,640) -> (32, 32)
(0,576) -> (32, 32)
INDEX: grass170 AT 70
(32,640) -> (32, 32)
(32,576) -> (32, 32)
INDEX: grass171 AT 71
(64,640) -> (32, 32)
(64,576) -> (32, 32)
INDEX: grass172 AT 72
(96,640) -> (32, 32)
(96,576) -> (32, 32)
INDEX: grass173 AT 73
(128,640) -> (32, 32)
(128,576) -> (32, 32)
INDEX: grass174 AT 74
(160,640) -> (32, 32)
(160,576) -> (32, 32)
INDEX: grass175 AT 75
(192,640) -> (32, 32)
(192,576) -> (32, 32)
INDEX: grass176 AT 76
(224,640) -> (32, 32)
(224,576) -> (32, 32)
INDEX: grass177 AT 77
(256,640) -> (32, 32)
(256,576) -> (32, 32)
INDEX: grass178 AT 78
(288,640) -> (32, 32)
(288,576) -> (32, 32)
INDEX: grass179 AT 79
(320,640) -> (32, 32)
(320,576) -> (32, 32)
INDEX: grass180 AT 80
(352,640) -> (32, 32)
(352,576) -> (32, 32)
INDEX: grass181 AT 81
(384,640) -> (32, 32)
INDEX: grass182 AT 82
(416,640) -> (32, 32)
INDEX: grass183 AT 83
(448,640) -> (32, 32)
INDEX: grass184 AT 84
(480,640) -> (32, 32)
INDEX: grass185 AT 85
(512,640) -> (32, 32)
INDEX: grass186 AT 86
(544,640) -> (32, 32)
INDEX: grass187 AT 87
(576,640) -> (32, 32)
INDEX: grass188 AT 88
(608,640) -> (32, 32)
INDEX: grass189 AT 89
(640,640) -> (32, 32)
INDEX: grass190 AT 90
(672,640) -> (32, 32)
INDEX: grass191 AT 91
(704,640) -> (32, 32)
INDEX: grass192 AT 92
(736,640) -> (32, 32)
INDEX: grass193 AT 93
(768,640) -> (32, 32)
INDEX: grass194 AT 94
(800,640) -> (32, 32)
INDEX: grass195 AT 95
(832,640) -> (32, 32)
INDEX: grass196 AT 96
(864,640) -> (32, 32)
INDEX: grass197 AT 97
(896,640) -> (32, 32)
INDEX: grass198 AT 98
(928,640) -> (32, 32)
INDEX: grass199 AT 99
(960,640) -> (32, 32)
INDEX: grass1100 AT 100
(992,640) -> (32, 32)
INDEX: grass1101 AT 101
(1024,640) -> (32, 32)
INDEX: bottom-center0 AT 102
(384,576) -> (32, 32)
INDEX: bottom-center1 AT 103
INDEX: grass182 AT 82
(416,576) -> (32, 32)
INDEX: bottom-center2 AT 104
INDEX: grass183 AT 83
(448,576) -> (32, 32)
INDEX: bottom-center3 AT 105
INDEX: grass184 AT 84
(480,576) -> (32, 32)
INDEX: bottom-center4 AT 106
INDEX: grass185 AT 85
(512,576) -> (32, 32)
INDEX: bottom-center5 AT 107
INDEX: grass186 AT 86
(544,576) -> (32, 32)
INDEX: bottom-center6 AT 108
INDEX: grass187 AT 87
(576,576) -> (32, 32)
INDEX: bottom-center7 AT 109
INDEX: grass188 AT 88
(608,576) -> (32, 32)
INDEX: bottom-center8 AT 110
INDEX: grass189 AT 89
(640,576) -> (32, 32)
INDEX: bottom-center9 AT 111
INDEX: grass190 AT 90
(672,576) -> (32, 32)
INDEX: bottom-center10 AT 112
INDEX: grass191 AT 91
(704,576) -> (32, 32)
INDEX: grass192 AT 92
(736,576) -> (32, 32)
INDEX: grass193 AT 93
(768,576) -> (32, 32)
INDEX: grass194 AT 94
(800,576) -> (32, 32)
INDEX: grass195 AT 95
(832,576) -> (32, 32)
INDEX: grass196 AT 96
(864,576) -> (32, 32)
INDEX: grass197 AT 97
(896,576) -> (32, 32)
INDEX: grass198 AT 98
(928,576) -> (32, 32)
INDEX: grass199 AT 99
(960,576) -> (32, 32)
INDEX: grass1100 AT 100
(992,576) -> (32, 32)
INDEX: grass1101 AT 101
(1024,576) -> (32, 32)
INDEX: grass1102 AT 102
(-32,608) -> (32, 32)
INDEX: grass1103 AT 103
(0,608) -> (32, 32)
INDEX: grass1104 AT 104
(32,608) -> (32, 32)
INDEX: grass1105 AT 105
(64,608) -> (32, 32)
INDEX: grass1106 AT 106
(96,608) -> (32, 32)
INDEX: grass1107 AT 107
(128,608) -> (32, 32)
INDEX: grass1108 AT 108
(160,608) -> (32, 32)
INDEX: grass1109 AT 109
(192,608) -> (32, 32)
INDEX: grass1110 AT 110
(224,608) -> (32, 32)
INDEX: grass1111 AT 111
(256,608) -> (32, 32)
INDEX: grass1112 AT 112
(288,608) -> (32, 32)
INDEX: grass1113 AT 113
(320,608) -> (32, 32)
INDEX: grass1114 AT 114
(352,608) -> (32, 32)
INDEX: grass1115 AT 115
(384,608) -> (32, 32)
INDEX: bottom-center11 AT 113
INDEX: grass1116 AT 116
(416,608) -> (32, 32)
INDEX: bottom-center12 AT 114
INDEX: grass1117 AT 117
(448,608) -> (32, 32)
INDEX: bottom-center13 AT 115
INDEX: grass1118 AT 118
(480,608) -> (32, 32)
INDEX: bottom-center14 AT 116
INDEX: grass1119 AT 119
(512,608) -> (32, 32)
INDEX: bottom-center15 AT 117
INDEX: grass1120 AT 120
(544,608) -> (32, 32)
INDEX: bottom-center16 AT 118
INDEX: grass1121 AT 121
(576,608) -> (32, 32)
INDEX: bottom-center17 AT 119
INDEX: grass1122 AT 122
(608,608) -> (32, 32)
INDEX: bottom-center18 AT 120
INDEX: grass1123 AT 123
(640,608) -> (32, 32)
INDEX: bottom-center19 AT 121
INDEX: grass1124 AT 124
(672,608) -> (32, 32)
INDEX: bottom-center20 AT 122
INDEX: grass1125 AT 125
(704,608) -> (32, 32)
INDEX: grass1126 AT 126
(736,608) -> (32, 32)
INDEX: grass1127 AT 127
(768,608) -> (32, 32)
INDEX: grass1128 AT 128
(800,608) -> (32, 32)
INDEX: grass1129 AT 129
(832,608) -> (32, 32)
INDEX: grass1130 AT 130
(864,608) -> (32, 32)
INDEX: grass1131 AT 131
(896,608) -> (32, 32)
INDEX: grass1132 AT 132
(928,608) -> (32, 32)
INDEX: grass1133 AT 133
(960,608) -> (32, 32)
INDEX: grass1134 AT 134
(992,608) -> (32, 32)
INDEX: grass1135 AT 135
(1024,608) -> (32, 32)
INDEX: grass1136 AT 136
(-32,640) -> (32, 32)
INDEX: grass1137 AT 137
(0,640) -> (32, 32)
INDEX: grass1138 AT 138
(32,640) -> (32, 32)
INDEX: grass1139 AT 139
(64,640) -> (32, 32)
INDEX: grass1140 AT 140
(96,640) -> (32, 32)
INDEX: grass1141 AT 141
(128,640) -> (32, 32)
INDEX: grass1142 AT 142
(160,640) -> (32, 32)
INDEX: grass1143 AT 143
(192,640) -> (32, 32)
INDEX: grass1144 AT 144
(224,640) -> (32, 32)
INDEX: grass1145 AT 145
(256,640) -> (32, 32)
INDEX: grass1146 AT 146
(288,640) -> (32, 32)
INDEX: grass1147 AT 147
(320,640) -> (32, 32)
INDEX: grass1148 AT 148
(352,640) -> (32, 32)
INDEX: grass1149 AT 149
(384,640) -> (32, 32)
INDEX: bottom-center21 AT 123
INDEX: grass1150 AT 150
(416,640) -> (32, 32)
INDEX: bottom-center22 AT 124
INDEX: grass1151 AT 151
(448,640) -> (32, 32)
INDEX: bottom-center23 AT 125
INDEX: grass1152 AT 152
(480,640) -> (32, 32)
INDEX: bottom-center24 AT 126
INDEX: grass1153 AT 153
(512,640) -> (32, 32)
INDEX: bottom-center25 AT 127
INDEX: grass1154 AT 154
(544,640) -> (32, 32)
INDEX: bottom-center26 AT 128
INDEX: grass1155 AT 155
(576,640) -> (32, 32)
INDEX: bottom-center27 AT 129
INDEX: grass1156 AT 156
(608,640) -> (32, 32)
INDEX: bottom-center28 AT 130
INDEX: grass1157 AT 157
(640,640) -> (32, 32)
INDEX: bottom-center29 AT 131
INDEX: grass1158 AT 158
(672,640) -> (32, 32)
INDEX: green-sheel AT 132
(163,553) -> (25, 22)
INDEX: brick AT 133
(128,448) -> (32, 32)
INDEX: mystery-bloc AT 134
(160,448) -> (32, 32)
INDEX: mario AT 135
(547,544) -> (25, 32)
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
Grass collided with Mario from bottom
INDEX: grass1159 AT 159
(704,640) -> (32, 32)
INDEX: grass1160 AT 160
(736,640) -> (32, 32)
INDEX: grass1161 AT 161
(768,640) -> (32, 32)
INDEX: grass1162 AT 162
(800,640) -> (32, 32)
INDEX: grass1163 AT 163
(832,640) -> (32, 32)
INDEX: grass1164 AT 164
(864,640) -> (32, 32)
INDEX: grass1165 AT 165
(896,640) -> (32, 32)
INDEX: grass1166 AT 166
(928,640) -> (32, 32)
INDEX: grass1167 AT 167
(960,640) -> (32, 32)
INDEX: grass1168 AT 168
(992,640) -> (32, 32)
INDEX: grass1169 AT 169
(1024,640) -> (32, 32)
INDEX: bloc10 AT 170
(320,448) -> (32, 32)
INDEX: bloc11 AT 171
(352,448) -> (32, 32)
INDEX: bloc12 AT 172
(384,448) -> (32, 32)
INDEX: bloc13 AT 173
(416,448) -> (32, 32)
INDEX: bloc14 AT 174
(448,448) -> (32, 32)
INDEX: bloc15 AT 175
(480,448) -> (32, 32)
INDEX: bloc16 AT 176
(512,448) -> (32, 32)
INDEX: bloc17 AT 177
(544,448) -> (32, 32)
INDEX: bloc18 AT 178
(576,448) -> (32, 32)
INDEX: bloc19 AT 179
(608,448) -> (32, 32)
INDEX: bloc110 AT 180
(640,448) -> (32, 32)
INDEX: bloc111 AT 181
(672,448) -> (32, 32)
INDEX: bloc112 AT 182
(704,448) -> (32, 32)
INDEX: bloc113 AT 183
(736,448) -> (32, 32)
INDEX: bloc20 AT 184
(736,416) -> (32, 32)
INDEX: green-sheel AT 185
(387,361) -> (25, 22)
INDEX: brick AT 186
(96,416) -> (32, 32)
INDEX: brick2 AT 187
(320,416) -> (32, 32)
INDEX: mystery-bloc AT 188
(160,416) -> (32, 32)
INDEX: mario AT 189
(547,416) -> (25, 32)

BIN
SDL#4/exe

Binary file not shown.

View File

@ -31,28 +31,34 @@ int main(int argc, char* argv[]) {
/* [2] On definit le terrain
=========================================================*/
// On cree un bout du terrain
xMarioGrass g1(mgr, (SDL_Rect){-1, 20-2, 32+2, 3} );
xMarioGrass g1(mgr, (SDL_Rect){-1, 20-4, 32+2, 5} );
g1.push("grass1");
// On cree un bout du terrain
xMarioGrass btmcenter(mgr, (SDL_Rect){12, 20-2, 10, 3} );
btmcenter.push("bottom-center");
xMarioBloc b1(mgr, (SDL_Rect){10, 20-6, 14, 1});
b1.push("bloc1");
xMarioBloc b2(mgr, (SDL_Rect){23, 20-7, 1, 1});
b2.push("bloc2");
/* [3] Gestion des blocs
=========================================================*/
// On cree une coquille verte
xMarioGreenShell gs(mgr, 5, 20-3);
xMarioGreenShell gs(mgr, 20-8, 20-9);
gs.push("green-sheel");
gs.start(80, SPRITE_ANIM_INFINITE);
// On cree une brique
xMarioBrick mBrick(mgr, 4, 20-6, 10); // 10 sauts
xMarioBrick mBrick(mgr, 3, 20-7, 10); // 10 sauts
mBrick.push("brick");
xMarioBrick mBrick2(mgr, 10, 20-7, 5); // 5 sauts
mBrick2.push("brick2");
// On cree un bloc mystere
xMarioMysteryBloc mMystery(mgr, 5, 20-6, 2); // 2 sauts
xMarioMysteryBloc mMystery(mgr, 5, 20-7, 2); // 2 sauts
mMystery.push("mystery-bloc");
mMystery.start(150, SPRITE_ANIM_INFINITE);
@ -60,7 +66,7 @@ int main(int argc, char* argv[]) {
// On cree mario
mario = new xMarioMario(mgr, 17, 20-3);
mario = new xMarioMario(mgr, 17, 20-7);
mario->push("mario");
mario->start(100, SPRITE_ANIM_INFINITE);

Binary file not shown.

View File

@ -1,16 +1,19 @@
A FAIRE
=======
- [ ] Verifier toute la trajectoire pour move()
- [x][ ] Gestion du saut unique ou double (limitation)
- [ ] Gestion du terrain (grass, bloc) sous forme de tableau de points (polygone)
EN COURS
========
- [ ] Verifier toute la trajectoire pour move()
- [x] Refaire texture xGreenShell
- [ ] Gestion arret animation + reprise (switch)
- [ ] Gestion du deplacement xGreenShell
FAIT
====
- [x] Gestion direction collision en fonction des verifs de collide()
- [x] Erreur saut infini mario
- [x] Erreur -> Gestion params velocite en fonction taille bloc

View File

@ -96,8 +96,12 @@ void xMarioBreakableBloc::active(bool active){
/* [ONCOLLIDE] Gestion des collisions
=========================================================*/
void xMarioBreakableBloc::onCollide(vector<int> from, xSprite* by){
void xMarioBreakableBloc::onCollide(vector<bool> from, xSprite* by){
/* (1) Saut de mario */
if( by->getType() == "Mario" && from[1] == -1 )
if( by->getType() == "Mario" && from[3] )
this->jump();
/* (2) Collision laterale par objet mobile */
if( by->getType() == "green-shell" && (from[0]||from[1]) )
this->jump();
}

View File

@ -8,7 +8,7 @@
xMarioBreakableBloc(xManager *manager, const char *url, int x, int y, int nb=1); // Spritesheet avec taille de chaque sprite
// Surcharge parent
void onCollide(vector<int> from, xSprite* by);
void onCollide(vector<bool> from, xSprite* by);
void jump(); // Effectue l'animation d'activation (debut/saut)

View File

@ -14,6 +14,7 @@ xMarioBloc::xMarioBloc(xManager *m, SDL_Rect rect){
/* (1) On charge la texture */
_spritesheet = IMG_LoadTexture(_manager->renderer(), "src/blocs.png");
// Evite de la dupliquer, uniquement des pointeurs
int index = 0;
@ -24,6 +25,9 @@ xMarioBloc::xMarioBloc(xManager *m, SDL_Rect rect){
// On cree une copie du spritesheet
this->add( new xSprite(_manager, _spritesheet) );
// On definit le tyoe
_sprites[index]->setType("Bloc");
this->get(index)->dimensions(
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE},
(SDL_Rect){0, 153, 16, 16}

View File

@ -14,7 +14,7 @@ xMarioGrass::xMarioGrass(xManager *m, SDL_Rect rect){
/* (1) On charge la texture */
_spritesheet = IMG_LoadTexture(_manager->renderer(), "src/ground.png");
// Evite de la dupliquer, uniquement des pointeurs
int index = 0;

View File

@ -53,13 +53,12 @@ xMarioMario::xMarioMario(xManager *m, int x, int y)
void xMarioMario::moveFromVelocity(){
/* (1) Si aucune collision, on deplace */
vector<int> after;
after = this->move(_velocity[0], _velocity[1]);
vector<int> after = this->move(_velocity[0], _velocity[1]);
/* (2) On modifie la velocite en fonction des collisions */
_velocity[0] = (double) after[2];
_velocity[1] = (double) after[3];
_velocity[0] = (double) after[0];
_velocity[1] = (double) after[1];
/* (3) Modification du sprite en fonction du mouvement */

View File

@ -82,7 +82,6 @@ SDL_Renderer* xManager::renderer(){ return _renderer; }
bool xManager::setBackground(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
if( !this->status() ) return false;
SDL_SetRenderDrawColor( _renderer, r, g, b, a );
return true;
@ -103,96 +102,39 @@ bool xManager::setImage(const char *url){
/* [HIT] Retourne si une texture est en collision avec une autre
=========================================================*/
// bool xManager::hit(SDL_Texture *current, int movex, int movey){
// // Anti conflit inter-thread
// _mutex_hit.try_lock();
// /* (1) On recupere le SDL_Rect destination du sprite courant */
// int xIndex = -1;
// for( int i = 0 ; i < _sprites.size() ; i++ )
// if( _sprites[i] == current )
// xIndex = i;
// if( xIndex == -1 ){
// _mutex_hit.unlock();
// return false;
// }
// SDL_Rect a = (SDL_Rect){
// (*_dst[xIndex]).x+movex,
// (*_dst[xIndex]).y+movey,
// (*_dst[xIndex]).w,
// (*_dst[xIndex]).h
// };
// SDL_Rect b;
// /* (2) On regarde si en dehors de la fenetre */
// for( int y = a.y ; y < a.y+a.h ; y++ )
// for( int x = a.x ; x < a.x+a.w ; x++ )
// if( x < _winrect.x || x > _winrect.x+_winrect.w || y < _winrect.y || y>_winrect.y+_winrect.h ){
// // On debloque la ressource
// _mutex_hit.unlock();
// return true;
// }
// /* (3) On compare avec toutes les autres textures */
// for( int i = 0 ; i < _sprites.size() ; i++ ){
// // Si c'est pas le sprite courant
// if( _sprites[i] != current ){
// // taille du sprite en cours
// b.x = (*_dst[i]).x;
// b.y = (*_dst[i]).y;
// b.w = (*_dst[i]).w;
// b.h = (*_dst[i]).h;
// for( int y = a.y ; y < a.y+a.h ; y++ )
// for( int x = a.x ; x < a.x+a.w ; x++ )
// if( x>=b.x && x<=b.x+b.w && y>=b.y && y<=b.y+b.h ){
// // On debloque la ressource
// _mutex_hit.unlock();
// return true;
// }
// }
// }
// // On debloque la ressource
// _mutex_hit.unlock();
// return false;
// }
/* [COLLIDE] Retourne si 2 objets sont en collision
=========================================================*/
bool xManager::collide(SDL_Rect a, SDL_Rect b){
// collisions <vector<bool>*>
// [0] -> VRAI si collision a droite
// [1] -> VRAI si collision a gauche
// [2] -> VRAI si collision en haut
// [3] -> VRAI si collision en bas
bool xManager::collide(SDL_Rect a, SDL_Rect b, vector<bool>& cols){
if( !this->status() ) return true;
bool notCollide =
(a.x >= b.x+b.w ) // Inclus a droite
|| (a.x+a.w <= b.x ) // Inclus a gauche
|| (a.y >= b.y+b.h ) // Inclus en haut
|| (a.y+a.h <= b.y ); // Inclus en bas
// Verification de collisions
bool outLeft = (a.x >= b.x+b.w ); // Trop a droite
bool outRight = (a.x+a.w <= b.x ); // Trop a gauche
bool outUp = (a.y >= b.y+b.h ); // Trop en haut
bool outDown = (a.y+a.h <= b.y ); // Trop en bas
// bool collide = (
// ( ( a.x > b.x && a.x < b.x+b.w )
// || ( a.x+a.w > b.x && a.x+a.w < b.x+b.w ) )
// &&
// ( ( a.y > b.y && a.y < b.y+b.h )
// || ( a.y+a.h > b.y && a.y+a.h < b.y+b.h ) )
// );
return !notCollide;
// Calcule du bord en question
int distLeft = abs( (a.x+a.w) - b.x );
int distRight = abs( a.x - (b.x+b.w) );
int distBottom = abs( a.y - (b.y+b.h) );
int distTop = abs( (a.y+a.h) - b.y );
// Valeurs de retour pointeur
cols[0] = !outRight && distRight <= 1; // plus proche de droite
cols[1] = !outLeft && distLeft <= 2; // plus proche de gauche
cols[2] = !outUp && distTop <= 2; // plus proche du haut
cols[3] = !outDown && distBottom <= 1; // plus proche du bas
// On retourne si il y a collision ou pas
return !( outRight || outLeft || outUp || outDown );
}
@ -228,13 +170,9 @@ bool xManager::hit(xSprite* current, int movex, int movey){
a.y += movey;
// Contiendra le sens de collision
vector<int> collideFrom;
collideFrom.push_back( (movex!=0) ? (int)( movex / abs(movex) ) : 0 );
collideFrom.push_back( (movey!=0) ? (int)( movey / abs(movey) ) : 0 );
vector<int> collideTo;
collideTo.push_back( -collideFrom[0] );
collideTo.push_back( -collideFrom[1] );
vector<bool> collideFrom(4, false);
// Contiendra le sens de collision
vector<bool> collideTo(4, false);
/* (2) On regarde si en dehors de la fenetre */
@ -260,12 +198,19 @@ bool xManager::hit(xSprite* current, int movex, int movey){
if( _sprites[i] != current ){
// On verifie que le sprite n'entre pas en collision
if( this->collide(a, *(_sprites[i])->dst()) ){
if( this->collide(a, *(_sprites[i])->dst(), collideTo) ){
// On recupere la surface en collision inverse
collideFrom[0] = collideTo[1]; // On inverse Droite
collideFrom[1] = collideTo[0]; // et Gauche
collideFrom[2] = collideTo[3]; // On inverse Haut
collideFrom[3] = collideTo[2]; // et Bas
// On lance les listeners de collision
_sprites[i]->onCollide(collideFrom, current);
current->onCollide(collideTo, _sprites[i]);
_sprites[i]->onCollide(collideTo, current);
current->onCollide(collideFrom, _sprites[i]);
_debug = *(_sprites[i])->dst();
@ -285,6 +230,8 @@ bool xManager::hit(xSprite* current, int movex, int movey){
}
/* [HIT] Retourne si une texture est en collision avec une autre
=========================================================*/
bool xManager::hit(string current, int movex, int movey){

View File

@ -13,7 +13,7 @@
bool setImage(const char *url);
bool collide(SDL_Rect a, SDL_Rect b); // Collision entre 2 SDL_Rect
bool collide(SDL_Rect a, SDL_Rect b, vector<bool>& cols); // Collision entre 2 SDL_Rect
bool hit(xSprite *current, int movex=0, int movey=0); // Gestion des collisions
bool hit(string current, int movex=0, int movey=0); // Gestion des collisions

View File

@ -128,57 +128,18 @@ void xSprite::setTexture(SDL_Texture *t){
return;
}
/* [MOVE] Modification de la position/taille du sprite
=========================================================*/
vector<int> xSprite::move(SDL_Rect newpos){
vector<int> result;
if( !_manager->hit(this, newpos.x, newpos.y) ){
if( newpos.x != 0 )
_dst.x = newpos.x;
if( newpos.y != 0 )
_dst.y = newpos.y;
if( newpos.w != 0 )
_dst.w = newpos.w;
if( newpos.h != 0)
_dst.h = newpos.h;
}
result.push_back( newpos.x );
result.push_back( newpos.y );
result.push_back( newpos.w );
result.push_back( newpos.h );
return result;
}
/* [MOVE] Deplacement de la position/taille du sprite
=========================================================*/
// renvoie un tableau d'au moins 4 entiers
// 1 -> -1 ou 1 en fonction de la direction de la collision sur x
// 2 -> -1 ou 1 en fonction de la direction de la collision sur y
// 3 -> le deplacement effectif sur x
// 4 -> le deplacement effectif sur y
// @return -> tableau de 2 entiers
// 0 -> le deplacement effectif sur x
// 1 -> le deplacement effectif sur y
//
vector<int> xSprite::move(int x, int y){
// Protection inter-thread
_mutex_move.try_lock();
vector<int> result;
result.push_back( (x!=0) ? (int)( x / abs(x) ) : 0 );
result.push_back( (y!=0) ? (int)( y / abs(y) ) : 0 );
result.push_back(0);
result.push_back(0);
vector<int> result(2, 0);
/* (1) Variables utiles */
@ -192,9 +153,8 @@ vector<int> xSprite::move(int x, int y){
/* (2) Tant qu'on peut bouger (ni x ni y ne vaut 0) */
while( incrx!=0 || incry!=0 ){
result[2] = incrx;
result[3] = incry;
result[0] = incrx;
result[1] = incry;
/* (3) Si on peut aller a la destination */
if( !_manager->hit(this, incrx, incry) ){
@ -203,8 +163,8 @@ vector<int> xSprite::move(int x, int y){
// cerr << ">>> not locked <<<" << endl;
result[2] = incrx;
result[3] = incry;
result[0] = incrx;
result[1] = incry;
_mutex_move.unlock();
return result;
@ -241,21 +201,24 @@ vector<int> xSprite::move(int x, int y){
}
/* [ONCOLLIDE] Action en cas de collision
=========================================================*/
void xSprite::onCollide(vector<int> from, xSprite* by){
void xSprite::onCollide(vector<bool> from, xSprite* by){
if( from[0] == 0 && from[1] == 0 )
return;
// if( from[0] == 0 && from[1] == 0 )
// return;
cerr << _type << " collided with " << by->_type << " from ";
// cerr << _type << " collided with " << by->_type << " from ";
if( from[0] != 0 )
cerr << ((from[0]==1)?"right":"left") << endl;
// if( from[0] != 0 )
// cerr << ((from[0]==1)?"right":"left") << endl;
if( from[1] != 0 )
cerr << ((from[1]==1)?"bottom":"top") << endl;
// if( from[1] != 0 )
// cerr << ((from[1]==1)?"bottom":"top") << endl;
}

View File

@ -17,11 +17,10 @@
void setTexture(SDL_Texture *t); // Sprite texture
vector<int> move(SDL_Rect newpos); // Deplace le sprite
vector<int> move(int x, int y); // Deplace le sprite
// Action en cas de collision
virtual void onCollide(vector<int> from, xSprite* by);
virtual void onCollide(vector<bool> from, xSprite* by);
string getType(); // renvoie le type de sprite
void setType(string newtype); // modifie le type de sprite