Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "Walker.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class Day2_WalkerAttractionApp : public App {
public:
void prepareSettings( Settings *settings );
void setup() override;
void mouseDown( MouseEvent event ) override;
void update() override;
void draw() override;
Walker *mWalker1;
Walker *mWalker2;
};
void Day2_WalkerAttractionApp::prepareSettings( Settings *settings )
{
settings->setWindowSize( 640, 320 );
}
void Day2_WalkerAttractionApp::setup()
{
mWalker1 = new Walker();
mWalker2 = new Walker();
}
void Day2_WalkerAttractionApp::mouseDown( MouseEvent event )
{
}
void Day2_WalkerAttractionApp::update()
{
mWalker1->step(*mWalker2);
mWalker2->step(*mWalker1);
}
void Day2_WalkerAttractionApp::draw()
{
// gl::clear( Color( 0, 0, 0 ) );
gl::clear( Color( 0, 0, 0 ) );
mWalker1->display();
mWalker2->display();
}
CINDER_APP( Day2_WalkerAttractionApp, RendererGl )
//
// Walker.cpp
// Walker
//
// Created by Kat Sullivan on 12/12/17.
//
//
#include "Walker.h"
#include "cinder/Rand.h"
using namespace ci;
using namespace ci::app;
using namespace std;
Walker::Walker() {
Rand::randomize();
x = randInt(getWindowWidth());
y = randInt(getWindowHeight());
}
void Walker::display() {
cinder::gl::color(1.0, 0.0, 0.0);
cinder::gl::drawSolidEllipse(vec2(x,y), 1.0, 1.0);
}
void Walker::step(Walker w) {
int stepX=0;
int stepY=0;
if (w.x - this->x > 0) {
stepX = randInt(-1,3);
} else if(w.x - this->x < 0) {
stepX = randInt(-2,2);
}
if (w.y - this->y > 0) {
stepY = randInt(-1,3);
} else if(w.y - this->y < 0) {
stepY = randInt(-2,2);
}
this->x += stepX;
this->y += stepY;
}
//
// Walker.h
// Walker
//
// Created by Kat Sullivan on 12/12/17.
//
//
#pragma once
class Walker {
public:
int x;
int y;
Walker();
void display();
void step(Walker w);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment