home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / objects / enemystopper.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2008-09-25  |  2.9 KB  |  112 lines

  1. /***************************************************************************
  2.  * enemystopper.cpp  -  enemystopper class
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #include "../objects/enemystopper.h"
  17. #include "../level/level_editor.h"
  18. #include "../core/game_core.h"
  19. #include "../core/camera.h"
  20. #include "../core/i18n.h"
  21.  
  22. /* *** *** *** *** *** cEnemyStopper *** *** *** *** *** *** *** *** *** *** *** *** */
  23.  
  24. cEnemyStopper :: cEnemyStopper( float x, float y )
  25. : cImageObjectSprite( x, y )
  26. {
  27.     cEnemyStopper::Init();
  28. }
  29.  
  30. cEnemyStopper :: cEnemyStopper( CEGUI::XMLAttributes &attributes )
  31. : cImageObjectSprite()
  32. {
  33.     cEnemyStopper::Init();
  34.     cEnemyStopper::Create_from_Stream( attributes );
  35. }
  36.  
  37. cEnemyStopper :: ~cEnemyStopper( void )
  38. {
  39.  
  40. }
  41.  
  42. cEnemyStopper *cEnemyStopper :: Copy( void )
  43. {
  44.     cEnemyStopper *enemystopper = new cEnemyStopper( startposx, startposy );
  45.  
  46.     return enemystopper;
  47. }
  48.  
  49. void cEnemyStopper :: Init( void )
  50. {
  51.     sprite_array = ARRAY_ACTIVE;
  52.     type = TYPE_ENEMY_STOPPER;
  53.     massivetype = MASS_PASSIVE;
  54.     editor_posz = 0.11f;
  55.  
  56.     name = _("Enemystopper");
  57.  
  58.     rect.w = 15;
  59.     rect.h = 15;
  60.     col_rect.w = 15;
  61.     col_rect.h = 15;
  62.     start_rect.w = 15;
  63.     start_rect.h = 15;
  64.  
  65.     editor_color = Color( static_cast<Uint8>(0), 0, 255, 128 );
  66. }
  67.  
  68. void cEnemyStopper :: Create_from_Stream( CEGUI::XMLAttributes &attributes )
  69. {
  70.     Set_Pos( static_cast<float>(attributes.getValueAsInteger( "posx" )), static_cast<float>(attributes.getValueAsInteger( "posy" )), 1 );
  71. }
  72.  
  73. void cEnemyStopper :: Save_to_Stream( ofstream &file )
  74. {
  75.     // begin enemystopper
  76.     file << "\t<enemystopper>" << std::endl;
  77.  
  78.     // position
  79.     file << "\t\t<Property name=\"posx\" value=\"" << static_cast<int>(startposx) << "\" />" << std::endl;
  80.     file << "\t\t<Property name=\"posy\" value=\"" << static_cast<int>(startposy) << "\" />" << std::endl;
  81.  
  82.     // end enemystopper
  83.     file << "\t</enemystopper>" << std::endl;
  84. }
  85.  
  86. void cEnemyStopper :: Draw( cSurfaceRequest *request /* = NULL */ )
  87. {
  88.     if( !valid_draw )
  89.     {
  90.         return;
  91.     }
  92.  
  93.     pVideo->Draw_Rect( col_rect.x - pActive_Camera->x, col_rect.y - pActive_Camera->y, col_rect.w, col_rect.h, editor_posz, &editor_color );
  94. }
  95.  
  96. bool cEnemyStopper :: Is_Draw_Valid( void )
  97. {
  98.     // if editor not enabled
  99.     if( !editor_enabled )
  100.     {
  101.         return 0;
  102.     }
  103.  
  104.     // if not visible on the screen
  105.     if( !visible || !Is_Visible_on_Screen() )
  106.     {
  107.         return 0;
  108.     }
  109.  
  110.     return 1;
  111. }
  112.