Skip to content

Instantly share code, notes, and snippets.

@dannycallaghan
Created April 23, 2019 10:37
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 dannycallaghan/d016af63098b00e3c12111037f612baf to your computer and use it in GitHub Desktop.
Save dannycallaghan/d016af63098b00e3c12111037f612baf to your computer and use it in GitHub Desktop.
Case 402 - Stage 4 - New
/*
402 - The case of the Why Gang ruby heist
Stage 4 - Fox
Officer: 5980088
CaseNum: 402-3-22317853-5980088
This final Why gang member Fox is the boss of the gang. Fox is particularly
cunning and has hidden herself down this twisted network of alleys known as
vice city. Head into vice city to find her but don’t get lost!
The gang is still in the dark about our code, not the brightest pixels in the
city!
North: detSpeedX = 0 and detSpeedY = -1
East: detSpeedX = 1 and detSpeedY = 0
South: detSpeedX = 0 and detSpeedY = 1
West: detSpeedX = -1 and detSpeedY = 0
*/
var currentRoad;
var direction;
var mapImage;
var overlayImage;
var det = {
"speedX": 0,
"speedY": 0,
"locationX": 763,
"locationY": 696,
"image": "./det.png"
};
function preload()
{
perp.image = loadImage(perp.image);
det.image = loadImage(det.image);
mapImage = loadImage("./map.png");
overlayImage = loadImage("./overlay.png")
}
function setup()
{
createCanvas(1024, 768);
}
function draw()
{
///////////////////ADD YOUR CODE HERE///////////////////
// if (det.locationY > 509)
// {
// det.speedX = 0;
// det.speedY = -1;
// }
//console.warn(det.locationY, det.locationX);
if (det.locationX === 763 && (det.locationY > 495 && det.locationY < 697))
{
north();
}
if (det.locationY === 496 && (det.locationX < 764 && det.locationX > 184))
{
west();
}
if (det.locationX === 185 && (det.locationY < 497 && det.locationY > 370))
{
north();
}
if (det.locationY === 371 && (det.locationX > 184 && det.locationX < 588))
{
east();
}
if (det.locationX === 587 && (det.locationY < 372 && det.locationY > 245))
{
north();
}
if (det.locationY === 246 && (det.locationX < 588 && det.locationX > 310))
{
west();
}
if (det.locationX === 311 && (det.locationY < 247 && det.locationY > 121))
{
north();
}
if (det.locationY === 122 && (det.locationX > 310 && det.locationX < 839))
{
east();
}
if (det.locationX === 838 && (det.locationY < 123 && det.locationY > 58))
{
north();
}
if (det.locationY === 59 && (det.locationX < 839 && det.locationX > 131))
{
west();
}
if (det.locationX === 130 && (det.locationY < 60 && det.locationY > 10))
{
north();
}
function east () {
det.speedX = 1;
det.speedY = 0;
}
function west () {
det.speedX = -1;
det.speedY = 0;
}
function north () {
det.speedX = 0;
det.speedY = -1;
}
///////////////DO NOT CHANGE CODE BELOW THIS POINT///////////////////
background(50);
det.locationX += det.speedX;
det.locationY += det.speedY;
//draw the images of the map perp and the detective
image(mapImage, 0, 0);
image(overlayImage, 0, 0);
image(perp.image, perp.locationX - roadWidth, perp.locationY - roadWidth, roadWidth * 2, roadWidth * 2);
push();
translate(det.locationX, det.locationY);
if (det.speedX != 0) rotate((det.speedX - 1.5) * PI);
else if (det.speedY < 0) rotate(PI);
image(det.image, -roadWidth, -roadWidth, roadWidth * 2, roadWidth * 2);
pop();
push();
textAlign(CENTER);
textSize(32);
noStroke();
//the perp has been caught
if (dist(det.locationX, det.locationY, perp.locationX, perp.locationY) < roadWidth / 2)
{
//display message to the player
fill(0, 220, 0);
text("Just in the nick of time! \nYou caught " + perp.name, width / 2, height / 2);
perp.caught = 1;
noLoop();
}
//not on any roads, therefore the game is lost.
if (!getOnRoad() || (det.speedX == 0 && det.speedY == 0))
{
fill(255, 0, 0);
text("You let " + perp.name + " get away.\n Better luck next time.", width / 2, height / 2);
perp.caught = -1;
noLoop();
}
pop();
hud();
}
function hud()
{
push();
fill(250);
noStroke();
textAlign(LEFT, TOP);
text("detective location - x: " + det.locationX + " y: " + det.locationY, 5, 5);
pop();
}
function getOnRoad()
{
if (mapImage.get(det.locationX, det.locationY)[0] == bckgrndColour)
{
return false;
}
return true;
}
var roadWidth = 25;
var bckgrndColour = 50;
var perp = {
"caught": 0,
"name": "Fox",
"image": "./perp.png",
"locationX": 136,
"locationY": 10
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment