Skip to content

Instantly share code, notes, and snippets.

@Jl9549
Created May 22, 2019 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jl9549/5b51b3f36551dc7ceb25a2fd6aec6c8b to your computer and use it in GitHub Desktop.
Save Jl9549/5b51b3f36551dc7ceb25a2fd6aec6c8b to your computer and use it in GitHub Desktop.
ui//These control the Transitions from Screen to Screen
boolean god = false;
boolean god2 = true;
boolean god3 = true;
boolean god4 = true;
//Libaries
import processing.sound.*;
import processing.serial.*;
import processing.video.*;
//Serial Communication
String myString = null;
Serial myPort;
int NUM_OF_VALUES = 9;
int[] sensorValues;
int PORT_INDEX = 0;
//All the digital media
Movie myMovie;
SoundFile file;
PImage maze;
PImage mino;
PImage person;
PImage death;
PImage win;
PImage rules;
PImage introPage;
//Starting Location of Runner and Minotaur
int mLocX = 860;
int mLocY = 870;
int pLocX = 100;
int pLocY = 890;
//Distance
float d;
//The previous position of a Character
int[] previous = new int[4];
void setup()
{
file = new SoundFile(this, "bM.mp3");
setupSerial();
rules = loadImage("rules.jpg");
introPage = loadImage("introPage.jpg");
death = loadImage("death.jpg");
mino = loadImage("mino.png");
person = loadImage("person.png");
maze = loadImage("maze.png");
win = loadImage("win.jpg");
size(1000, 1000);
person.resize(35, 35);
mino.resize(50, 40);
myMovie = new Movie(this, "introVideo.mp4");
myMovie.play();
}
void draw()
{
image(myMovie, 0, 0, width, height);
if (mousePressed)
{
myMovie.stop();
god = true;
god2 = false;
if(god ==true)
{ file.loop();
}
}
if (god2 == false)
{
background(introPage);
if (keyPressed)
{
if (key == 'n') {
god3 = false;
}
}
if (god3 == false)
{
background(rules);
if (keyPressed)
{
if (key== 'm')
{
god4 = false;
}
}
if (god4 == false)
{
if (god == true)
{
background(255);
pMove();
updateSerial();
mMove();
image(maze, 0, 0);
color p = get(pLocX + 15, pLocY +15);
color m = get(mLocX +15, mLocY+ 15);
if (green(p) < 100) {
//println("wall");
pLocX = previous[0];
pLocY = previous[1];
} else {
//println("no wall");
}
if (green(m) < 100) {
//println("wall");
mLocX = previous[2];
mLocY = previous[3];
} else {
//println("no wall");
}
image(mino, mLocX, mLocY);
image(person, pLocX, pLocY );
previous[0] = pLocX;
previous[1] = pLocY;
previous[2] = mLocX;
previous[3] = mLocY;
d = dist(mLocX, mLocY, pLocX, pLocY); //Distance between the players
if (d < 30) //The win condition for the Minotaur, if the distance between them is less than 30 units
{
god = false;
}
if (pLocY <= 45) //The win condition for the Player, if the player reaches a Y value great than or equal to 45
{
god = false;
}
} else if (d < 30)
{
maze = death;
image(maze, 0, 0);
if (keyPressed == true)
{
if (key == 'r') //Resets the Game
{
mLocX = 860;
mLocY = 870;
pLocX = 100;
pLocY = 890;
maze = loadImage("maze.png");
god = true;
}
} else {
god = false;
}
} else if (pLocY <= 45)
{
maze = win;
image(maze, 0, 0);
if (keyPressed == true) //Resets the Game
{
if (key == 'r')
{
mLocX = 860;
mLocY = 870;
pLocX = 100;
pLocY = 890;
maze = loadImage("maze.png");
god = true;
}
} else {
god = false;
}
}
int hr = sensorValues[8];
println(hr);
}
}
}
}
//void pMove()
//{
// if (keyPressed)
// {
// if ( keyCode == LEFT)
// {
// pLocX = pLocX -8;
// } else if ( keyCode == RIGHT)
// {
// pLocX = pLocX + 8;
// } else if ( keyCode == UP)
// {
// pLocY = pLocY -8;
// } else if ( keyCode == DOWN)
// {
// pLocY = pLocY + 8;
// }
// }
//}
//void mMove()
//{
// if (keyPressed)
// {
// if ( keyCode == LEFT)
// {
// mLocX = mLocX -9;
// } else if ( keyCode == RIGHT)
// {
// mLocX = mLocX + 9;
// } else if ( keyCode == UP )
// {
// mLocY = mLocY -9;
// } else if ( keyCode == DOWN)
// {
// mLocY = mLocY + 9;
// }
// }
//}
//Moves the Player
void pMove()
{
int hr = sensorValues[8];
if (sensorValues[6] ==1)
{
if (hr < 115)
{
pLocX = pLocX - 4;
} else if (hr >= 115)
{
pLocX = pLocX - 7;
}
} else if (sensorValues[7] ==1)
{
if (hr < 115)
{
pLocX = pLocX + 4;
} else if (hr > 115)
{
pLocX = pLocX +7;
}
} else if ( sensorValues[4]==1)
{
if (hr < 115) {
pLocY = pLocY -4;
} else if (hr > 115)
{
pLocY = pLocY - 7;
}
} else if (sensorValues[5]==1)
{
if (hr < 115) {
pLocY = pLocY +4;
} else if (hr >= 115) {
pLocY = pLocY +7;
}
}
}
//Moves the Minotaur
void mMove()
{
//LEFT
if (sensorValues[2] == 1)
{
mLocX = mLocX -5;
//RIGHT
} else if (sensorValues[3] == 1)
{
mLocX = mLocX + 5;
}
//UP
else if (sensorValues[0] == 1)
{
mLocY = mLocY -5;
} else if (sensorValues[1] == 1)
{
mLocY = mLocY + 5;
}
}
//Needed for plaiying the Video
void movieEvent(Movie m) {
m.read();
}
//Serial Communication
void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ PORT_INDEX ], 9600);
myPort.clear();
myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
myString = null;
sensorValues = new int[NUM_OF_VALUES];
}
//Serial Communication
void updateSerial() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
if (myString != null) {
String[] serialInArray = split(trim(myString), ",");
if (serialInArray.length == NUM_OF_VALUES) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment