wall.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* This file is part of Invaders.
  2. *
  3. * Copyright (C) 2020 LCM.
  4. * You may use, distribute and modify Invaders under the terms of the
  5. * GPLv3 license, available at <https://www.gnu.org/licenses/\>.
  6. */
  7. #include "wall.hpp"
  8. wall::wall():game_object(0,0,32) , body(0,0){} //default constructor
  9. wall::wall(int x,int y,int w,int h,int life) : game_object(x,y,32) , body(w,h){
  10. /*health = new int* [height];
  11. for(int i=0; i<height; ++i)
  12. health[i] = new int[w];*/
  13. set_life(life);
  14. }
  15. wall::~wall()
  16. {
  17. //delete [] health; if this line is commented, the program won't receive SIGSEGV after calling the destructor while creating walls' vector.
  18. }
  19. void wall::set_life(int Life){
  20. for(int i=0;i<width;i++)
  21. for(int j=0;j<height;j++)
  22. health[j][i]=Life;
  23. }
  24. void wall::create(int X,int Y,int W, int H,int life){
  25. x=X;
  26. y=Y;
  27. width=W;
  28. height=H;
  29. /*health = new int* [height];
  30. for(int i=0; i<height; ++i)
  31. health[i] = new int[width];*/
  32. set_life(life);
  33. }
  34. void wall::printlife(){
  35. for(int i=0;i<height;i++){
  36. for(int j=0;j<width;j++)
  37. std::cout<<health[i][j];
  38. std::cout<<std::endl;
  39. }
  40. std::cout<<std::endl;
  41. }