Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MyRectangle.cpp
- // prak_13
- //
- // Created by Marcel Ochsendorf on 11.01.17.
- // Copyright © 2017 Marcel Ochsendorf. All rights reserved.
- //
- #include "MyRectangle.hpp"
- MyRectangle::MyRectangle(const int _x,const int _y,const int _w,const int _h){
- x = _x;
- y = _y;
- w = _w;
- h = _h;
- }
- MyRectangle::MyRectangle(){
- x = 0;
- y = 0;
- w = 20;
- h = 20;
- }
- MyRectangle::~MyRectangle(){
- }
- void MyRectangle::set_x(const int _val){
- x = _val;
- }
- void MyRectangle::set_y(const int _val){
- y = _val;
- }
- void MyRectangle::set_w(const int _val){
- w = _val;
- }
- void MyRectangle::set_h(const int _val){
- h = _val;
- }
- int MyRectangle::get_x(){return x;}
- int MyRectangle::get_y(){return y;}
- int MyRectangle::get_w(){return w;}
- int MyRectangle::get_h(){return h;}
- void MyRectangle::set(const int _x,const int _y,const int _w,const int _h){
- x = _x;
- y = _y;
- w = _w;
- h = _h;
- }
- void MyRectangle::draw(){
- #ifndef UNIT_TEST
- gip_stop_updates();
- #endif
- gip_draw_rectangle(x, y, x+w, y+h, blue);
- #ifndef UNIT_TEST
- gip_start_updates();
- #endif
- }
- bool MyRectangle::is_point_inside(const int _x, const int _y){
- if(_x > x && _x < x+w && _y > y && _y < y+h){
- return true;
- }
- return false;
- }
- bool MyRectangle::does_not_collide_with(const MyRectangle& other){
- if(this->w < other.x){return true;}
- else if(other.w < this->x){return true;}
- else if(other.y > this->h){return true;}
- else if(this->y > other.h){return true;}
- return false;
- /*
- bool inter = true;
- if(is_point_inside(other.x, other.y)){inter = false;}
- if(is_point_inside(other.x + other.w, other.y)){inter = false;}
- if(is_point_inside(other.x, other.y + other.h)){inter = false;}
- if(is_point_inside(other.x + other.w, other.y + other.h)){inter = false;}
- if(x > other.x && x < other.x+other.w && y > other.y && y < other.y+other.h){inter = false;}
- if(x+w > other.x && x+w < other.x+other.w && y > other.y && y < other.y+other.h){inter = false;}
- if(x > other.x && x < other.x+other.w && y+h > other.y && y+h < other.y+other.h){inter = false;}
- if(x+w > other.x && x+w < other.x+other.w && y+h > other.y && y+h < other.y+other.h){inter = false;}
- return inter;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement