Want more features on Pastebin? Sign Up, it's FREE!
Guest

my_code3

By: a guest on Mar 14th, 2012  |  syntax: C++  |  size: 1.35 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HGE* hge = hgeCreate(HGE_VERSION);
  2. class CPlayer
  3. {
  4. public:
  5.         float x,y;
  6.         float speed;
  7.         hgeQuad quad;
  8.         HTEXTURE tex1;
  9.         CPlayer(float xf=600,float yf=400,float speedf=400);
  10.        
  11.         void obj_framefunc();
  12.  
  13.         void obj_render();
  14.  
  15.         void obj_initiate();
  16.  
  17.  
  18.         private:
  19.        
  20.        
  21.  
  22.        
  23. };
  24. CPlayer::CPlayer(float xf,float yf,float speedf)
  25. {
  26.        
  27.         x = xf;
  28.         y = yf;
  29.         speed = speedf;
  30.        
  31.  
  32. }
  33.  
  34. void CPlayer::obj_framefunc()
  35. {
  36. float dt=hge->Timer_GetDelta();
  37.  
  38. if (hge->Input_GetKeyState(HGEK_LEFT)) x-=speed*dt;
  39.   if (hge->Input_GetKeyState(HGEK_RIGHT)) x+=speed*dt;
  40.   if (hge->Input_GetKeyState(HGEK_UP)) y-=speed*dt;
  41.   if (hge->Input_GetKeyState(HGEK_DOWN)) y+=speed*dt;
  42.  
  43.  
  44.  
  45.   if(x>784) {x=784;}
  46.   if(x<16) {x=16;}
  47.   if(y>584) {y=584;}
  48.   if(y<16) {y=16;}
  49.  
  50.  
  51.   quad.v[0].x=x-16; quad.v[0].y=y-16;
  52.   quad.v[1].x=x+16; quad.v[1].y=y-16;
  53.   quad.v[2].x=x+16; quad.v[2].y=y+16;
  54.   quad.v[3].x=x-16; quad.v[3].y=y+16;
  55.  
  56.  
  57. }
  58.  
  59. void CPlayer::obj_render()
  60. {
  61. hge->Gfx_RenderQuad(&quad);
  62.  
  63. }
  64. void CPlayer::obj_initiate()
  65. {
  66.         quad.tex=tex1;
  67.           quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL | BLEND_ZWRITE;
  68.  
  69.     for(int i=0;i<4;i++)
  70.     {
  71.       quad.v[i].z=0.5f;
  72.       quad.v[i].col=0xFFFFA000;
  73.     }
  74.  
  75.     quad.v[0].tx=0; quad.v[0].ty=0;
  76.     quad.v[1].tx=1; quad.v[1].ty=0;
  77.     quad.v[2].tx=1; quad.v[2].ty=1;
  78.     quad.v[3].tx=0; quad.v[3].ty=1;
  79. }
  80. hge->Release();
clone this paste RAW Paste Data