-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete rough refactor into modules
- Loading branch information
Showing
19 changed files
with
359 additions
and
49 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// The nearest neighbor algorithm as described by: | ||
// https://tech-algorithm.com/articles/nearest-neighbor-image-scaling/ | ||
const scaleNearestNeighbor = function(image, targetWidth, targetHeight) | ||
{ | ||
image.loadPixels(); | ||
let tmp = createImage(targetWidth, targetHeight); | ||
let wRatio = image.width/targetWidth; | ||
let hRatio = image.height/targetHeight; | ||
for (let i = 0; i < targetWidth; i++) | ||
{ | ||
for (let j = 0; j < targetHeight; j++) | ||
{ | ||
const x = Math.floor(i*wRatio); | ||
const y = Math.floor(j*hRatio); | ||
tmp.set(i, j, image.get(x, y)); | ||
} | ||
} | ||
tmp.updatePixels(); | ||
return tmp; | ||
} | ||
|
||
export { scaleNearestNeighbor } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// let imageButtons = []; | ||
|
||
// const ImageButton = class | ||
// { | ||
// img; | ||
// x; | ||
// y; | ||
// callback; | ||
|
||
// constructor(img, x, y, callback) | ||
// { | ||
// this.img = img; | ||
// this.x = x; | ||
// this.y = y; | ||
// this.callback = function (event) { | ||
// if (mouseX > x && mouseX < x + img.width && mouseY > y && mouseY < y + img.height) | ||
// { | ||
// callback(event); | ||
// } | ||
// }; | ||
// } | ||
|
||
// show() | ||
// { | ||
// image(this.img, this.x, this.y); | ||
// } | ||
|
||
// init() | ||
// { | ||
// if (imageButtons.indexOf(this) == -1) | ||
// imageButtons.push(this); | ||
// } | ||
|
||
// destroy() | ||
// { | ||
// imageButtons.splice(imageButtons.indexOf(this), 1); | ||
// } | ||
// } | ||
|
||
export default class ImageButton { | ||
|
||
constructor(img, x, y, callback) | ||
{ | ||
this.img = img; | ||
this.x = x; | ||
this.y = y; | ||
this.callback = function (event) { | ||
if (mouseX > x && mouseX < x + img.width && mouseY > y && mouseY < y + img.height) | ||
{ | ||
callback(event); | ||
} | ||
}; | ||
} | ||
|
||
show() | ||
{ | ||
image(this.img, this.x, this.y); | ||
} | ||
|
||
init() | ||
{ | ||
// if (imageButtons.indexOf(this) == -1) | ||
// imageButtons.push(this); | ||
} | ||
|
||
destroy() | ||
{ | ||
// imageButtons.splice(imageButtons.indexOf(this), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default class Scene { | ||
setup() {} | ||
draw() { | ||
background(0, 0, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
const challengeMode = function() | ||
{ | ||
background(0, 0, 255); | ||
const challengeMode = { | ||
"setup": function() | ||
{ | ||
|
||
}, | ||
"draw": function() | ||
{ | ||
background(0, 0, 255); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
const cheatSheet = function() | ||
{ | ||
background(0, 255, 0); | ||
import Scene from "../objects/scene.js"; | ||
import { scaleNearestNeighbor } from "../helperFunctions/imageFunctions.js"; | ||
import ImageButton from "../objects/imageButton.js"; | ||
import { currentScene, scenes, MAIN_MENU } from "../scenes/scenes.js"; | ||
|
||
export default class CheatSheet extends Scene { | ||
constructor() { | ||
super(); | ||
this.cheatSheetImg = {}; | ||
this.cheatSheetBtnImg = {}; | ||
this.cheatSheetBtn = {}; | ||
} | ||
|
||
setup() { | ||
this.cheatSheetImg = loadImage("assets/textures/CheatSheet.png", | ||
() => this.cheatSheetImg = scaleNearestNeighbor(this.cheatSheetImg, 640, 480)); | ||
this.cheatSheetBtnImg = loadImage("assets/textures/CheatSheetBackButton.png", | ||
() => { | ||
this.cheatSheetBtnImg = scaleNearestNeighbor(this.cheatSheetBtnImg, 301, 103); | ||
this.cheatSheetBtn = new ImageButton(this.cheatSheetBtnImg, 13, 359, | ||
() => { | ||
currentScene = MAIN_MENU; | ||
this.cheatSheetBtn.destroy(); | ||
scenes[currentScene]["setup"](); | ||
}); | ||
this.cheatSheetBtn.init(); | ||
}); | ||
} | ||
|
||
draw() { | ||
image(this.cheatSheetImg, 0, 0); | ||
image(this.cheatSheetBtnImg, 13, 359); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
const gameOver = function() | ||
{ | ||
background(0, 255, 255); | ||
const gameOver = { | ||
"setup": function() | ||
{ | ||
|
||
}, | ||
"draw": function() | ||
{ | ||
background(0, 255, 255); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
const instructions = function() | ||
{ | ||
background(255, 0, 0); | ||
const instructions = { | ||
"setup": function() | ||
{ | ||
|
||
}, | ||
"draw": function() | ||
{ | ||
background(255, 0, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
let timer = 3; //Countdown timer | ||
let midLine; //Horizontal line in the scene | ||
let midLine2; //Vertical line in the scene | ||
let animatedLine; //Line that will circle around during the countdown | ||
let angle=0; //Angle the animatedLine will use to circle around | ||
let finishedCountdown = false; //Boolean to stop the line from circling around when countdown stops | ||
|
||
const levelCountdown = function() | ||
{ | ||
background(130); //Setting up background color | ||
textAlign(CENTER); //Aligning timer text to be in center | ||
textSize(100); //Changing size of text | ||
text(timer, width/2, height/2); //Adding text to the scene | ||
|
||
stroke('black'); //Setting up the color of the brush | ||
fill('black'); //Setting the fill color of the shapes | ||
strokeWeight(3); //Setting up the size of the brush | ||
|
||
midLine = line(0,240,640,240); //Drawing the first middle line | ||
midLine2 = line(320,0,320,480); //Drawing the second middle line | ||
|
||
stroke('white'); | ||
noFill(); //Disabling filling | ||
strokeWeight(4); | ||
|
||
//Creating two circles | ||
circle1 = circle(320,240, 300); | ||
circle2 = circle(320,240, 350); | ||
|
||
stroke('black'); | ||
fill('black'); | ||
strokeWeight(3); | ||
|
||
//Condition to check if countdown is finished | ||
if(!finishedCountdown){ | ||
|
||
//The next 4 lines add the animation to the line that should circle around | ||
translate(width/2, height/2); | ||
rotate(angle); | ||
animatedLine = line(0, 0, 480, 0); | ||
angle += 0.1; | ||
} | ||
|
||
/** | ||
* (frameCount is a variable that keeps track of the number of frames that have been displayed since program started) | ||
* The following condition checks if it's been 1 second and the timer bigger than 0: | ||
* 1- It decreases the timer if condition is satisfied. | ||
* 2- If condition is satisfied and timer equals 0 after decreasing it, the word "Start" will be displayed and line that circles around will stop. | ||
*/ | ||
if(frameCount % 60 == 0 && timer > 0) { | ||
timer --; | ||
|
||
if (timer == 0){ | ||
timer = "Start"; | ||
animatedLine = line(0, 0, 0, 0); | ||
finishedCountdown = true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,51 @@ | ||
export default function mainMenu() | ||
{ | ||
background(255, 0, 255); | ||
} | ||
import Scene from "../objects/scene.js"; | ||
import { scaleNearestNeighbor } from "../helperFunctions/imageFunctions.js"; | ||
import ImageButton from "../objects/imageButton.js"; | ||
import { scenes, currentScene, CHALLENGE_MODE, PRACTICE_MODE, INSTRUCTIONS, CHEAT_SHEET, SETTINGS } from "./scenes.js"; | ||
import { canvas } from "../index.js"; | ||
|
||
export default class MainMenu extends Scene { | ||
constructor() { | ||
super(); | ||
this.imageButtons = []; | ||
} | ||
|
||
setup() { | ||
const btnImageSpritesheet = "assets/textures/mainMenu/buttons.png"; | ||
const btnScenes = [ | ||
CHALLENGE_MODE, | ||
PRACTICE_MODE, | ||
INSTRUCTIONS, | ||
CHEAT_SHEET, | ||
SETTINGS | ||
]; | ||
let btnImgs = []; | ||
let img = loadImage(btnImageSpritesheet, () => { | ||
img.loadPixels(); | ||
btnScenes.forEach((e, i, a) => { | ||
let subImg = img.get(0, i*11, 75, 11); | ||
btnImgs.push(scaleNearestNeighbor(subImg, 480, 70)); | ||
}); | ||
btnImgs.forEach((image, index) => { | ||
let btn = new ImageButton(image, 0, index * 70, () => { | ||
currentScene.value = btnScenes[index]; | ||
btns.forEach(button => { | ||
button.destroy(); | ||
}); | ||
scenes[currentScene.value].setup(); | ||
}); | ||
this.imageButtons.push(btn); | ||
}); | ||
}); | ||
//canvas.mouseClicked(event => this.imageButtons.forEach(button => button.callback(event))); | ||
canvas.mousePressed(() => { | ||
console.log({ currentScene }) | ||
currentScene.value = CHEAT_SHEET | ||
scenes[currentScene.value].setup(); | ||
}); | ||
} | ||
|
||
draw() { | ||
this.imageButtons.forEach(button => button.show()); | ||
} | ||
} |
Oops, something went wrong.