Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <object.hpp>
- #include <player.hpp>
- #include <tile.hpp>
- using namespace kit;
- #define OBJIMG(_index) gl_objImg[_index]
- #define OBJIMG_LEVER_WALL OBJIMG(1)
- #define OBJIMG_ABILITY_SHRINK OBJIMG(2)
- #define OBJIMG_ABILITY_DBLJMP OBJIMG(3)
- #define OBJIMG_SIGNPOST_WOOD OBJIMG(4)
- //do not use this object in a scene with more than 2 states
- //also, there can in theory be multiple 1lever(s) in a scene,
- //as long as they share the same values of scene_old&new
- union _obj_1lever {
- struct {
- u16 scene_old;
- u16 scene_new;
- u16 _padding16;
- bool init;
- bool flipped;
- shape::rect rect_dst;
- Bitmap* img;
- };
- Object o;
- };
- #define obj ((_obj_1lever*)_obj_a)
- bool obj_1lever(Object* _obj_a, bool render_only){
- if(!obj->init){
- obj->init = true;
- obj->flipped = false;
- obj->rect_dst.x = obj->o.x;
- obj->rect_dst.y = obj->o.y;
- obj->rect_dst.w = obj->o.size.x;
- obj->rect_dst.h = obj->o.size.y;
- obj->img = OBJIMG_LEVER_WALL;
- }
- shape::rect rect_src(0,0, 8,24);
- bool scene_changed = false;
- //if player is touching the lever
- if(rects_overlapping(gl_player.getRect(), obj->rect_dst)){
- rect_src.y = 24; //highlighted
- //if player activates the lever
- if(!render_only && CTRLSTATE_GET(down_p)){
- //(this does not keep track of scene states, so don't
- //use this object on a scene with more than 2 states!)
- swapScene(obj->scene_old, obj->scene_new);
- obj->flipped ^= 1;
- scene_changed = true;
- }
- }
- if(obj->flipped) rect_src.x = 8;
- if(obj->img) obj->img->blitRect(&obj->rect_dst, &rect_src, 0xff00ff);
- return scene_changed;
- }
- #undef obj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement