|
|
@@ -0,0 +1,409 @@ |
|
|
|
// |
|
|
|
// checkedInVisitor.cpp |
|
|
|
// Projekt_FORUM |
|
|
|
// |
|
|
|
// Created by Sebastian Holzki on 19.06.19. |
|
|
|
// |
|
|
|
|
|
|
|
#include "checkedInVisitor.hpp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckedInVisitor::CheckedInVisitor(){ |
|
|
|
|
|
|
|
started = false; |
|
|
|
xVelocityMax = 1.5000; |
|
|
|
age = 0; |
|
|
|
setupInOfAppIsFinished = false; |
|
|
|
startingAnimationIsFinished = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckedInVisitor::~CheckedInVisitor(){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
void CheckedInVisitor::setup(int _playerType, int _checkedInStele, float sceneWidth, float sceneHeight){ |
|
|
|
|
|
|
|
//Everytime a visitor checks in, we will generate a "CheckedInVisitor". |
|
|
|
//Depending, what playerType checked in, a different image will be loaded into ofImage imageOfType, representing the playerType. |
|
|
|
//We also scale and set the default color here. Later we might be able to also pass the "greatWhole" information about the currentMode of the system, |
|
|
|
//so we can play around with the CheckedInVisitors as well. |
|
|
|
|
|
|
|
k1 = ofRandom(0.3,0.5); // random value for k1*sin(...)+... |
|
|
|
k2 = ofRandom(0.3,1.2); // random value for ...*sin(k2*age)+.... |
|
|
|
k3 = ofRandom(0.8, 1.2); |
|
|
|
|
|
|
|
checkedInStele = _checkedInStele; |
|
|
|
playerType = _playerType; |
|
|
|
|
|
|
|
|
|
|
|
switch ( playerType ){ |
|
|
|
|
|
|
|
case 1: { |
|
|
|
|
|
|
|
imageOfType.load("images/image1_color.png"); |
|
|
|
hexagon.load("images/hexagon_1.png"); |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case 2: { |
|
|
|
|
|
|
|
imageOfType.load("images/image2_color.png"); |
|
|
|
hexagon.load("images/hexagon_2.png"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case 3: { |
|
|
|
|
|
|
|
imageOfType.load("images/image3_color.png"); |
|
|
|
hexagon.load("images/hexagon_3.png"); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case 4: { |
|
|
|
|
|
|
|
imageOfType.load("images/image4_color.png"); |
|
|
|
hexagon.load("images/hexagon_4.png"); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
imageOfType.load("images/noplayertype.png"); |
|
|
|
|
|
|
|
} //end of switch |
|
|
|
|
|
|
|
setupPosition(sceneWidth, sceneHeight, checkedInStele); |
|
|
|
|
|
|
|
|
|
|
|
imageOfType.resize(imageOfType.getWidth()*0.5, imageOfType.getHeight()*0.5); |
|
|
|
hexagon.resize(hexagon.getWidth()*0.5, hexagon.getHeight()*0.5); |
|
|
|
// pixelsWithValues(sceneWidth, sceneHeight, hexagon); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
void CheckedInVisitor::update(float deltaT, float sceneWidth, float sceneHeight){ |
|
|
|
|
|
|
|
|
|
|
|
aging(deltaT); |
|
|
|
move(deltaT, sceneWidth, sceneHeight); |
|
|
|
|
|
|
|
if(age > 3 && started == false){ |
|
|
|
|
|
|
|
setupVelocity(); |
|
|
|
started = true; |
|
|
|
} |
|
|
|
|
|
|
|
// updateAttractingPixels(); |
|
|
|
|
|
|
|
positionLastFrame = position; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::draw(){ |
|
|
|
|
|
|
|
ofSetColor(255,255,255); |
|
|
|
imageOfType.draw(position); |
|
|
|
hexagon.draw(position); |
|
|
|
if(attractingPixelsOfHexagon.size()){ |
|
|
|
ofDrawBitmapString(ofToString(attractingPixelsOfHexagon.at(0).x), position.x, position.y - 20); |
|
|
|
ofDrawBitmapString(ofToString(position.x), position.x, position.y - 40); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
ofVec2f CheckedInVisitor::getPosition(){ |
|
|
|
|
|
|
|
return position; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
ofVec2f CheckedInVisitor::getBottom(){ |
|
|
|
|
|
|
|
ofVec2f bottom = this->position; |
|
|
|
bottom.x += hexagon.getWidth()/2; |
|
|
|
bottom.y += hexagon.getHeight()*0.99; |
|
|
|
|
|
|
|
return bottom; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::aging(float deltaT){ |
|
|
|
|
|
|
|
|
|
|
|
age += deltaT; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
vector<ofVec2f> CheckedInVisitor::getPositionsOfAttractingPixels(){ |
|
|
|
|
|
|
|
return attractingPixelsOfHexagon; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
bool CheckedInVisitor::getIfEmitterIsDeleted(){ |
|
|
|
|
|
|
|
return emitterHasBeenDeleted; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::updateAttractingPixels(){ |
|
|
|
|
|
|
|
float differenceX = positionLastFrame.x - position.x; |
|
|
|
float differenceY = positionLastFrame.y - position.y; |
|
|
|
|
|
|
|
for(int i = 0; i < attractingPixelsOfHexagon.size(); i++){ |
|
|
|
|
|
|
|
attractingPixelsOfHexagon.at(i).x -= differenceX; |
|
|
|
attractingPixelsOfHexagon.at(i).y -= differenceY; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::pixelsWithValues(float sceneWidth, float sceneHeight, ofImage _hexagon){ |
|
|
|
|
|
|
|
int hexagonWidth = _hexagon.getWidth(); |
|
|
|
int hexagonHeight = _hexagon.getHeight(); |
|
|
|
|
|
|
|
ofPixels pixels; |
|
|
|
pixels = hexagon.getPixels(); |
|
|
|
|
|
|
|
int counter = 11; |
|
|
|
// Iterate trough the pixels, skip 3 do 1 because only 1 channel is needed |
|
|
|
for(int i = 3; i <= pixels.size(); i+=4){ |
|
|
|
|
|
|
|
if(pixels[i] > 0){ //if the pixel has a value jump into saving it |
|
|
|
|
|
|
|
int width = pixels.getWidth(); |
|
|
|
|
|
|
|
int y = i / 4 / width ; |
|
|
|
|
|
|
|
int x = i / 4 % width ; |
|
|
|
|
|
|
|
ofVec2f pixelPosition; |
|
|
|
pixelPosition.set(position.x + x, position.y + y); |
|
|
|
|
|
|
|
if(counter > 10){ |
|
|
|
attractingPixelsOfHexagon.push_back(pixelPosition); |
|
|
|
counter = 0; |
|
|
|
} |
|
|
|
|
|
|
|
counter++; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::setupPosition(int sceneWidth, int sceneHeight, int checkedInStele){ |
|
|
|
|
|
|
|
|
|
|
|
position.y = sceneHeight - imageOfType.getHeight()/2; |
|
|
|
|
|
|
|
position.x = sceneHeight + ((sceneWidth - sceneHeight)/6)*(checkedInStele - 1); //Hinter Kreis + 1/2 Stele |
|
|
|
position.x += (sceneWidth - sceneHeight)/12 - imageOfType.getWidth()/4; |
|
|
|
|
|
|
|
positionLastFrame = position; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::setupCornerPositions(float sceneWidth, float sceneHeight){ |
|
|
|
|
|
|
|
//save the corners of the generated hexagon as positions into an array |
|
|
|
|
|
|
|
//try with ofCircles |
|
|
|
ofSetColor(255,0,0); |
|
|
|
ofDrawCircle(position.x + hexagon.getWidth()/4, position.y, 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// attractingPixelsOfHexagon.push_back( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::setPosition(ofVec2f _position){ |
|
|
|
|
|
|
|
position = _position; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::setStateOfSetup(bool stateToSet){ |
|
|
|
|
|
|
|
setupInOfAppIsFinished = stateToSet; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
bool CheckedInVisitor::getStateOfSetup(){ |
|
|
|
|
|
|
|
return setupInOfAppIsFinished; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::move(float deltaT, float sceneWidth, float sceneHeight){ |
|
|
|
|
|
|
|
int startingSpeed = 65; |
|
|
|
|
|
|
|
if(startingAnimationIsFinished != true){ |
|
|
|
startingAnimation(startingSpeed, sceneWidth, sceneHeight); |
|
|
|
position += velocity * startingSpeed * deltaT; |
|
|
|
} |
|
|
|
|
|
|
|
if(startingAnimationIsFinished == true){ |
|
|
|
position.y += k1*sin(age*k2); |
|
|
|
position += velocity * startingSpeed * deltaT * k3; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//jump from right to left |
|
|
|
if(position.x > (sceneWidth - (sceneWidth - 0.5*sceneHeight)/36 )){ |
|
|
|
position.x = sceneHeight; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::startingAnimation(float startingSpeed, float sceneWidth, float sceneHeight){ |
|
|
|
|
|
|
|
|
|
|
|
if(position.y < sceneHeight*0.4){ |
|
|
|
|
|
|
|
velocity.y *= 0.99 ; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(position.y < sceneHeight*0.4 && startedMovingToTheRight == false){ |
|
|
|
|
|
|
|
velocity.x = 0.1; |
|
|
|
startedMovingToTheRight = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(velocity.x < xVelocityMax){ |
|
|
|
|
|
|
|
velocity.x *= 1.02; |
|
|
|
|
|
|
|
} |
|
|
|
if( (((xVelocityMax - velocity.x) < 0.0001)) && ((velocity.y < 0.0001)) ){ |
|
|
|
velocity.x = xVelocityMax; |
|
|
|
velocity.y = 0; |
|
|
|
startingAnimationIsFinished = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
void CheckedInVisitor::setupVelocity(){ |
|
|
|
|
|
|
|
velocity.set(0.0, -2.0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
float CheckedInVisitor::getAge(){ |
|
|
|
|
|
|
|
return age; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------- |
|
|
|
|
|
|
|
void CheckedInVisitor::clipToLastCheckedInVisitor(CheckedInVisitor _avatar){ |
|
|
|
|
|
|
|
//Read coordinates to clip to: |
|
|
|
ofVec2f tempCoords = _avatar.getPosition(); |
|
|
|
|
|
|
|
if( tempCoords.y == 0 ){ |
|
|
|
|
|
|
|
position.x = tempCoords.x + 20 ; |
|
|
|
position.y = tempCoords.y + 20 ; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
position.x = tempCoords.x + 20 ; |
|
|
|
position.y = tempCoords.y - 20 ; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |