xxxxxxxxxx
268
{
let guy;
let enemy = [];
let king;
let lemon;
let left;
let leftattack;
let leftdown;
let leftdownattack;
let right;
let rightattack;
let rightup;
let rightupattack;
let cutscene;
let font;
let paper;
let intro;
}
{
//Knight's dimensions: 210, 140
//King's dimesions: 230, 300
//lemon is 5x3 (50x30)
//Glitchy on chromebook: unfixable
//You can't die twice
//You stay alive if far away from the enemy
//battling is still garbachjghé
//Sir Eldron, you are my finest, bravest knight. This is the reason I have selected you for a long, daring quest. I'd like to remind you that it's your job, so you can't really say no. Just getting it out of the way. Anyway, I require you to retrieve... *ahem* The Citrustone! It will be the new lemon for my staff. Frankly, this one is just kinda nasty now. So, you'll be looking for a lemon yay big, encrusted with jewels, crystals and such. I, King Durox of North Ridebank now command you to be off in search of the lemon!
}
function preload() {
lemon = loadImage("lemon.png");
right = loadImage("right.png");
rightattack = loadImage("rightattack.png");
rightup = loadImage("rightup.png");
rightupattack = loadImage("rightupattack.png");
leftdown = loadImage("leftdown.png");
leftdownattack = loadImage("leftdownattack.png");
left = loadImage("left.png");
leftattack = loadImage("leftattack.png");
death = loadImage("death.gif");
king = loadImage("kingold.png");
song = loadSound("song.m4a");
font = loadFont("font.ttf");
paper = loadImage("paper.png");
}
function setup() {
createCanvas(1000, 1000);
guy = new Guy(385, 430);
enemy = new Enemy();
song.play();
cutScene = true;
intro = true;
frameRate(1);
textFont(font);
textSize(49);
textLeading(50);
}
function draw() {
background(255, 0, 255);
//image(king, 50, 50, 230, 300);
if (!cutScene) {
guy.update();
}
guy.show();
enemy.show();
if (cutScene && intro) {
image(paper, 0, 0, 1000, 1000);
fill(0);
noStroke();
text(" >-x-|'+'|->", 50, 100, 900, 900);
text(" You are the brave knight Sir Eldron,\n\nsent by King Durox of North Ridebank\nto retrieve the precious Citrustone, a\nbejewled lemon hidden far, far away.\nYou must overcome the many obstacles and numerous enemies you'll encounter during your journey if you're to succeed. Good luck, courageous knight.", 100, 200, 800, 900);
text(" -", 50, 600, 900, 900);
text(" Use the arrows or WASD to move\n\naround. Hold the spacebar to attack.", 100, 650, 800, 900);
text(" -", 50, 750, 800, 900);
text(" Press enter to continue.", 50, 800, 800, 900);
text(" >-- --- +-- +- ->", 50, 900, 800, 900);
}
if (!cutScene || !intro) {
frameRate(60);
song.stop();
cutScene = false;
}
}
function keyPressed() {
if (keyCode == 13) {
frameRate(60);
cutScene = false;
}
}
class Guy {
constructor(x, y) {
this.x = x;
this.y = y;
this.health = 100;
this.lives = 5;
this.dir = "leftdown";
this.attack = false;
}
show() {
point(this.x, this.y);
if (this.dir == "left") {
if (this.attack) {
image(leftattack, this.x, this.y, 210, 140);
} else {
image(left, this.x, this.y, 210, 140);
}
}
if (this.dir == "right") {
if (this.attack) {
image(rightattack, this.x, this.y, 210, 140);
} else {
image(right, this.x, this.y, 210, 140);
}
}
if (this.dir == "rightup") {
if (this.attack) {
image(rightupattack, this.x, this.y, 210, 140);
} else {
image(rightup, this.x, this.y, 210, 140);
}
}
if (this.dir == "leftdown") {
if (this.attack) {
image(leftdownattack, this.x, this.y, 210, 140);
} else {
image(leftdown, this.x, this.y, 210, 140);
}
}
if (this.dir == "dead") {
image(death, this.x, this.y, 210, 140);
//stop update
}
image(paper, 0, 880, 1000, 120, 0, 100, 1000, 50);
stroke(0);
line(0, 880, 1000, 880);
fill(50);
stroke(50);
strokeWeight(3);
rect(40, 920, 300, 40);
rect(380, 920, 300, 40);
fill(255, 0, 0);
rect(40, 920, this.health * 3, 40);
for(let i = 0; i < this.lives; i++) {
image(lemon, 385 + i * 60, 925, 50, 30);
}
}
update() {
if (dist(this.x + 105, this.y, enemy.x, enemy.y) < 50) {
this.health--;
}
if (key === "x") {
this.dir = "dead";
}
if (keyIsDown(68) || keyIsDown(39)) {
if (this.x < 790) {
this.x += 5;
}
this.dir = "right";
}
if (keyIsDown(65) || keyIsDown(37)) {
if (this.x > 0) {
this.x -= 5;
}
this.dir = "left";
}
if (keyIsDown(87) || keyIsDown(38)) {
if (this.y > 0) {
this.y -= 5;
}
if (!keyIsDown(68) && !keyIsDown(39) && !keyIsDown(65) && !keyIsDown(37)) {
this.dir = "rightup";
}
}
if (keyIsDown(83) || keyIsDown(40)) {
if (this.y < 740) {
this.y += 5;
}
if (!keyIsDown(68) && !keyIsDown(39) && !keyIsDown(65) && !keyIsDown(37)) {
this.dir = "leftdown";
}
}
if (keyIsDown(32) && round(frameCount / 25) == floor(frameCount / 25)) {
this.attack = true;
} else {
this.attack = false;
}
if ((keyIsDown(87) || keyIsDown(38)) && (keyIsDown(68) || keyIsDown(39)) && (keyIsDown(65) || keyIsDown(37))) {
this.dir = "rightup";
} else {
if ((keyIsDown(68) || keyIsDown(39)) && (keyIsDown(65) || keyIsDown(37))) {
this.dir = "leftdown";
}
}
if (this.health < 0) {
if (this.lives > 1) {
this.lives--;
this.health = 100 + this.health;
} else {
this.health = 0;
this.lives = 0;
//you die :(
this.dir = "dead";
}
}
if (this.health > 100) {
if (this.lives < 5) {
this.lives++;
this.health = this.health - 100;
} else {
this.health = 100;
}
}
}
}
class Enemy {
constructor() {
this.x = 600;
this.y = 600;
this.rot = 0;
}
show() {
this.rot = atan2(guy.y - this.y, guy.x + 105 - this.x);
if (dist(this.x, this.y, guy.x + 105, guy.y) > 50) {
this.x += cos(this.rot) * 2;
}
this.y += sin(this.rot) * 2;
stroke(0);
rect(this.x, this.y, 80, 140);
}
}