Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win animation #45

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 65 additions & 10 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ let pos, dir;
let bias;
// All the points along the drill path so far
let path;
let reversePath;
let pathPosition;
let finalPathLength;
let oldPaths;
let actionSequence;
// let randomTurnResistance = 0;
Expand Down Expand Up @@ -341,6 +343,10 @@ function createHddScene() {
hddScene.noStroke();
hddScene.rect(0, 0, width, groundLevel);

// todo add the houses here
// it is important to color houses differently
// because the status checking occurs based on color

// Add the goal
hddScene.fill(goalColor);
hddScene.rect(goal.x - 2, groundLevel - goal.w - 2, goal.w + 4, goal.w + 4);
Expand Down Expand Up @@ -387,9 +393,13 @@ function startDrill() {

// rest of the setup
path = [];
reversePath = [
[createVector(width, groundLevel - 4)],
[createVector(goal.x + goal.w, groundLevel - 4)]];
actionSequence = [];
oldPaths = [];
pathPosition = -1;
finalPathLength = undefined;
stuckCount = 0;
startCount = 0;
// randomTurnResistance = 0;
Expand Down Expand Up @@ -555,7 +565,9 @@ function setup() {
createDiv(
'<a href="instructions/instructions-slide.png">Visual instructions</a>'
).id("visual-instructions");
createDiv("");
createDiv(
'<a href="https://github.com/CodingTrain/Directional-Boring">Link to GitHub</a>'
);
createDiv(
'Copyright (c) 2022 Daniel Shiffman; Sergey Alyaev; ArztKlein; Denisovich; tyomka896 <a href="LICENSE.md">MIT License</a>'
).id("copyright");
Expand All @@ -568,6 +580,16 @@ function setup() {
machineFront = loadImage('assets/machine-foreground-small.png');

startDrill();

// removing an anoying div from LaspPass
const annoyingDivs = document.querySelectorAll(`div`);
// [style="position: static !important;]
for (const annoying1 of annoyingDivs) {
// annoying1.remove();
if (annoying1.style[0] === "position"){
annoying1.remove();
}
}
}

function createGameControlDivs(){
Expand Down Expand Up @@ -898,11 +920,16 @@ function drawEndGameStatsAtY(textY){
textAlign(RIGHT, TOP);
noStroke();
fill(255);
// todo fix font for linux
textFont('courier-bold');
const fontSize = 24;
const textX = width - fontSize;
textSize(fontSize);

if (!finalPathLength){
finalPathLength = path.length;
}

let reward = 0;
if (state == "WIN"){
reward = 5000;
Expand All @@ -913,7 +940,7 @@ function drawEndGameStatsAtY(textY){
}
textY += fontSize;
if (state == "WIN"){
let drilledPathPixels = path.length*deltaSpeedCurGame;
let drilledPathPixels = finalPathLength*deltaSpeedCurGame;
text(`final pipe length = ${padNumber(drilledPathPixels)}-`, textX, textY);
reward -= drilledPathPixels;
} else{
Expand All @@ -923,7 +950,7 @@ function drawEndGameStatsAtY(textY){
}
textY += fontSize;

let length = path.length;
let length = finalPathLength;
for (let oldPath of oldPaths) {
length += oldPath.length;
}
Expand Down Expand Up @@ -1020,6 +1047,7 @@ function draw() {
}
endShape();
}

// the newest well
beginShape();
noFill();
Expand All @@ -1031,6 +1059,31 @@ function draw() {
}
endShape();

// the pulled pipe/cable if win

if (state == 'WIN'){
beginShape();
noFill();
stroke(127);
strokeWeight(8);
let v;
for (let vPair of reversePath) {
v = vPair[0]
vertex(v.x, v.y);
}
endShape();
// draw hole enlarger in black
if (v){
stroke(0);
// todo something weird with circle diameter should be the same as strokeWeight
circle(v.x, v.y, 3);
}
// propogate pipe
if (path.length > 0){
reversePath.push(path.pop());
}
}

// Draw something where drill starts
fill(255, 0, 0);
stroke(0);
Expand Down Expand Up @@ -1088,13 +1141,15 @@ function draw() {
}

// Draw the drill bit
push();
stroke(252, 238, 33);
strokeWeight(8);
translate(pos.x, pos.y);
rotate(dir.heading() + (startingAngle) * bias);
line(0, 0, 10, 0);
pop();
if (state != 'WIN'){
push();
stroke(252, 238, 33);
strokeWeight(8);
translate(pos.x, pos.y);
rotate(dir.heading() + (startingAngle) * bias);
line(0, 0, 10, 0);
pop();
}

// show frame rate
textAlign(LEFT, TOP);
Expand Down