supertux-coop.diff 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. Index: src/control/joystickkeyboardcontroller.cpp
  2. ===================================================================
  3. --- src/control/joystickkeyboardcontroller.cpp (revision 6139)
  4. +++ src/control/joystickkeyboardcontroller.cpp (working copy)
  5. @@ -479,11 +479,12 @@
  6. KeyMap::iterator key_mapping = keymap.find(event.key.keysym.sym);
  7. // if console key was pressed: toggle console
  8. - if ((key_mapping != keymap.end()) && (key_mapping->second == CONSOLE)) {
  9. + // only main controller does console
  10. + if ((key_mapping != keymap.end()) && (key_mapping->second == CONSOLE) && (this == g_main_controller)) {
  11. if (event.type == SDL_KEYDOWN)
  12. Console::instance->toggle();
  13. } else {
  14. - if (Console::instance->hasFocus()) {
  15. + if (Console::instance->hasFocus() && (this == g_main_controller)) {
  16. // if console is open: send key there
  17. process_console_key_event(event);
  18. } else if (MenuManager::current()) {
  19. Index: src/object/player.cpp
  20. ===================================================================
  21. --- src/object/player.cpp (revision 6139)
  22. +++ src/object/player.cpp (working copy)
  23. @@ -152,7 +152,7 @@
  24. climbing(0)
  25. {
  26. this->name = name;
  27. - controller = g_main_controller;
  28. + controller = (name == "Penny") ? g_secondary_controller : g_main_controller;
  29. scripting_controller.reset(new CodeController());
  30. sprite = sprite_manager->create("images/creatures/tux/tux.sprite");
  31. airarrow = Surface::create("images/engine/hud/airarrow.png");
  32. @@ -1015,6 +1015,16 @@
  33. else
  34. sa_postfix = "-right";
  35. + // two-player hack: draw Penny in a different color
  36. + if (name == "Penny") {
  37. + sprite->set_color(Color(1.0f, 1.0f, 0.5f, 1.0f));
  38. + } else {
  39. + sprite->set_color(Color(1.0f, 1.0f, 1.0f, 1.0f));
  40. + }
  41. + // if/when we have complete penny gfx, we can
  42. + // load those instead of Tux's sprite in the
  43. + // constructor
  44. +
  45. /* Set Tux sprite action */
  46. if(dying) {
  47. sprite->set_action("gameover");
  48. @@ -1177,6 +1187,11 @@
  49. return FORCE_MOVE;
  50. }
  51. + Player* player = dynamic_cast<Player*> (&other);
  52. + if(player) {
  53. + return ABORT_MOVE;
  54. + }
  55. +
  56. if(hit.left || hit.right) {
  57. try_grab(); //grab objects right now, in update it will be too late
  58. }
  59. @@ -1276,8 +1291,11 @@
  60. dying_timer.start(3.0);
  61. set_group(COLGROUP_DISABLED);
  62. - Sector::current()->effect->fade_out(3.0);
  63. - sound_manager->stop_music(3.0);
  64. + // Two-player hack: ignore Penny's death
  65. + if (name != "Penny") {
  66. + Sector::current()->effect->fade_out(3.0);
  67. + sound_manager->stop_music(3.0);
  68. + }
  69. }
  70. }
  71. Index: src/supertux/game_session.cpp
  72. ===================================================================
  73. --- src/supertux/game_session.cpp (revision 6139)
  74. +++ src/supertux/game_session.cpp (working copy)
  75. @@ -93,6 +93,7 @@
  76. end_sequence = 0;
  77. g_main_controller->reset();
  78. + g_secondary_controller->reset();
  79. currentsector = 0;
  80. @@ -434,6 +435,22 @@
  81. game_pause = false;
  82. }
  83. + // two-player hack: resurrect Penny when she dies
  84. + Player* tux = currentsector->player;
  85. + for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin(); i != currentsector->gameobjects.end(); ++i) {
  86. + Player* p = dynamic_cast<Player*>(*i);
  87. + if (!p) continue;
  88. + if (p == tux) continue;
  89. + if (p->is_dead()) {
  90. + p->remove_me();
  91. + static PlayerStatus* ps = new PlayerStatus();
  92. + p = new Player(ps, "Penny");
  93. + currentsector->add_object(p);
  94. + p->move(tux->get_pos());
  95. + p->safe_timer.start(TUX_SAFE_TIME);
  96. + }
  97. + }
  98. +
  99. check_end_conditions();
  100. // respawning in new sector?
  101. Index: src/supertux/gameconfig.cpp
  102. ===================================================================
  103. --- src/supertux/gameconfig.cpp (revision 6139)
  104. +++ src/supertux/gameconfig.cpp (working copy)
  105. @@ -94,6 +94,11 @@
  106. g_main_controller->read(*config_control_lisp);
  107. }
  108. + const lisp::Lisp* config_control_p2_lisp = config_lisp->get_lisp("control-p2");
  109. + if(config_control_p2_lisp && g_secondary_controller) {
  110. + g_secondary_controller->read(*config_control_p2_lisp);
  111. + }
  112. +
  113. const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
  114. if(config_addons_lisp) {
  115. AddonManager::get_instance().read(*config_addons_lisp);
  116. @@ -138,6 +143,12 @@
  117. writer.end_list("control");
  118. }
  119. + if(g_secondary_controller) {
  120. + writer.start_list("control-p2");
  121. + g_secondary_controller->write(writer);
  122. + writer.end_list("control-p2");
  123. + }
  124. +
  125. writer.start_list("addons");
  126. AddonManager::get_instance().write(writer);
  127. writer.end_list("addons");
  128. Index: src/supertux/globals.cpp
  129. ===================================================================
  130. --- src/supertux/globals.cpp (revision 6139)
  131. +++ src/supertux/globals.cpp (working copy)
  132. @@ -19,6 +19,7 @@
  133. SDL_Surface* g_screen;
  134. JoystickKeyboardController* g_main_controller = 0;
  135. +JoystickKeyboardController* g_secondary_controller = 0;
  136. tinygettext::DictionaryManager* dictionary_manager = 0;
  137. int SCREEN_WIDTH;
  138. Index: src/supertux/globals.hpp
  139. ===================================================================
  140. --- src/supertux/globals.hpp (revision 6139)
  141. +++ src/supertux/globals.hpp (working copy)
  142. @@ -41,6 +41,7 @@
  143. // global variables
  144. extern JoystickKeyboardController* g_main_controller;
  145. +extern JoystickKeyboardController* g_secondary_controller;
  146. extern SDL_Surface* g_screen;
  147. @@ -64,6 +65,7 @@
  148. // global player state
  149. extern PlayerStatus* player_status;
  150. +extern PlayerStatus* second_player_status;
  151. extern SpriteManager* sprite_manager;
  152. Index: src/supertux/main.cpp
  153. ===================================================================
  154. --- src/supertux/main.cpp (revision 6139)
  155. +++ src/supertux/main.cpp (working copy)
  156. @@ -541,6 +541,7 @@
  157. timelog("controller");
  158. g_main_controller = new JoystickKeyboardController();
  159. + g_secondary_controller = new JoystickKeyboardController();
  160. timelog("config");
  161. init_config();
  162. @@ -629,6 +630,8 @@
  163. g_config = NULL;
  164. delete g_main_controller;
  165. g_main_controller = NULL;
  166. + delete g_secondary_controller;
  167. + g_secondary_controller = NULL;
  168. delete Console::instance;
  169. Console::instance = NULL;
  170. scripting::exit_squirrel();
  171. Index: src/supertux/menu/menu_storage.cpp
  172. ===================================================================
  173. --- src/supertux/menu/menu_storage.cpp (revision 6139)
  174. +++ src/supertux/menu/menu_storage.cpp (working copy)
  175. @@ -26,6 +26,8 @@
  176. ProfileMenu* MenuStorage::profile_menu = 0;
  177. KeyboardMenu* MenuStorage::key_options_menu = 0;
  178. JoystickMenu* MenuStorage::joystick_options_menu = 0;
  179. +KeyboardMenu* MenuStorage::key_options_p2_menu = 0;
  180. +JoystickMenu* MenuStorage::joystick_options_p2_menu = 0;
  181. OptionsMenu*
  182. MenuStorage::get_options_menu()
  183. @@ -63,4 +65,26 @@
  184. return joystick_options_menu;
  185. }
  186. +KeyboardMenu*
  187. +MenuStorage::get_key_options_p2_menu()
  188. +{
  189. + if (!key_options_p2_menu)
  190. + { // FIXME: this in never freed
  191. + key_options_p2_menu = new KeyboardMenu(g_secondary_controller);
  192. + }
  193. +
  194. + return key_options_p2_menu;
  195. +}
  196. +
  197. +JoystickMenu*
  198. +MenuStorage::get_joystick_options_p2_menu()
  199. +{
  200. + if (!joystick_options_p2_menu)
  201. + { // FIXME: this in never freed
  202. + joystick_options_p2_menu = new JoystickMenu(g_secondary_controller);
  203. + }
  204. +
  205. + return joystick_options_p2_menu;
  206. +}
  207. +
  208. /* EOF */
  209. Index: src/supertux/menu/menu_storage.hpp
  210. ===================================================================
  211. --- src/supertux/menu/menu_storage.hpp (revision 6139)
  212. +++ src/supertux/menu/menu_storage.hpp (working copy)
  213. @@ -32,12 +32,16 @@
  214. static ProfileMenu* get_profile_menu();
  215. static KeyboardMenu* get_key_options_menu();
  216. static JoystickMenu* get_joystick_options_menu();
  217. + static KeyboardMenu* get_key_options_p2_menu();
  218. + static JoystickMenu* get_joystick_options_p2_menu();
  219. private:
  220. static OptionsMenu* options_menu;
  221. static ProfileMenu* profile_menu;
  222. static KeyboardMenu* key_options_menu;
  223. static JoystickMenu* joystick_options_menu;
  224. + static KeyboardMenu* key_options_p2_menu;
  225. + static JoystickMenu* joystick_options_p2_menu;
  226. private:
  227. MenuStorage(const MenuStorage&);
  228. Index: src/supertux/menu/options_menu.cpp
  229. ===================================================================
  230. --- src/supertux/menu/options_menu.cpp (revision 6139)
  231. +++ src/supertux/menu/options_menu.cpp (working copy)
  232. @@ -161,6 +161,13 @@
  233. add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
  234. ->set_help(_("Configure joystick control-action mappings"));
  235. +
  236. + add_submenu(_("Setup P2 Keyboard"), MenuStorage::get_key_options_p2_menu())
  237. + ->set_help(_("Configure key-action mappings"));
  238. +
  239. + add_submenu(_("Setup P2 Joystick"), MenuStorage::get_joystick_options_p2_menu())
  240. + ->set_help(_("Configure joystick control-action mappings"));
  241. +
  242. add_hl();
  243. add_back(_("Back"));
  244. }
  245. Index: src/supertux/player_status.cpp
  246. ===================================================================
  247. --- src/supertux/player_status.cpp (revision 6139)
  248. +++ src/supertux/player_status.cpp (working copy)
  249. @@ -30,6 +30,7 @@
  250. static const int MAX_COINS = 9999;
  251. PlayerStatus* player_status = 0;
  252. +PlayerStatus* second_player_status = 0;
  253. PlayerStatus::PlayerStatus() :
  254. coins(START_COINS),
  255. Index: src/supertux/resources.cpp
  256. ===================================================================
  257. --- src/supertux/resources.cpp (revision 6139)
  258. +++ src/supertux/resources.cpp (working copy)
  259. @@ -48,6 +48,7 @@
  260. sprite_manager = new SpriteManager();
  261. player_status = new PlayerStatus();
  262. + second_player_status = new PlayerStatus();
  263. }
  264. /* Free shared data: */
  265. @@ -67,6 +68,9 @@
  266. delete player_status;
  267. player_status = NULL;
  268. +
  269. + delete second_player_status;
  270. + second_player_status = NULL;
  271. }
  272. /* EOF */
  273. Index: src/supertux/screen_manager.cpp
  274. ===================================================================
  275. --- src/supertux/screen_manager.cpp (revision 6139)
  276. +++ src/supertux/screen_manager.cpp (working copy)
  277. @@ -190,11 +190,13 @@
  278. ScreenManager::process_events()
  279. {
  280. g_main_controller->update();
  281. + g_secondary_controller->update();
  282. Uint8* keystate = SDL_GetKeyState(NULL);
  283. SDL_Event event;
  284. while(SDL_PollEvent(&event))
  285. {
  286. g_main_controller->process_event(event);
  287. + g_secondary_controller->process_event(event);
  288. if(MenuManager::current() != NULL)
  289. MenuManager::current()->event(event);
  290. Index: src/supertux/sector.cpp
  291. ===================================================================
  292. --- src/supertux/sector.cpp (revision 6139)
  293. +++ src/supertux/sector.cpp (working copy)
  294. @@ -84,6 +84,7 @@
  295. effect(0)
  296. {
  297. add_object(new Player(player_status, "Tux"));
  298. + add_object(new Player(second_player_status, "Penny"));
  299. add_object(new DisplayEffect("Effect"));
  300. add_object(new TextObject("Text"));
  301. @@ -572,19 +573,27 @@
  302. }
  303. try_expose_me();
  304. - // spawn smalltux below spawnpoint
  305. - if (!player->is_big()) {
  306. - player->move(player_pos + Vector(0,32));
  307. - } else {
  308. - player->move(player_pos);
  309. - }
  310. - // spawning tux in the ground would kill him
  311. - if(!is_free_of_tiles(player->get_bbox())) {
  312. - log_warning << "Tried spawning Tux in solid matter. Compensating." << std::endl;
  313. - Vector npos = player->get_bbox().p1;
  314. - npos.y-=32;
  315. - player->move(npos);
  316. + // two-player hack: move other players to main player's position
  317. + for(GameObjects::iterator i = gameobjects.begin();
  318. + i != gameobjects.end(); ++i) {
  319. + Player* p = dynamic_cast<Player*>(*i);
  320. + if (!p) continue;
  321. +
  322. + // spawn smalltux below spawnpoint
  323. + if (!p->is_big()) {
  324. + p->move(player_pos + Vector(0,32));
  325. + } else {
  326. + p->move(player_pos);
  327. + }
  328. +
  329. + // spawning tux in the ground would kill him
  330. + if(!is_free_of_tiles(p->get_bbox())) {
  331. + log_warning << "Tried spawning Tux in solid matter. Compensating." << std::endl;
  332. + Vector npos = p->get_bbox().p1;
  333. + npos.y-=32;
  334. + p->move(npos);
  335. + }
  336. }
  337. camera->reset(player->get_pos());
  338. @@ -645,7 +654,13 @@
  339. void
  340. Sector::update(float elapsed_time)
  341. {
  342. - player->check_bounds(camera);
  343. + // keep players in bounds
  344. + for(GameObjects::iterator i = gameobjects.begin();
  345. + i != gameobjects.end(); ++i) {
  346. + Player* p = dynamic_cast<Player*>(*i);
  347. + if (!p) continue;
  348. + p->check_bounds(camera);
  349. + }
  350. /* update objects */
  351. for(GameObjects::iterator i = gameobjects.begin();
  352. @@ -741,10 +756,11 @@
  353. Player* player = dynamic_cast<Player*> (object);
  354. if(player != NULL) {
  355. if(this->player != 0) {
  356. - log_warning << "Multiple players added. Ignoring" << std::endl;
  357. - return false;
  358. +// log_warning << "Multiple players added. Ignoring" << std::endl;
  359. +// return false;
  360. + } else {
  361. + this->player = player;
  362. }
  363. - this->player = player;
  364. }
  365. DisplayEffect* effect = dynamic_cast<DisplayEffect*> (object);