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