Advertisement
Kitomas

player.cpp as of 2024-06-21

Jun 21st, 2024
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <object.hpp>
  2. #include <player.hpp>
  3. #include <tile.hpp>
  4.  
  5. using namespace kit;
  6.  
  7. #define OBJIMG(_index) gl_objImg[_index]
  8.  
  9. #define OBJIMG_LEVER_WALL     OBJIMG(1)
  10. #define OBJIMG_ABILITY_SHRINK OBJIMG(2)
  11. #define OBJIMG_ABILITY_DBLJMP OBJIMG(3)
  12. #define OBJIMG_SIGNPOST_WOOD  OBJIMG(4)
  13.  
  14.  
  15.  
  16.  
  17.  
  18. //do not use this object in a scene with more than 2 states
  19. //also, there can in theory be multiple 1lever(s) in a scene,
  20.  //as long as they share the same values of scene_old&new
  21. union _obj_1lever {
  22.   struct {
  23.     u16        scene_old;
  24.     u16        scene_new;
  25.     u16       _padding16;
  26.     bool            init;
  27.     bool         flipped;
  28.     shape::rect rect_dst;
  29.     Bitmap*          img;
  30.   };
  31.   Object o;
  32. };
  33. #define obj ((_obj_1lever*)_obj_a)
  34. bool obj_1lever(Object* _obj_a, bool render_only){
  35.   if(!obj->init){
  36.     obj->init    =  true;
  37.     obj->flipped = false;
  38.  
  39.     obj->rect_dst.x = obj->o.x;
  40.     obj->rect_dst.y = obj->o.y;
  41.     obj->rect_dst.w = obj->o.size.x;
  42.     obj->rect_dst.h = obj->o.size.y;
  43.  
  44.     obj->img = OBJIMG_LEVER_WALL;
  45.  
  46.   }
  47.  
  48.  
  49.   shape::rect rect_src(0,0, 8,24);
  50.   bool scene_changed = false;
  51.  
  52.   //if player is touching the lever
  53.   if(rects_overlapping(gl_player.getRect(), obj->rect_dst)){
  54.     rect_src.y = 24; //highlighted
  55.     //if player activates the lever
  56.     if(!render_only && CTRLSTATE_GET(down_p)){
  57.       //(this does not keep track of scene states, so don't
  58.        //use this object on a scene with more than 2 states!)
  59.       swapScene(obj->scene_old, obj->scene_new);
  60.       obj->flipped ^= 1;
  61.       scene_changed = true;
  62.     }
  63.  
  64.   }
  65.  
  66.   if(obj->flipped) rect_src.x = 8;
  67.  
  68.  
  69.   if(obj->img) obj->img->blitRect(&obj->rect_dst, &rect_src, 0xff00ff);
  70.  
  71.   return scene_changed;
  72.  
  73. }
  74. #undef obj
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement