#ifndef MONSTER_BOX_H #define MONSTER_BOX_H struct MonsterBox : public GameObject { MonsterBox() : GameObject("MonsterBox"){ dangerous = true; } bool location_refresh; bool init() override { solid = true; hostile = true; init_from_object("cube.obj"); setup_standard_shaders(); setup_texture("monster1.png"); setup_locations(); location_refresh = false; return true; } bool dangerous_at(vec4 loc) override { for(int i = 0; i < locations.size(); i++) { vec4 mbl = locations[i]; if(fabs(loc.x - mbl.x) < 0.5 && fabs(loc.y - mbl.y) < 0.5 && fabs(loc.z - mbl.z) < 0.5){ destroy(i, mbl); return true; } } return false; } float random_velocity(){ return (random() % 100 / 100.0f - 0.5f) * .2; } void destroy(int idx, vec4 mbl){ for(int i = 0; i < 20; i++){ fragments->addnew_direct(mbl.x, mbl.y, mbl.z, random_velocity(), random_velocity(), random_velocity()); } locations[idx] = locations[locations.size() - 1]; locations.pop_back(); location_refresh = true; } void activate(float x, float y, float z) override { int idx = in_contact(x, y, z); if(idx != -1) destroy(idx, locations[idx]); } void draw(mat4 vp){ if(location_refresh){ update_locations(); location_refresh = false; } draw_object(vp); } }; #endif