upload
This commit is contained in:
parent
86a0b94155
commit
d0c0781a0c
409
src/checkedInVisitor.cpp
Normal file
409
src/checkedInVisitor.cpp
Normal file
@ -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 ;
|
||||
|
||||
}
|
||||
|
||||
}
|
102
src/checkedInVisitor.hpp
Normal file
102
src/checkedInVisitor.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
//
|
||||
// checkedInVisitor.hpp
|
||||
// Projekt_FORUM
|
||||
//
|
||||
// Created by Sebastian Holzki on 19.06.19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "ofMain.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CheckedInVisitor {
|
||||
|
||||
|
||||
public:
|
||||
CheckedInVisitor();
|
||||
~CheckedInVisitor();
|
||||
|
||||
void setup(int playerType, int checkedInStele, float sceneWidth, float sceneHeight);
|
||||
void update(float deltaT, float sceneWidth, float sceneHeight);
|
||||
void draw();
|
||||
|
||||
void setupVelocity();
|
||||
void setupPosition(int x, int y, int checkedInStele);
|
||||
void setPosition(ofVec2f position);
|
||||
ofVec2f getPosition();
|
||||
ofVec2f getBottom();
|
||||
|
||||
void fillAttractingPixelsVector(float sceneWidth, float sceneHeight);
|
||||
void pixelsWithValues(float sceneWidth, float sceneHeight, ofImage hexagon);
|
||||
void updateAttractingPixels();
|
||||
|
||||
|
||||
vector<ofVec2f>getPositionsOfAttractingPixels();
|
||||
void setupCornerPositions(float sceneWidth, float sceneHeight);
|
||||
|
||||
void setStateOfSetup(bool setupFinished);
|
||||
bool getStateOfSetup();
|
||||
|
||||
//Every CheckedInVisitor creates an Emitter for his starting Animation
|
||||
//Following methods will help to not get any bad access errors when emitting
|
||||
// from new attractors and not doing it from older ones
|
||||
bool getIfEmitterIsDeleted();
|
||||
void setIfEmitterIsDeleted(bool isDeleted);
|
||||
|
||||
void setPlayerType();
|
||||
int getPlayerType();
|
||||
|
||||
void startingAnimation(float startingSpeed, float sceneWidth, float sceneHeight);
|
||||
void move(float deltaT, float sceneWidth, float sceneHeight);
|
||||
void aging(float deltaT);
|
||||
float getAge();
|
||||
|
||||
|
||||
|
||||
void clipToLastCheckedInVisitor(CheckedInVisitor visitor); //A particular "image" can clip its position, depending on the position of the last
|
||||
|
||||
|
||||
ofImage imageOfType;
|
||||
ofImage hexagon;
|
||||
vector<ofVec2f> attractingPixelsOfHexagon;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
int checkedInStele;
|
||||
int playerType;
|
||||
ofVec2f position;
|
||||
ofVec2f positionLastFrame;
|
||||
|
||||
|
||||
|
||||
ofVec2f velocity;
|
||||
float xVelocityMax;
|
||||
|
||||
bool started;
|
||||
bool startedMovingToTheRight;
|
||||
bool setupInOfAppIsFinished;
|
||||
bool startingAnimationIsFinished;
|
||||
bool emitterHasBeenDeleted;
|
||||
|
||||
|
||||
//Random values between 0.0 and 1.0
|
||||
float k1;
|
||||
float k2;
|
||||
float k3;
|
||||
|
||||
float age;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
79
src/greatWhole.cpp
Normal file
79
src/greatWhole.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// greatWhole.cpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by Sebastian Holzki on 17.04.19.
|
||||
//
|
||||
|
||||
#include "greatWhole.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
GreatWhole::GreatWhole()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
GreatWhole::~GreatWhole()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
|
||||
|
||||
void GreatWhole::setup(){
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
|
||||
void GreatWhole::update(vector<CheckedInVisitor*> checkedInVisitors){
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
|
||||
void GreatWhole::draw(){
|
||||
|
||||
/*
|
||||
|
||||
draw the whole avatar vector
|
||||
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
|
||||
void GreatWhole::addCheckedInVisitor(CheckedInVisitor checkedInVisitors){
|
||||
|
||||
|
||||
// avatars.push_back(avatar);
|
||||
|
||||
/*
|
||||
|
||||
Set coordinates in abhängigkeit vom letzten also bei avatars at (max-1)
|
||||
clip avatar dann an den letzten, y und x angepasst an x und y von avatars.at(max-1)
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
46
src/greatWhole.hpp
Normal file
46
src/greatWhole.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// greatWhole.hpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by Sebastian Holzki on 17.04.19.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ofMain.h"
|
||||
#include "checkedInVisitor.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
/* Das Große Ganze beinhaltet eine unbestimmte Anzahl an bereits eingecheckten Personen, deren Infos in Avatare gespeichert werden.
|
||||
Es bedarf eine setup(), update() und draw()-Methode. Dabei soll Platz für den vector<Avatar> geschaffen werden. In update wird eine
|
||||
gewisse Bewegung der Avatar-"Bubbles" definiert. Draw zeichnet die Avatare auf die Stelen, also die entsprechenden Koordinaten. */
|
||||
|
||||
|
||||
class GreatWhole {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
GreatWhole();
|
||||
~GreatWhole();
|
||||
|
||||
void setup();
|
||||
void update(vector<CheckedInVisitor*> checkedInVisitors);
|
||||
void draw();
|
||||
|
||||
void addCheckedInVisitor(CheckedInVisitor checkedInVisitors);
|
||||
CheckedInVisitor getCheckedInVisitorAt(int i);
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
vector<CheckedInVisitor*> checkedInVisitors;
|
||||
int rows;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
19
src/main.cpp
19
src/main.cpp
@ -1,10 +1,21 @@
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "ofApp.h"
|
||||
|
||||
//========================================================================
|
||||
int main( ){
|
||||
ofSetupOpenGL(1000, 1000, OF_WINDOW); // <-------- setup the GL context
|
||||
ofRunApp(new ofApp());
|
||||
}
|
||||
|
||||
//hahahahahahahahha
|
||||
//ofSetupOpenGL(3840,1200, OF_WINDOW); // <-------- setup the GL context
|
||||
|
||||
ofGLFWWindowSettings settings;
|
||||
settings.setGLVersion(3, 2);
|
||||
settings.setSize(3840, 1200);
|
||||
settings.decorated = false;
|
||||
ofCreateWindow(settings);
|
||||
|
||||
// this kicks off the running of my app
|
||||
// can be OF_WINDOW or OF_FULLSCREEN
|
||||
// pass in width and height too:
|
||||
ofRunApp( new ofApp());
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user