c94076cc99b31549fb3252738bb8603f52c14579
[supertux.git] / src / gameobjs_bridge.cpp
1  
2 /***************************************************************************
3                           gameobjs_bridge.cpp  -  description
4                              -------------------
5     begin                : Dec, 19 2004
6     copyright            : (C) 2004 by Ricardo Cruz
7     email                : rick2@aeiou.pt
8  ***************************************************************************/
9
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18
19 #include "gameobjs_bridge.h"
20
21 #include "object/coin.h"
22 #include "object/block.h"
23 #include "object/invisible_block.h"
24 #include "object/platform.h"
25 #include "object/bullet.h"
26 #include "object/rock.h"
27 #include "badguy/jumpy.h"
28 #include "badguy/snowball.h"
29 #include "badguy/bouncing_snowball.h"
30 #include "badguy/flame.h"
31 #include "badguy/flyingsnowball.h"
32 #include "badguy/mriceblock.h"
33 #include "badguy/mrbomb.h"
34 #include "badguy/dispenser.h"
35 #include "badguy/spike.h"
36 #include "badguy/spiky.h"
37 #include "badguy/nolok_01.h"
38 #include "trigger/door.h"
39 #include "trigger/sequence_trigger.h"
40 #include "trigger/secretarea_trigger.h"
41
42 std::string object_type_to_string(int kind)
43 {
44 switch(kind)
45   {
46   // Game Objects
47   case COIN_OBJECT:
48     return "coin";
49   case INVISIBLE_BLOCK_OBJECT:
50     return "invisible-block";
51   case PLATFORM_OBJECT:
52     return "platform";
53   case ROCK_OBJECT:
54     return "rock";
55   // Bad Guys
56   case JUMPY_BADGUY:
57     return "jumpy";
58   case SNOWBALL_BADGUY:
59     return "snowball";
60   case BOUNCING_SNOWBALL_BADGUY:
61     return "bouncingsnowball";
62   case FLAME_BADGUY:
63     return "flame";
64   case FLYING_SNOWBALL_BADGUY:
65     return "flyingsnowball";
66   case MRICEBLOCK_BADGUY:
67     return "mriceblock";
68   case MRBOMB_BADGUY:
69     return "mrbomb";
70   case DISPENSER_BADGUY:
71     return "dispenser";
72   case SPIKE_BADGUY:
73     return "spike";
74   case SPIKY_BADGUY:
75     return "spiky";
76   case NOLOK_01_BADGUY:
77     return "nolok_01";
78   // Triggers
79   case DOOR_TRIGGER:
80     return "door";
81   default:
82     std::cerr << "Warning: object not recognized.\n";
83     return "";  // should not happen
84   }
85 return "";  // avoids warnings
86 }
87
88 GameObjectsType object_name_to_type(const std::string& name)
89 {
90 // Game Objects
91 if(name == "coin")
92   return COIN_OBJECT;
93 else if(name == "invisible-block")
94   return INVISIBLE_BLOCK_OBJECT;
95 else if(name == "platform")
96   return PLATFORM_OBJECT;
97 else if(name == "rock")
98   return ROCK_OBJECT;
99 // Bad Guys
100 else if(name == "jumpy")
101   return JUMPY_BADGUY;
102 else if(name == "snowball")
103   return SNOWBALL_BADGUY;
104 else if(name == "bouncingsnowball")
105   return BOUNCING_SNOWBALL_BADGUY;
106 else if(name == "flame")
107   return FLAME_BADGUY;
108 else if(name == "flyingsnowball")
109   return FLYING_SNOWBALL_BADGUY;
110 else if(name == "mriceblock")
111   return MRICEBLOCK_BADGUY;
112 else if(name == "mrbomb")
113   return MRBOMB_BADGUY;
114 else if(name == "dispenser")
115   return DISPENSER_BADGUY;
116 else if(name == "spike")
117   return SPIKE_BADGUY;
118 else if(name == "spiky")
119   return SPIKY_BADGUY;
120 else if(name == "nolok_01")
121   return NOLOK_01_BADGUY;
122 // Triggers
123 else if(name == "door")
124   return DOOR_TRIGGER;
125
126 // Object not recognized
127 return NOT_RECOGNIZED_GAMEOBJECT;
128 }
129
130 bool is_object(const std::string& name)
131 {
132 if(object_name_to_type(name) == NOT_RECOGNIZED_GAMEOBJECT)
133   return false;
134 return true;
135 }
136
137 GameObject* create_object(GameObjectsType kind, const lisp::Lisp& reader)
138 {
139 switch(kind)
140   {
141   // Game Objects
142   case COIN_OBJECT:
143   case INVISIBLE_BLOCK_OBJECT:
144     std::cerr << "Error: This object doesn't yet supported a Lisp argument.\n";
145     return NULL;
146 //    return new Coin(reader);
147 //    return new InvisibleBlock(reader);
148   case PLATFORM_OBJECT:
149     return new Platform(reader);
150   case ROCK_OBJECT:
151     return new Rock(reader);
152   // Bad Guys
153   case JUMPY_BADGUY:
154     return new Jumpy(reader);
155   case SNOWBALL_BADGUY:
156     return new SnowBall(reader);
157   case BOUNCING_SNOWBALL_BADGUY:
158     return new BouncingSnowball(reader);
159   case FLAME_BADGUY:
160     return new Flame(reader);
161   case FLYING_SNOWBALL_BADGUY:
162     return new FlyingSnowBall(reader);
163   case MRICEBLOCK_BADGUY:
164     return new MrIceBlock(reader);
165   case MRBOMB_BADGUY:
166     return new MrBomb(reader);
167   case DISPENSER_BADGUY:
168     return new Dispenser(reader);
169   case SPIKE_BADGUY:
170     return new Spike(reader);
171   case SPIKY_BADGUY:
172     return new Spiky(reader);
173   case NOLOK_01_BADGUY:
174     return new Nolok_01(reader);
175   // Triggers
176   case DOOR_TRIGGER:
177     return new Door(reader);
178   default:
179     std::cerr << "Warning: object not recognized.\n";
180     return NULL;  // object not recognized
181   }
182 return NULL;  // avoids warnings
183 }
184
185 GameObject* create_object(GameObjectsType kind, const Vector& pos)
186 {
187 switch(kind)
188   {
189   // Game Objects
190   case COIN_OBJECT:
191     return new Coin(pos);
192   case INVISIBLE_BLOCK_OBJECT:
193     return new InvisibleBlock(pos);
194   case PLATFORM_OBJECT:
195   case ROCK_OBJECT:
196   case JUMPY_BADGUY:
197   case FLAME_BADGUY:
198   case DISPENSER_BADGUY:
199   case SPIKY_BADGUY:
200     std::cerr << "Error: This object doesn't yet support a position argument.\n";
201     return NULL;
202 //    return new Platform(pos);
203 //    return new Rock(pos);
204   // Bad Guys
205 //    return new Jumpy(pos.x,pos.y,LEFT);
206 //    return new Flame(pos.x,pos.y,LEFT);
207 //    return new Dispenser(pos.x,pos.y,LEFT);
208 //    return new Spiky(pos.x,pos.y,LEFT);
209   case SNOWBALL_BADGUY:
210     return new SnowBall(pos.x,pos.y,LEFT);
211   case BOUNCING_SNOWBALL_BADGUY:
212     return new BouncingSnowball(pos.x,pos.y,LEFT);
213   case FLYING_SNOWBALL_BADGUY:
214     return new FlyingSnowBall(pos.x,pos.y);
215   case MRICEBLOCK_BADGUY:
216     return new MrIceBlock(pos.x,pos.y,LEFT);
217   case MRBOMB_BADGUY:
218     return new MrBomb(pos.x,pos.y,LEFT);
219   case SPIKE_BADGUY:
220     return new Spike(pos,Spike::WEST);
221   case NOLOK_01_BADGUY:
222     return new Nolok_01(pos.x,pos.y);
223   // Triggers
224   case DOOR_TRIGGER:
225     return new Door((int)pos.x,(int)pos.y,"","");
226   default:
227     std::cerr << "Warning: object not recognized.\n";
228     return NULL;  // object not recognized
229   }
230 return NULL;  // avoids warnings
231 }