/
Object.cpp
85 lines (69 loc) · 1.96 KB
/
Object.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// Object.cpp
// Engine2D
//
// Created by Markus Pfundstein on 10/3/11.
// Copyright 2011 The Saints. All rights reserved.
//
#include <iostream>
#include "Object.h"
#include "Texture2D.h"
#include "Helpers.h"
#include "Player.h"
Object::Object() : AnimatedSprite()
{
this->animationCounter=0;
this->isMoving = false;
this->viewDirection = DOWN;
this->isPlayer = false;
this->inPlayerFocus = false;
this->isObject = true;
this->movingSpeed = 1.0f;
}
void Object::createCopyOf(const Object& other)
{
this->numSpritesX = other.numSpritesX;
this->numSpritesY = other.numSpritesY;
this->tbo = other.tbo;
this->vbo = other.vbo;
this->texture = other.texture;
this->rect = other.rect;
this->viewDirection = other.viewDirection;
this->scalar = other.scalar;
this->angle = other.angle;
this->animationCounter = other.animationCounter;
this->isMoving = other.isMoving;
this->movingSpeed = other.movingSpeed;
this->isPlayer = other.isPlayer;
this->inPlayerFocus = other.inPlayerFocus;
this->isObject = other.isObject;
this->height = other.height;
strcpy(this->name, other.name);
//printf("Object with Name %s copied\n", this->name);
}
void Object::create(const Texture2D &spriteSet, char* name, int _height)
{
this->loadData(spriteSet, NUMBER_SPRITES_OBJECTS_X, NUMBER_SPRITES_OBJECTS_Y, _height, name);
}
void Object::update(const AnimatedSprite &player)
{
this->updateAnimationState();
if (this->inPlayerFocus)
{
Rect2D tempA = player.getRect();
// loose focus on player if he walks away
if (distVect(&tempA, &this->rect)>=32)
{
this->setInPlayerFocus(false);
}
}
}
bool Object::getIfInPlayerFocus() const
{
return this->inPlayerFocus;
}
void Object::setInPlayerFocus(bool val)
{
this->inPlayerFocus = val;
//printf("Object %s PlayerFocus %d\n", this->name, this->inPlayerFocus);
}