xxxxxxxxxx
125
var canvasWidth = 800;
var canvasHeight = 700;
var night = true; // if false, it changes it to day
function preload() {
//fontRegular = loadFont("fonts/PatrickHand-Regular.ttf");
bgImg = loadImage("images/Background.png");
candyImg = loadImage("images/Candy.png");
var catImg = loadSpriteSheet("images/Cat.png", 140, 150, 9);
var broomImg = loadSpriteSheet("images/Broom.png", 90, 290, 16);
var monsterImg = loadSpriteSheet("images/Monster.png", 170, 280, 8);
var ghostImg = loadSpriteSheet("images/Ghost.png", 110, 170, 9);
catAnim = loadAnimation(catImg);
broomAnim = loadAnimation(broomImg);
monsterAnim = loadAnimation(monsterImg);
ghostAnim = loadAnimation(ghostImg);
}
function setup() {
createCanvas(canvasWidth, canvasHeight);
createGameObjects();
}
function createGameObjects() {
backgroundSprites = createSprite(400, 400, 800, 700);
backgroundSprites.addImage(bgImg);
cat = createSprite(60, 550, 140, 150);
cat.addAnimation("walk", catAnim);
broom = createSprite(700, 530, 90, 290);
broom.addAnimation("glow", broomAnim);
if (night == true) {
ghost = createSprite(300, 330, 110, 170);
ghost.addAnimation("float", ghostAnim);
} else {
monster = createSprite(500, 500, 170, 280);
monster.addAnimation("walk", monsterAnim);
}
}
function draw() {
if (night == true) {
background("darkslateblue");
} else {
background("orange");
}
//drawText();
drawSprites();
checkInput();
enemyMovement();
collisions();
}
function checkInput() {
if (night == false) {
monster.onMousePressed = function() {
// do something like shrink or temporarily freeze maybe? or make cat invinsible?
}
}
if (night == true) {
ghost.onMousePressed = function() {
// teleport to a random position? or change color
}
if (mouseIsPressed) { // throwing candy
candy = createSprite(mouseX, mouseY, 50, 50);
candy.addImage(candyImg);
ghost.attractionPoint(0.5, mouseX, mouseY); // right now it doesn't stop at mouseX and mouseY, it just kinda keeps going... Maybe have to remove previously placed candy?
}
}
}
function enemyMovement() {
// make ghost move towards cat and monster move on a set path back and forth (maybe this is the part students are programming?)
}
function collisions() {
cat.position.x += 0.5;
cat.overlap(broom, youWin);
if (night == true) {
cat.overlap(ghost, gameOver);
} else {
cat.overlap(monster, gameOver);
}
}
function youWin() {
console.log("You win!");
// Make a screen for this/stop the game
}
function gameOver() {
console.log("Game Over...");
// Make a screen for this/stop the game
}
// THIS IS ALL PORTED, UPDATE IF WE NEED TEXT:
/*function drawText() {
textFont(fontRegular);
textSize(28);
fill(color(0, 255, 153));
text("Total Candy: " + candyAmount, 310, height - 11);
textAlign(CENTER, BASELINE);
textSize(38);
fill('white');
text(textDisplayed, width / 2, height - 100);
}*/