wall.cpp 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "wall.hpp"
  2. wall::wall():game_object(0,0,32) , body(0,0){} //default constructor
  3. wall::wall(int x,int y,int w,int h,int life) : game_object(x,y,32) , body(w,h){
  4. /*health = new int* [height];
  5. for(int i=0; i<height; ++i)
  6. health[i] = new int[w];*/
  7. set_life(life);
  8. }
  9. wall::~wall()
  10. {
  11. //delete [] health; if this line is commented, the program won't receive SIGSEGV after calling the destructor while creating walls' vector.
  12. }
  13. void wall::set_life(int Life){
  14. for(int i=0;i<width;i++)
  15. for(int j=0;j<height;j++)
  16. health[j][i]=Life;
  17. }
  18. void wall::create(int X,int Y,int W, int H,int life){
  19. x=X;
  20. y=Y;
  21. width=W;
  22. height=H;
  23. /*health = new int* [height];
  24. for(int i=0; i<height; ++i)
  25. health[i] = new int[width];*/
  26. set_life(life);
  27. }
  28. void wall::printlife(){
  29. for(int i=0;i<height;i++){
  30. for(int j=0;j<width;j++)
  31. std::cout<<health[i][j];
  32. std::cout<<std::endl;
  33. }
  34. std::cout<<std::endl;
  35. }