xxxxxxxxxx
1228
//Knight's Tale is a simple introductory platformer.
//You may control the Hero using A to move left, D to move right, Spacebar to jump, E to slide-dash right, q to slide-dash left.
//Slide-dashing uses energy which is indicated by the large yellow energy bar.
//BECAREFUL because once you run out of energy your Knight will be exhausted and move very slowly.
//You can ATTACK enemies using "K"
//Collect all the coins, kill all the skeletons, and kill the boss to win!
let HeroIdle;
let HeroRun;
let HeroUpJump;
let HeroDownJump;
let HeroAttack1;
let HeroSlide;
let HeroSlideSound;
let HeroRunSound;
let HeroAttackSound;
let HeroDirection = false;
let Boss;
let BossHealth = 60;
let BossIdle, BossWalk, BossAttack1;
let BossWalkDirection = false;
let BossDeath = false;
let BossAttackSound;
let BossMusic;
let BossAttackSwing1Left;
let SkeletonIdle, SkeletonWalk, SkeletonAttack, SkeletonHit, SkeletonDeath;
let SkeletonAttackSound;
let CoinCollectSound;
let SkeletonWalkDirection = false;
let Skeleton2WalkDirection = false;
let Skeleton3WalkDirection = false;
let Skeleton4WalkDirection = false;
let Skeleton5WalkDirection = false;
let CoinSpin;
let platforms;
let Theme;
let bg1, bg2, bg3;
let bgx1 = 1;
let bgx2 = 1;
let bgScroll = 0;
let touchingGround = false;
let Rswing, Lswing;
let SKRswing, SKLswing;
let SK2Rswing, SK2Lswing;
let SK3Rswing, SK3Lswing;
let SK4Rswing, SK4Lswing;
let SK5Rswing, SK5Lswing;
let SK1Health = 4;
let SK2Health = 4;
let SK3Health = 4;
let SK4Health = 4;
let SK5Health = 4;
let startGame = false;
let death = false;
let fade;
let fadeAmount = 1;
let slideEnergy;
let Exhaust = true;
let BGtiles, TrueTiles;
let Rock, Standard, Sleft, SRight;
let score = 0;
let SKscore = 0;
let goal1 = false;
let floor1;
let floormove = false;
let Health = 200;
let BossSwingInterval = 0;
let SwingInterval = 0;
let SK1SwingInterval = 0;
let SK2SwingInterval = 0;
let SK3SwingInterval = 0;
let SK4SwingInterval = 0;
let SK5SwingInterval = 0;
let BossTile;
let VictoryImage;
function preload() {
TrueTiles = loadImage("background/Tileset.png");
BossTile = loadImage("background/env_rock.png");
bg1 = loadImage("background/background_layer_1.png");
bg2 = loadImage("background/background_layer_2.png");
bg3 = loadImage("background/background_layer_3.png");
bgTiles = loadImage("background/Tileset.png");
VictoryImage = loadImage("VictoryImg.jpg")
//JumpSound = loadSound("Sounds/Spring2.wav")
HeroAttackSound = loadSound("Sounds/SFX/attack_knight.wav");
HeroSlideSound = loadSound("Sounds/SFX/slide_knight.wav");
HeroJumpSound = loadSound("Sounds/SFX/jump_knight.wav");
HeroRunSound = loadSound("Sounds/SFX/walk_knight.wav");
SkeletonAttackSound = loadSound("Sounds/SFX/attack_monster.wav");
CoinCollectSound = loadSound("Sounds/SFX/coin.wav");
BossAttackSound = loadSound("Sounds/SFX/axe_boss.wav")
HeroIdle = loadAnimation("Knight/_Idle.png", {
size: [120, 100],
frames: 10,
});
HeroRun = loadAnimation("Knight/_Run.png", {
size: [120, 100],
frames: 8,
});
HeroUpJump = loadAnimation("Knight/_Jump.png", {
size: [120, 100],
frames: 8,
});
HeroDownJump = loadAnimation("Knight/_Fall.png", {
size: [120, 100],
frames: 8,
});
HeroSlide = loadAnimation("Knight/_SlideFull.png", {
size: [120, 100],
frames: 8,
});
HeroAttack1 = loadAnimation("Knight/_Attack.png", {
size: [120, 100],
frames: 10,
});
CoinSpin = loadAnimation("background/coin2_20x20.png", {
size: [20, 20],
frames: 9,
});
SkeletonIdle = loadAnimation("Enemies/Skeleton/Idle.png", {
size: [150, 150],
frames: 4,
});
SkeletonAttack = loadAnimation("Enemies/Skeleton/Attack.png", {
size: [150, 150],
frames: 8,
});
SkeletonWalk = loadAnimation("Enemies/Skeleton/Walk.png", {
size: [150, 150],
frames: 4,
});
BossWalk = loadAnimation("Enemies/Boss/SL_walk.png", {
size: [196, 196],
frames: 8,
});
BossAttack1 = loadAnimation("Enemies/Boss/SL_attack_1.png", {
size: [196, 196],
frames: 10,
});
BossAttack2 = loadAnimation("Enemies/Boss/SL_attack_2.png", {
size: [196, 196],
frames: 10,
});
}
//background for the Title Screen
function setup() {
createCanvas(600, 400);
bg1.resize(600, 400);
bg2.resize(600, 400);
bg3.resize(600, 400);
VictoryImage.resize(600,400);
bgx2 = width;
bgx1 = width;
bgScroll = 0;
fadeAmount = 1;
fullBG();
//Creating the Tile Set for the Game
floor1 = new Sprite();
floor1.y = 346;
floor1.x = 936;
floor1.w = 48;
floor1.h = 24;
floor1.spriteSheet = TrueTiles;
floor1.addAni({ w: 24, h: 24, row: 2, col: 6 });
floor1.collider = "k";
Sright = new Group();
Sright.collider = "static";
Sright.spriteSheet = TrueTiles;
Sright.addAni({ w: 24, h: 24, row: 3, col: 7 });
Sright.ani.offset.y=20;
Sright.tile = "r";
Sleft = new Group();
Sleft.collider = "static";
Sleft.spriteSheet = TrueTiles;
Sleft.addAni({ w: 24, h: 24, row: 3, col: 5 });
Sleft.ani.offset.y=20;
Sleft.tile = "l";
Standard = new Group();
Standard.collider = "static";
Standard.spriteSheet = TrueTiles;
Standard.addAni({ w: 24, h: 24, row: 2, col: 6 });
Standard.ani.offset.y=20;
Standard.tile = "s";
coins = new Group();
coins.color = "yellow";
coins.collider = "static";
coins.addAni(CoinSpin);
coins.tile = "c";
coins.d = 15;
/*for (let i = 0; i < 0; i++) {
new coins.Sprite(random(50, 700), random(50,275), 15, "static");
}*/
new Tiles(
[
" c",
" c c lsssssssssssssr",
" ss lssssssssssssssssssssssssssssssssssssssssssssssssssssssssr",
" lsssssr ss",
" lsssr ss",
" lssssr",
"",
" lssssssr",
" c",
"",
" lssssssssr",
"",
" ",
" c lssssssssr",
"lsssssssssssssr ",
],
0,
300,
24,
24
);
//Creating my Hero and his Animations
Hero = new Sprite(150, -200, 20, 50);
Lswing = new Sprite(Hero.pos.x - 20, Hero.pos.y - 15, 15, "dynamic");
Lswing.life = 5;
Lswing.visible = false;
Rswing = new Sprite(Hero.pos.x + 20, Hero.pos.y - 15, 15, "dynamic");
Rswing.life = 5;
Rswing.visible = false;
Hero.rotationLock = true;
Hero.addAni("idle", HeroIdle);
Hero.addAni("run", HeroRun);
Hero.addAni("Upjump", HeroUpJump);
Hero.addAni("Downjump", HeroDownJump);
Hero.addAni("attack1", HeroAttack1);
Hero.addAni("Slide", HeroSlide);
Hero.visible = false;
HeroAttack1.frameDelay = 6;
Hero.ani.offset.y = 5;
Hero.ani.offset.x = 5;
//Adjusting Volume
HeroAttackSound = createAudio("Sounds/SFX/attack_knight.wav");
HeroSlideSound = createAudio("Sounds/SFX/slide_knight.wav");
HeroJumpSound = createAudio("Sounds/SFX/jump_knight.wav");
HeroRunSound = createAudio("Sounds/SFX/walk_knight.wav");
SkeletonAttackSound = createAudio("Sounds/SFX/attack_monster.wav");
BossAttackSound = createAudio("Sounds/SFX/axe_boss.wav")
Theme = createAudio("Sounds/Music/NormalMusic.mp3");
Theme.volume(0.07);
HeroRunSound.volume(0.02);
HeroSlideSound.volume(0.1);
HeroAttackSound.volume(0.1);
HeroJumpSound.volume(0.14);
SkeletonAttackSound.volume(0.1);
BossAttackSound.volume(0.14);
Theme.play();
VictoryTheme = createAudio ("Sounds/Music/Victory.mp3");
VictoryTheme.volume(0.4);
//Making Boss
Boss = new Sprite(2300, 250, 35, 80, "dynamic");
Boss.addAni("BossAttack1", BossAttack1);
Boss.addAni("BossAttack2", BossAttack2);
Boss.addAni("BossWalk", BossWalk);
Boss.visible = false;
Boss.rotationLock = true;
Boss.ani.offset.x = -22;
BossAttackSwing1 = new Sprite(
Boss.pos.x - 20,
Boss.pos.y - 15,
15,
"dynamic"
);
BossAttackSwing2 = new Sprite(
Boss.pos.x + 20,
Boss.pos.y - 15,
15,
"dynamic"
);
BossAttackSwing1.visible = false;
BossAttackSwing2.visible = false;
//Making Skeleton 1
Skeleton1 = new Sprite(40, 600, 20, 50, "dynamic");
Skeleton1.addAni("SKIdle", SkeletonIdle);
Skeleton1.addAni("SKAttack", SkeletonAttack);
Skeleton1.addAni("SKWalk", SkeletonWalk);
Skeleton1.ani.offset.y=20;
Skeleton1.visible = false;
Skeleton1.rotationLock = true;
SKRswing = new Sprite(
Skeleton1.pos.x - 20,
Skeleton1.pos.y - 15,
15,
"dynamic"
);
//Making Skeleton 2
Skeleton2 = new Sprite(815, 502, 20, 50, "dynamic");
Skeleton2.addAni("SKIdle", SkeletonIdle);
Skeleton2.addAni("SKAttack", SkeletonAttack);
Skeleton2.addAni("SKWalk", SkeletonWalk);
Skeleton2.ani.offset.y=20;
Skeleton2.visible = false;
Skeleton2.rotationLock = true;
SK2Rswing = new Sprite(
Skeleton2.pos.x - 10,
Skeleton2.pos.y - 15,
15,
"dynamic"
);
//Making Skeleton 3
Skeleton3 = new Sprite(215, 358, 20, 50, "dynamic");
Skeleton3.addAni("SKIdle", SkeletonIdle);
Skeleton3.addAni("SKAttack", SkeletonAttack);
Skeleton3.addAni("SKWalk", SkeletonWalk);
Skeleton3.ani.offset.y=20;
Skeleton3.visible = false;
Skeleton3.rotationLock = true;
SK3Rswing = new Sprite(
Skeleton3.pos.x - 10,
Skeleton3.pos.y - 15,
15,
"dynamic"
);
//Making Skeleton 4
Skeleton4 = new Sprite(715, 335, 20, 50, "dynamic");
Skeleton4.addAni("SKIdle", SkeletonIdle);
Skeleton4.addAni("SKAttack", SkeletonAttack);
Skeleton4.addAni("SKWalk", SkeletonWalk);
Skeleton4.ani.offset.y=20;
Skeleton4.visible = false;
Skeleton4.rotationLock = true;
SK4Rswing = new Sprite(
Skeleton4.pos.x - 10,
Skeleton4.pos.y - 15,
15,
"dynamic"
);
//Making Skeleton 5
Skeleton5 = new Sprite(1375, 286, 20, 50, "dynamic");
Skeleton5.addAni("SKIdle", SkeletonIdle);
Skeleton5.addAni("SKAttack", SkeletonAttack);
Skeleton5.addAni("SKWalk", SkeletonWalk);
Skeleton5.ani.offset.y=20;
Skeleton5.visible = false;
Skeleton5.rotationLock = true;
SK5Rswing = new Sprite(
Skeleton5.pos.x - 10,
Skeleton5.pos.y - 15,
15,
"dynamic"
);
SKRswing.visible = false;
SK2Rswing.visible = false;
SK3Rswing.visible = false;
SK4Rswing.visible = false;
SK5Rswing.visible = false;
slideEnergy = 100;
//create some platform sprites
platforms = new Group();
platforms.visible = false;
//game start visuals
startGame = false;
Sright.visible = false;
Standard.visible = false;
Sleft.visible = false;
coins.visible = false;
}
//Function for my Slide Energy display
function slideEnergyUse() {
slideEnergy++;
if (keyIsDown("")) {
slideEnergy--;
}
}
//Creating Boss Damage to Hero attack 1 right
function BigHealthDamage(BossAttackSwing1, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 20;
//print(Health);
}
//Creating Boss Damage to Hero attack 1 Left
function HealthDamage(BossAttackSwing2, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 20;
//print(Health);
}
//Creating Skeleton 1 Damage to Hero
function HealthDamage(SKRswing, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 0.5;
//print(Health);
}
//Creating Skeleton 2 Damage to Hero
function HealthDamage(SK2Rswing, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 0.5;
//print(Health);
}
//Creating Skeleton 3 Damage to Hero
function HealthDamage(SK3Rswing, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 0.5;
//print(Health);
}
//Creating Skeleton 4 Damage to Hero
function HealthDamage(SK4Rswing, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 0.5;
//print(Health);
}
//Creating Skeleton 5 Damage to Hero
function HealthDamage(SK5Rswing, Hero) {
if (Health == 0) {
Health = 0;
}
Health = Health - 0.5;
//print(Health);
}
//Coin Pick up function
function pickupCoins(Hero, coin) {
CoinCollectSound.play();
coin.remove();
score++;
if (Health <= 200) {
Health = Health + 25;
}
}
//Creating Boss Attack
function BossAttack() {
if (
dist(Hero.pos.x, Hero.pos.y, Boss.pos.x, Boss.pos.y) <= 75 &&
BossHealth >= 1
) {
Boss.ani = "BossAttack1";
Boss.vel.x = 0;
BossSwingInterval++;
BossSwingInterval %= 32;
if (BossSwingInterval != 2) {
return;
}
if (BossWalkDirection == true) {
BossAttackSwing1 = new Sprite(
Boss.pos.x - 30,
Boss.pos.y - 10,
10,
"dynamic"
);
BossAttackSwing1.life = 5;
BossAttackSwing1.velocity.x = -7;
BossAttackSwing1.velocity.y = 3;
BossAttackSwing1.visible = false;
} else if (BossWalkDirection == false) {
BossAttackSwing1 = new Sprite(
Boss.pos.x + 30,
Boss.pos.y - 10,
10,
"dynamic"
);
BossAttackSwing1.life = 5;
BossAttackSwing1.velocity.x = 7;
BossAttackSwing1.velocity.y = 3;
BossAttackSwing1.visible = false;
}
BossAttackSound.play();
Boss.mirror.x = true;
//BossAttackSound.play();
print("Skeleton Attacking");
} else {
Boss.ani = "BossWalk";
}
}
//Creating Boss Attack 2
//I was unable to debug this correctly to make boss Attack range recognize the correct attack pattern.
//I think this was my biggest failure in the project and I am somewhat disappointed
/*function BossAttackR() {
if (
dist(Hero.pos.x, Hero.pos.y, Boss.pos.x, Boss.pos.y) >= 100 && dist(Hero.pos.x, Hero.pos.y, Boss.pos.x, Boss.pos.y) <= 200 &&
BossHealth >= 1
) {
Boss.ani = "BossAttack2";
Boss.vel.x = 0;
BossSwingInterval++;
BossSwingInterval %= 32;
if (BossSwingInterval != 2) {
return;
}
if (BossWalkDirection == true) {
BossAttackSwing2 = new Sprite(
Boss.pos.x - 75,
Boss.pos.y - 10,
10,
"dynamic"
);
BossAttackSwing2.life = 8;
BossAttackSwing2.velocity.x = -7;
BossAttackSwing2.velocity.y = 1;
BossAttackSwing2.visible = true;
} else if (BossWalkDirection == false) {
BossAttackSwing2 = new Sprite(
Boss.pos.x + 75,
Boss.pos.y - 10,
10,
"dynamic"
);
BossAttackSwing2.life = 8;
BossAttackSwing2.velocity.x = 7;
BossAttackSwing2.velocity.y = 1;
BossAttackSwing2.visible = true;
}
//BossAttackSound.play();
Boss.mirror.x = true;
} else {
Boss.ani = "BossWalk";
}
}*/
//Creating Skeleton1 Attack
function SkeletonSwing() {
if (
dist(Hero.pos.x, Hero.pos.y, Skeleton1.pos.x, Skeleton1.pos.y) <= 75 &&
SK1Health >= 1
) {
SK1SwingInterval++;
SK1SwingInterval %= 16;
SKRswing = new Sprite(
Skeleton1.pos.x + 30,
Skeleton1.pos.y - 10,
10,
"dynamic"
);
SKRswing.life = 4;
SKRswing.velocity.x = 5;
SKRswing.velocity.y = 3;
SKRswing.visible = false;
Skeleton1.mirror.x = false;
Skeleton1.ani = "SKAttack";
Skeleton1.ani.offset.y=20;
Skeleton1.vel.x = 0;
if (SK1SwingInterval != 2) {
return;
}
SkeletonAttackSound.play();
//print("Skeleton Attacking")
} else {
Skeleton1.ani = "SKWalk";
//print("SK non aggressive")
}
}
//Creating Skeleton2 Attack
function Skeleton2Swing() {
if (
dist(Hero.pos.x, Hero.pos.y, Skeleton2.pos.x, Skeleton2.pos.y) <= 75 &&
SK2Health >= 1
) {
Skeleton2.vel.x = 0;
SK2SwingInterval++;
SK2SwingInterval %= 16;
SK2Rswing = new Sprite(
Skeleton2.pos.x - 10,
Skeleton2.pos.y - 10,
10,
"dynamic"
);
SK2Rswing.life = 4;
SK2Rswing.velocity.x = -5;
SK2Rswing.velocity.y = 3;
SK2Rswing.visible = false;
Skeleton2.mirror.x = true;
Skeleton2.ani = "SKAttack";
Skeleton2.ani.offset.y=20;
if (SK2SwingInterval != 2) {
return;
}
SkeletonAttackSound.play();
//print("Skeleton Attacking")
} else {
Skeleton2.ani = "SKWalk";
//print("SK non aggressive")
}
}
//Creating Skeleton3 Attack
function Skeleton3Swing() {
if (
dist(Hero.pos.x, Hero.pos.y, Skeleton3.pos.x, Skeleton3.pos.y) <= 75 &&
SK3Health >= 1
) {
SK3SwingInterval++;
SK3SwingInterval %= 16;
SK3Rswing = new Sprite(
Skeleton3.pos.x + 30,
Skeleton3.pos.y - 10,
10,
"dynamic"
);
SK3Rswing.life = 4;
SK3Rswing.velocity.x = 5;
SK3Rswing.velocity.y = 3;
SK3Rswing.visible = false;
Skeleton3.mirror.x = false;
Skeleton3.ani = "SKAttack";
Skeleton3.ani.offset.y=20;
Skeleton3.vel.x = 0;
if (SK3SwingInterval != 2) {
return;
}
SkeletonAttackSound.play();
//print("Skeleton Attacking")
} else {
Skeleton3.ani = "SKWalk";
//print("SK non aggressive")
}
}
//Creating Skeleton4 Attack
function Skeleton4Swing() {
if (
dist(Hero.pos.x, Hero.pos.y, Skeleton4.pos.x, Skeleton4.pos.y) <= 75 &&
SK4Health >= 1
) {
SK4SwingInterval++;
SK4SwingInterval %= 16;
SK4Rswing = new Sprite(
Skeleton4.pos.x - 10,
Skeleton4.pos.y - 10,
10,
"dynamic"
);
SK4Rswing.life = 4;
SK4Rswing.velocity.x = -5;
SK4Rswing.velocity.y = 3;
SK4Rswing.visible = false;
Skeleton4.mirror.x = true;
Skeleton4.ani = "SKAttack";
Skeleton4.ani.offset.y=20;
Skeleton4.vel.x = 0;
if (SK4SwingInterval != 2) {
return;
}
SkeletonAttackSound.play();
//print("Skeleton Attacking")
} else {
Skeleton4.ani = "SKWalk";
//print("SK non aggressive")
}
}
//Creating Skeleton5 Attack
function Skeleton5Swing() {
if (
dist(Hero.pos.x, Hero.pos.y, Skeleton5.pos.x, Skeleton5.pos.y) <= 75 &&
SK5Health >= 1
) {
SK5SwingInterval++;
SK5SwingInterval %= 16;
SK5Rswing = new Sprite(
Skeleton5.pos.x - 10,
Skeleton5.pos.y - 10,
10,
"dynamic"
);
SK5Rswing.life = 4;
SK5Rswing.velocity.x = -5;
SK5Rswing.velocity.y = 3;
SK5Rswing.visible = false;
Skeleton5.mirror.x = true;
Skeleton5.ani = "SKAttack";
Skeleton5.ani.offset.y=20;
Skeleton5.vel.x = 0;
if (SK5SwingInterval != 2) {
return;
}
SkeletonAttackSound.play();
//print("Skeleton Attacking")
} else {
Skeleton5.ani = "SKWalk";
//print("SK non aggressive")
}
}
//Boss function
function BossHealthDamage(Rswing, Boss) {
BossHealth = BossHealth - 5;
print(BossHealth);
if (BossHealth == 0) {
Boss.remove();
BossDeath = true;
}
}
//Skeleton1 Health function
function SK1HealthDamage(Lswing, Skeleton1) {
SK1Health = SK1Health - 2;
if (SK1Health == 0) {
Skeleton1.remove();
SKscore++;
}
}
//Skeleton2 Health Function
function SK2HealthDamage(Rswing, Skeleton2) {
SK2Health = SK2Health - 2;
if (SK2Health == 0) {
Skeleton2.remove();
SKscore++;
}
}
//Skeleton3 Health Function
function SK3HealthDamage(Rswing, Skeleton3) {
SK3Health = SK3Health - 2;
if (SK3Health == 0) {
Skeleton3.remove();
SKscore++;
}
}
//Skeleton4 Health Function
function SK4HealthDamage(Rswing, Skeleton4) {
SK4Health = SK4Health - 2;
if (SK4Health == 0) {
Skeleton4.remove();
SKscore++;
}
}
//Skeleton5 Health Function
function SK5HealthDamage(Rswing, Skeleton5) {
SK5Health = SK5Health - 2;
if (SK5Health == 0) {
Skeleton5.remove();
SKscore++;
}
}
//Hero Attack Swings
function AttackSwing() {
if (HeroDirection == false) {
Hero.vel.x = 0;
Hero.ani = "attack1";
SwingInterval++;
SwingInterval %= 16;
if (SwingInterval != 2) {
return;
}
Rswing = new Sprite(Hero.pos.x + 30, Hero.pos.y - 20, 15, "dynamic");
Rswing.life = 4;
Rswing.velocity.x = 10;
Rswing.velocity.y = 6;
//Rswing.visible = false;
HeroAttackSound.play();
} else if (HeroDirection == true) {
Hero.vel.x = 0;
Hero.ani = "attack1";
SwingInterval++;
SwingInterval %= 16;
if (SwingInterval != 2) {
return;
}
Lswing = new Sprite(Hero.pos.x - 20, Hero.pos.y - 15, 15, "dynamic");
Lswing.life = 4;
Lswing.velocity.x = -10;
Lswing.velocity.y = 3;
//Lswing.visible = false;
HeroAttackSound.play();
}
}
//Designing the Background to move with the Hero
function fullBG() {
image(bg1, 0, 0);
image(bg2, bgx1, 0, width + 5, height);
image(bg2, bgx2, 0, width + 5, height);
image(bg3, bgx1, 0, width + 5, height);
image(bg3, bgx2, 0, width + 5, height);
image(bg2, bgx1 - 600, 0, width + 2, height);
image(bg2, bgx2 - 600, 0, width + 2, height);
image(bg3, bgx1 - 600, 0, width + 2, height);
image(bg3, bgx2 - 600, 0, width + 2, height);
image(bg2, bgx1 - 1200, 0, width + 2, height);
image(bg2, bgx2 - 1200, 0, width + 2, height);
image(bg3, bgx1 - 1200, 0, width + 2, height);
image(bg3, bgx2 - 1200, 0, width + 2, height);
image(bg2, bgx1 + 600, 0, width + 2, height);
image(bg2, bgx2 + 600, 0, width + 2, height);
image(bg3, bgx1 + 600, 0, width + 2, height);
image(bg3, bgx2 + 600, 0, width + 2, height);
bgx1 -= bgScroll;
bgx2 -= bgScroll;
if (bgx1 < -width) {
bgx1 = width;
}
if (bgx2 < -width) {
bgx2 = width;
}
}
//Hero Slide Energy Bar
function EnergyBar() {
stroke(0);
strokeWeight(4);
noFill();
rect(50, 50, 200, 10);
noStroke();
fill(255, 215, 0);
rect(50, 50, slideEnergy * 2, 10);
}
//Creating my Health bar
function HealthBar() {
stroke(0);
strokeWeight(4);
noFill();
rect(50, 25, 200, 10);
noStroke();
fill(255, 0, 0);
rect(50, 25, Health, 10);
if (Health >= 200) {
Health = 200;
}
}
//Creating Boss Health bar
function BossHealthBar() {
stroke(0);
//print("Spawned Boss Healthbar")
strokeWeight(4);
noFill();
rect(50, 75, 360, 10);
noStroke();
fill(139, 0, 0);
rect(50, 75, BossHealth*6, 10);
if (BossHealth >= 60) {
BossHealth = 60;
}
}
//Death Screen
function Death() {
//Death Screen and Reset
if (Hero.pos.y >= 800) {
death = true;
}
if (death == true) {
allSprites.remove();
coins.removeAll();
Theme.stop();
background(0);
textFont("Veranda");
textSize(48);
textAlign(CENTER);
fill(255, 0, 0, fade);
text("You have died!", width / 2, height / 2);
text("Please try again", width / 2, height / 2 + 60);
fill(255, 0, 0, frameCount);
}
}
//Win Title. I think it may involve the use of tiles.
function Win() {
if (score >= 5 && SKscore >= 5 && BossDeath == true) {
goal1 = true;
}
if (goal1 == true) {
allSprites.remove();
Theme.stop();
VictoryTheme.play();
image(VictoryImage, 0, 0);
textFont("Veranda");
textSize(48);
textAlign(CENTER);
fill(255);
text("You have won!", width / 2, height / 2);
text("Please play again", width / 2, height / 2 + 60);
fill(255, 0, 0, frameCount);
}
}
//Game Sequencing
function draw() {
//Game Title Screen
clear();
background(255);
fullBG();
if (kb.presses("enter")) {
startGame = true;
}
if (startGame == false) {
world.gravity.y = 10;
fill(255, 255, 255, frameCount);
textFont("Veranda");
textSize(48);
textAlign(CENTER);
image(bg1, 0, 0);
image(bg2, 0, 0);
image(bg3, 0, 0);
text("Knight's Tale", width / 2 - 25, height / 6 - 25);
textSize(12);
text("Press ENTER to play", width / 2 - 30, height - 25);
}
//Starting the Game and activating motion in the background
else if (startGame == true && death == false) {
fullBG();
Hero.visible = true;
Standard.visible = true;
Sright.visible = true;
Sleft.visible = true;
coins.visible = true;
Skeleton1.visible = true;
Skeleton2.visible = true;
Skeleton3.visible = true;
Skeleton4.visible = true;
Skeleton5.visible = true;
Boss.visible = true;
//Hero Camera
camera.x = Hero.x + 100;
camera.y = Hero.y - 75;
//Jumping with Hero
if (touchingGround == true && kb.pressed("space")) {
Hero.vel.y = -10.5;
touchingGround = false;
HeroJumpSound.play();
}
//Moving Hero Left
else if (kb.pressing("left")) {
Hero.ani = "run";
Hero.vel.x = -3;
Hero.mirror.x = true;
HeroDirection = true;
bgScroll = -1;
slideEnergy++;
}
//Moving Hero Right
else if (kb.pressing("right")) {
Hero.ani = "run";
Hero.vel.x = 3;
Hero.mirror.x = false;
HeroDirection = false;
bgScroll = +1;
slideEnergy++;
} else if (kb.pressing("down")) {
Hero.ani = "idle";
Hero.vel.x = 0;
camera.y = Hero.y;
slideEnergy++;
}
//Sliding Hero Right
else if (kb.pressing("e") && Exhaust == false) {
Hero.ani = "Slide";
Hero.vel.x = 6;
//Hero.pos.x = Hero.pos.x+50
Hero.mirror.x = false;
bgScroll = +2;
slideEnergy--;
}
//Hero Slide Exhausted
else if (kb.pressing("e") && Exhaust == true) {
Hero.ani = "run";
Hero.vel.x = 1;
//Hero.pos.x = Hero.pos.x+50
Hero.mirror.x = false;
bgScroll = +0.5;
}
//Sliding Hero Left
else if (kb.pressing("q") && Exhaust == false) {
Hero.ani = "Slide";
Hero.vel.x = -6;
Hero.mirror.x = true;
bgScroll = -2;
slideEnergy = slideEnergy - 1;
}
//Hero Slide Exhausted
else if (kb.pressing("q") && Exhaust == true) {
Hero.ani = "run";
Hero.vel.x = -1;
Hero.mirror.x = true;
bgScroll = -0.5;
}
//Hero Idle
else {
Hero.vel.x = 0;
Hero.ani = "idle";
bgScroll = 0;
slideEnergy++;
}
//Hero Slide limit
if (slideEnergy >= 100) {
slideEnergy = 100;
Exhaust = false;
}
if (slideEnergy == 0) {
Exhaust = true;
}
if (Exhaust == true) {
slideEnergy++;
}
if (Health <= 0) {
Health = 0;
death = true;
}
//Attacking With Hero
if (kb.pressing("k")) {
AttackSwing();
bgScroll = 0;
}
//Adding Animation to Hero Jumps and Falls
if (Hero.vel.y < 0) {
Hero.ani = "Upjump";
touchingGround = false;
}
if (Hero.vel.y > 0) {
Hero.ani = "Downjump";
touchingGround = false;
}
if (Hero.vel.y == 0) {
setTouching();
}
//Boss Animations
if (Boss.pos.x <= 2050) {
BossWalkDirection = false;
} else if (Boss.pos.x >= 2750) {
BossWalkDirection = true;
}
if (BossWalkDirection == false) {
Boss.velocity.x = 3;
Boss.mirror.x = false;
Boss.ani = "BossWalk"; // Move right
} else if (BossWalkDirection == true) {
Boss.velocity.x = -3;
Boss.mirror.x = true; // Move left
Boss.ani = "BossWalk";
}
//Skeleton1 Animations
if (Skeleton1.pos.x <= 20) {
SkeletonWalkDirection = false;
} else if (Skeleton1.pos.x >= 60) {
SkeletonWalkDirection = true;
}
if (SkeletonWalkDirection == false) {
Skeleton1.velocity.x = 1;
Skeleton1.mirror.x = false;
Skeleton1.ani = "SKWalk"; // Move right
} else if (SkeletonWalkDirection == true) {
Skeleton1.velocity.x = -1;
Skeleton1.mirror.x = true; // Move left
Skeleton1.ani = "SKWalk";
}
//Skeleton2 Animation
if (Skeleton2.pos.x <= 800) {
Skeleton2WalkDirection = false;
} else if (Skeleton2.pos.x >= 830) {
Skeleton2WalkDirection = true;
}
if (Skeleton2WalkDirection == false) {
Skeleton2.velocity.x = 1;
Skeleton2.mirror.x = false;
Skeleton2.ani = "SKWalk"; // Move right
} else if (Skeleton2WalkDirection == true) {
Skeleton2.velocity.x = -1;
Skeleton2.mirror.x = true; // Move left
Skeleton2.ani = "SKWalk";
}
//Skeleton3 Animation
if (Skeleton3.pos.x <= 210) {
Skeleton3WalkDirection = false;
} else if (Skeleton3.pos.x >= 240) {
Skeleton3WalkDirection = true;
}
if (Skeleton3WalkDirection == false) {
Skeleton3.velocity.x = 1;
Skeleton3.mirror.x = false;
Skeleton3.ani = "SKWalk"; // Move right
} else if (Skeleton3WalkDirection == true) {
Skeleton3.velocity.x = -1;
Skeleton3.mirror.x = true; // Move left
Skeleton3.ani = "SKWalk";
}
//Skeleton4 Animation
if (Skeleton4.pos.x <= 680) {
Skeleton4WalkDirection = false;
} else if (Skeleton4.pos.x >= 750) {
Skeleton4WalkDirection = true;
}
if (Skeleton4WalkDirection == false) {
Skeleton4.velocity.x = 1;
Skeleton4.mirror.x = false;
Skeleton4.ani = "SKWalk"; // Move right
} else if (Skeleton4WalkDirection == true) {
Skeleton4.velocity.x = -1;
Skeleton4.mirror.x = true; // Move left
Skeleton4.ani = "SKWalk";
}
//Skeleton5 Animation
if (Skeleton5.pos.x <= 1250) {
Skeleton5WalkDirection = false;
} else if (Skeleton5.pos.x >= 1500) {
Skeleton5WalkDirection = true;
}
if (Skeleton5WalkDirection == false) {
Skeleton5.velocity.x = 1;
Skeleton5.mirror.x = false;
Skeleton5.ani = "SKWalk"; // Move right
} else if (Skeleton5WalkDirection == true) {
Skeleton5.velocity.x = -1;
Skeleton5.mirror.x = true; // Move left
Skeleton5.ani = "SKWalk";
}
BossAttack.ani = "BossAttack1";
BossAttack();
//BossAttackR()
Skeleton1.ani = "SKWalk";
SkeletonSwing();
Skeleton2.ani = "SKWalk";
Skeleton2Swing();
Skeleton3.ani = "SKWalk";
Skeleton3Swing();
Skeleton4.ani = "SKWalk";
Skeleton4Swing();
Skeleton5.ani = "SKWalk";
Skeleton5Swing();
Hero.overlaps(coins, pickupCoins);
Hero.colliding(Standard, setTouching);
Hero.colliding(Sright, setTouching);
Hero.colliding(Sleft, setTouching);
Lswing.overlaps(Skeleton1, SK1HealthDamage);
Rswing.overlaps(Skeleton2, SK2HealthDamage);
Lswing.overlaps(Skeleton3, SK3HealthDamage);
Rswing.overlaps(Skeleton3, SK3HealthDamage);
Lswing.overlaps(Skeleton4, SK4HealthDamage);
Rswing.overlaps(Skeleton4, SK4HealthDamage);
Lswing.overlaps(Skeleton5, SK5HealthDamage);
Rswing.overlaps(Skeleton5, SK5HealthDamage);
BossAttackSwing1.overlaps(Hero, BigHealthDamage);
//BossAttackSwing2.overlaps(Hero, BigHealthDamage);
Rswing.overlaps(Boss, BossHealthDamage);
SKRswing.overlaps(Hero, HealthDamage);
SK2Rswing.overlaps(Hero, HealthDamage);
SK3Rswing.overlaps(Hero, HealthDamage);
SK4Rswing.overlaps(Hero, HealthDamage);
SK5Rswing.overlaps(Hero, HealthDamage);
Lswing.overlaps(SKRswing);
SKRswing.overlaps(Lswing);
SK2Rswing.overlaps(Lswing);
SK3Rswing.overlaps(Lswing);
SK4Rswing.overlaps(Lswing);
SK5Rswing.overlaps(Lswing);
SKRswing.overlaps(Rswing);
SK2Rswing.overlaps(Rswing);
SK3Rswing.overlaps(Rswing);
SK4Rswing.overlaps(Rswing);
SK5Rswing.overlaps(Rswing);
EnergyBar();
HealthBar();
if (Hero.pos.x >= 1780) {
BossHealthBar();
}
Boss.debug = mouse.holding();
}
if (Hero.collided(floor1)) {
floor1.collider = "dynamic";
setTouching();
}
Win();
Death();
function setTouching() {
touchingGround = true;
}
}