Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MATTHEW SLUG 0.5 - Object.cpp

Object.cpp

Caricato da: Matthew
Scarica il programma completo

  1. /*
  2.  * Object.cpp
  3.  *
  4.  *  Created on: 12-Oct-2009
  5.  *      Author: matthew
  6.  */
  7.  
  8. #include "Object.h"
  9. #include "mylib.h"
  10.  
  11. Object::Object()
  12. {
  13.         gravity = 0;
  14.         x=0;
  15.         y=0;
  16.         speed_x=0;
  17.         speed_y=0;
  18.         dynamic=false;
  19.  
  20. }
  21. Object::Object(BITMAP *image)
  22. {
  23.         x=0;
  24.         y=0;
  25.         speed_x=0;
  26.         speed_y=0;
  27.         dynamic=false;
  28.         h=image->h;
  29.         w=image->w;
  30.         gravity = 0;
  31.         curr = 0;
  32.         sprite.push_back(image);
  33. }
  34.  
  35.         Object::~Object()
  36.         {
  37.         }
  38.  
  39.         int Object::getX()
  40.     {
  41.         return x;
  42.     }
  43.     int Object::getY()
  44.     {
  45.         return y;
  46.     }
  47.     void Object::setX(int _x)
  48.     {
  49.          x=_x;
  50.     }
  51.     void Object::setY(int _y)
  52.     {
  53.          y=_y;
  54.     }
  55.     int Object::getH()
  56.     {
  57.         return h;
  58.     }
  59.     int Object::getW()
  60.     {
  61.         return w;
  62.     }
  63.     void Object::setH(int _h)
  64.     {
  65.         h=_h;
  66.     }
  67.     void Object::setW(int _w)
  68.     {
  69.         w=_w;
  70.     }
  71.     int Object::getSpeedX()
  72.     {
  73.         return speed_x;
  74.     }
  75.     int Object::getSpeedY()
  76.     {
  77.         return speed_y;
  78.     }
  79.     void Object::setSpeedX(int _sx)
  80.     {
  81.          speed_x=_sx;
  82.     }
  83.     void Object::setSpeedY(int _sy)
  84.     {
  85.          speed_y=_sy;
  86.     }
  87.     void Object::move()
  88.     {
  89.         speed_y+=gravity;
  90.                 int y_new = y + (int)speed_y;
  91.                 int x_new = x+(int)speed_x;
  92.  
  93.          if(y_new <0)
  94.          {
  95.                 //If it goes beyond the top border, pull it back
  96.                 y_new=0;
  97.                 speed_y=0;
  98.          }
  99.          else if(y_new >600-h)
  100.          {
  101.                 //If it goes beyond the bottom border, pull it back
  102.                 y_new=600-h;
  103.                 speed_y=0;
  104.          }
  105.          //Set new y
  106.          y = y_new;
  107.  
  108.          if(x_new < 0)
  109.          {
  110.              //If it goes beyond the left border, pull it back
  111.              x_new=0;
  112.              speed_x*=-1;
  113.          }
  114.          else if(x_new >800-w)
  115.          {
  116.              //If it goes beyond the right border, pull it back
  117.              x_new=800-w;
  118.              speed_x*=-1;
  119.          }
  120.          //Set new x
  121.          x=x_new;
  122.  
  123.          }
  124.  
  125.     bool Object::getDynamic()
  126.     {
  127.          return dynamic;
  128.     }
  129.     void Object::setDynamic(bool value)
  130.     {
  131.          dynamic = value;
  132.     }
  133.     void Object::setSpriteN(unsigned int value)
  134.     {
  135.         curr= value;
  136.     }
  137.     int Object::getSpriteN()
  138.     {
  139.          return curr;
  140.     }
  141.     void Object::scroll(int speed)
  142.     {
  143.         x-=speed;
  144.     }
  145.     int Object::getGravity()
  146.     {
  147.         return gravity;
  148.     }
  149.     void Object::setGravity(int value)
  150.     {
  151.         gravity=value;
  152.     }
  153.     bool Object::onScreen()
  154.     {
  155.         if((x>800)|(x+w<0)|(y>600)|(y+h<0))
  156.                 return false;
  157.         else return true;
  158.     }
  159.     void Object::loadSprite(BITMAP *image)
  160.     {
  161.         sprite.push_back(image);
  162.     }
  163.     BITMAP *Object::getSprite()
  164.     {
  165.         return sprite[curr];
  166.     }