]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/lineDefs.cpp
Use time_t to store time data.
[quix0rs-blobwars.git] / src / lineDefs.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 */
21
22 #include "lineDefs.h"
23
24 void addLineDef(const char *name, const char *linkName, const char *message, int x, int y, int width, int height, bool active)
25 {
26         LineDef *lineDef = new LineDef();
27
28         lineDef->set(name, linkName, message, x, y, width, height);
29         lineDef->activated = active;
30
31         map.addLineDef(lineDef);
32 }
33
34 void showMessageLineDef(const char *linkName, bool show)
35 {
36         LineDef *lineDef = (LineDef*)map.lineList.getHead();
37
38         while (lineDef->next != NULL)
39         {
40                 lineDef = (LineDef*)lineDef->next;
41
42                 if (strcmp(lineDef->linkName, linkName) == 0)
43                         lineDef->activated = show;
44         }
45 }
46
47 void doLineDefs()
48 {
49         LineDef *lineDef = (LineDef*)map.lineList.getHead();
50
51         int x, y, absX, absY;
52
53         while (lineDef->next != NULL)
54         {
55                 lineDef = (LineDef*)lineDef->next;
56
57                 if (lineDef->activated)
58                         continue;
59
60                 x = (int)(lineDef->x - engine.playerPosX);
61                 y = (int)(lineDef->y - engine.playerPosY);
62
63                 absX = abs(x);
64                 absY = abs(y);
65
66                 if ((absX < 800) && (absY < 600))
67                 {
68                         #if DEBUG
69                                 graphics.drawRect(x, y, lineDef->width, lineDef->height, graphics.red, graphics.screen);
70                         #endif
71
72                         if (player.health < 1)
73                         {
74                                 continue;
75                         }
76
77                         if (Collision::collision(player.x + player.dx, player.y + player.dy, player.width, player.height, lineDef->x, lineDef->y, lineDef->width, lineDef->height))
78                         {
79                                 if ((strcmp(lineDef->name, "Exit") == 0) && (!requiredObjectivesCompleted()))
80                                 {
81                                         config.resetControl(CONTROL::LEFT);
82                                         config.resetControl(CONTROL::RIGHT);
83
84                                         if (player.dx > 0) player.x = (lineDef->x - player.width) - 2;
85                                         if (player.dx < 0) player.x = (lineDef->x + lineDef->width + 2);
86                                         
87                                         player.dx = 0;
88                                         
89                                         if (!map.isBossMission)
90                                         {
91                                                 engine.setInfoMessage("Can't Exit Yet - Objectives Not Met", 1, INFO_HINT);
92                                         }
93                                         
94                                         continue;
95                                 }
96
97                                 if (strcmp(lineDef->name, "Message") == 0)
98                                 {
99                                         engine.setInfoMessage(lineDef->activateMessage, 1, INFO_HINT);
100                                         if (strcmp(lineDef->linkName, "@none@") == 0)
101                                         {
102                                                 lineDef->activated = true;
103                                         }
104                                 }
105                                 else if (strcmp(lineDef->name, "PlayerOut") == 0)
106                                 {
107                                         if (game.missionOver == 0)
108                                         {
109                                                 player.health--;
110                                         }
111
112                                         if (player.health > 0)
113                                         {
114                                                 game.setMissionOver(MIS_PLAYEROUT);
115                                         }
116                                         else
117                                         {
118                                                 game.setMissionOver(MIS_PLAYERDEAD);
119                                         }
120                                 }
121                                 else if (strcmp(lineDef->name, "CheckPoint") == 0)
122                                 {
123                                         game.setObjectiveCheckPoint();
124                                         engine.setInfoMessage("Checkpoint Reached", 9, INFO_OBJECTIVE);
125                                         lineDef->activated = true;
126                                 }
127                                 else if (strcmp(lineDef->name, "ActivateBoss") == 0)
128                                 {
129                                         map.mainBossPart->active = true;
130                                         lineDef->activated = true;
131                                 }
132                                 else
133                                 {
134                                         checkObjectives(lineDef->name, true);
135                                         activateTrigger(lineDef->linkName, lineDef->activateMessage, true);
136                                         lineDef->activated = true;
137                                         
138                                         if (strcmp(lineDef->name, "StealCrystal") == 0)
139                                         {
140                                                 stealCrystal();
141                                                 lineDef->activated = true;
142                                         }
143                                 }
144                         }
145                 }
146
147         }
148 }