Commit e953007b authored by Sahil Miah's avatar Sahil Miah 😷
Browse files

init

parents
Pipeline #3516 failed with stages
in 0 seconds
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
playerX = 200;
playerY = 200;
//npcX = 500;
//npcY = 200;
plane.set(ofGetWidth(),ofGetHeight());
plane.setPosition(ofGetWidth()/2, ofGetHeight()/2, 0);
player.set(200,200);
npc.set(200,200);
npc.setPosition(500, 200, 0);
}
//------------------------------
bool collision(ofPlanePrimitive rect1, ofPlanePrimitive rect2){
float x1 = rect1.getX() - rect1.getWidth()/2;
float y1 = rect1.getY() - rect1.getHeight()/2;
float x2 = rect2.getX() - rect2.getWidth()/2;
float y2 = rect2.getY() - rect2.getHeight()/2;
if (x1 < x2 + rect2.getWidth() && x1 + rect1.getWidth() > x2 && y1 < y2 + rect2.getHeight() && y1 + rect1.getHeight() > y2){
return true;
}
else{
return false;
}
}
//--------------------------------------------------------------
void ofApp::update(){
player.setPosition(playerX, playerY, 0);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofColor purple(150, 0, 150);
ofColor blue(60, 60, 200);
ofSetColor(240);
plane.draw();
if(collision(player, npc)) ofSetColor(purple);
else ofSetColor(blue);
player.draw();
if(!collision(player, npc)) ofSetColor(purple);
else ofSetColor(blue);
npc.draw();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
switch (key) {
case 'w':
playerY -= 10;
break;
case 's':
playerY += 10;
break;
case 'a':
playerX -= 10;
break;
case 'd':
playerX += 10;
break;
case 'r':
playerX = 200;
playerY = 200;
break;
default:
break;
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofPlanePrimitive plane;
ofPlanePrimitive player;
ofPlanePrimitive npc;
float playerX;
float playerY;
//float npcX;
//float npcY;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment