123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "GameObject.h"
- #include "Punkt.h"
- GameObject::GameObject( VariableTyp typ, int x, int y, int width, int height )
- : Variable( typ )
- {
- this->x = (float)x;
- this->y = (float)y;
- w = (float)width;
- h = (float)height;
- textur = 0;
- texturScale = 0;
- intersectable = 1;
- }
- GameObject::~GameObject()
- {
- if( textur )
- textur->release();
- }
- void GameObject::setX( float x )
- {
- this->x = x;
- }
- void GameObject::setY( float y )
- {
- this->y = y;
- }
- void GameObject::setWidth( float width )
- {
- w = width;
- }
- void GameObject::setHeight( float height )
- {
- h = height;
- }
- bool GameObject::intersectsWith( GameObject *zObj )
- {
- if( !intersectable || !zObj->intersectable )
- return 0;
- return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
- }
- void GameObject::render( Bild &rObj )
- {
- if( textur )
- {
- if( rObj.setDrawOptions( (int)x, (int)y, (int)w, (int)h ) )
- {
- if( texturScale )
- rObj.alphaBildSkall( 0, 0, (int)w, (int)h, *textur );
- else
- {
- for( int xx = 0; xx < w; xx += textur->getBreite() )
- {
- for( int yy = 0; yy < h; yy += textur->getHeight() )
- rObj.alphaBild( xx, yy, textur->getBreite(), textur->getHeight(), *textur );
- }
- }
- rObj.releaseDrawOptions();
- }
- }
- }
- float GameObject::getX() const
- {
- return x;
- }
- float GameObject::getY() const
- {
- return y;
- }
- float GameObject::getWidth() const
- {
- return w;
- }
- float GameObject::getHeight() const
- {
- return h;
- }
- bool GameObject::isIntersectable() const
- {
- return intersectable;
- }
- float GameObject::abstandZu( GameObject *zObj )
- {
- return ( Vec2<float>( x + w / 2, y + h / 2 ) - Vec2<float>( zObj->x + zObj->w / 2, zObj->y + zObj->h / 2 ) ).getLength();
- }
|