xxxxxxxxxx
422
var charx = 150;
var chary = 250;
var bullet = false;
var bulletx = charx;
var bady = 255;
var badrespawn = 1300;
var bad2respawn = 3000;
var bad3respawn = 2200;
var badx = badrespawn;
var bady2 = 100;
var badx2 = bad2respawn;
var bady3 = 400;
var badx3 = bad3respawn;
var score = 0;
var lives = 3;
var song;
var death;
var hit;
var gameOver = false;
var wow;
var hey;
var coconut;
var start = false;
var wowww;
var power;
var space = false;
var spacey = -500;
var img;
var fight;
function preload() {
font = loadFont('PressStart2P-vaV7.ttf');
song = loadSound('moonHero.mp3');
death = loadSound('death.mp3');
hit = loadSound('MLG.mp3');
wow = loadSound('wow.mp3');
hey = loadSound('hey.mp3');
coconut = loadSound('coconut.mp3');
wowww = loadSound('wowww.mp3');
power = loadSound('power.mp3');
img = loadImage('mall.png');
fight = loadSound('fight.mp3');
}
function setup() {
createCanvas(1000, 500);
textFont(font)
textSize(25);
song.loop();
}
function draw() {
if(start == false){
push()
stroke(255);
strokeWeight(15);
textAlign(CENTER, CENTER);
textSize(170);
colorMode(HSB, 1);
fill((frameCount*0.007)%1,1,1);
rect(0,0,width,height);
fill(0,0,0,0.3);
text("Lunar",width/2,height*0.25);
text("Hero",width/2,height*0.62);
noStroke();
fill(0,0,1);
textSize(30);
text("Click to begin.", width/2,height*0.87);
pop();
if(mouseX > 250 && mouseX < 750 && mouseY > 400 && mouseY < 470){
stroke(0);
strokeWeight(5);
textSize(30);
fill(255);
textAlign(CENTER, CENTER);
text("Click to begin.", width/2,height*0.87);
}
if(mouseX > 250 && mouseX < 750 && mouseY > 400 && mouseY < 470 && mouseIsPressed){
start = true;
fight.play();
}
}
if(start == true){
if(gameOver == true){
cursor();
push();
colorMode(HSB, 1);
fill(0);
rect(0,0,width,height);
fill((frameCount*0.007)%1,1,1);
noStroke();
textSize(180);
textAlign(CENTER, CENTER);
text("GAME",width/2,height*0.25);
text("OVER",width/2,height*0.6);
textSize(25);
text("Click to restart.", width/2,height*0.92);
text("Score: "+score,width/2,height*0.825);
pop();
if(mouseX > 250 && mouseX < 750 && mouseY > 400 && mouseY < 470){
stroke(255);
strokeWeight(5);
textSize(25);
fill(255,0,0);
textAlign(CENTER, CENTER);
text("Click to restart.", width/2,height*0.92);
}
if(mouseX > 250 && mouseX < 750 && mouseY > 400 && mouseY < 470 && mouseIsPressed){
gameOver = false;
score = 0;
lives = 3;
badx = badrespawn;
badx2 = bad2respawn;
badx3 = bad3respawn;
textSize(25);
}
}
else{
background(220);
noCursor();
// if(mouseY > height){
// score = score + 1000;
// }
if(lives <= 0){
gameOver = true;
}
else{
gameOver = false;
}
// sound effects
if (score == 1000){
if(!wow.isPlaying()){
wow.play();
}
}
if (score == 5000){
if(!hey.isPlaying()){
hey.play();
}
}
if (score == 10000){
if(!wowww.isPlaying()){
wowww.play();
}
}
if (score == 15000){
if(!power.isPlaying()){
power.play();
}
}
if (score == 20000){
if(!coconut.isPlaying()){
coconut.play();
}
}
// background
for (let i = 0; i < height; i++) {
stroke(0, 0, i / 1.7);
line(0, i, width, i);
}
// score: & lives:
fill(255);
textAlign(LEFT, TOP);
text("Score: "+score, 10, 10);
textAlign(RIGHT, TOP);
text("Lives: "+lives, 990,10);
noStroke();
// bullet
if (mouseIsPressed) {
bullet = true;
}
if (bullet == true) {
fill(255,245,167);
triangle(bulletx-8, chary-2, bulletx, chary-2, bulletx, chary+4);
triangle(bulletx+8, chary-2, bulletx, chary-2, bulletx, chary+4);
triangle(bulletx-2, chary-2, bulletx, chary-8, bulletx+1, chary-2);
triangle(bulletx-6, chary+8, bulletx-2, chary-2, bulletx, chary+4);
triangle(bulletx, chary+4, bulletx+2, chary-2, bulletx+6, chary+8);
bulletx = bulletx + 10;
}
// bullet collision
if (bulletx > width) {
bullet = false;
bulletx = charx;
}
if (dist(bulletx, chary, badx, bady) < 30) {
badx = badrespawn;
bulletx = charx;
score = score + 100;
bullet = false;
hit.play();
}
if (dist(bulletx, chary, badx2, bady2) < 30) {
badx2 = bad2respawn;
bulletx = charx;
score = score + 100;
bullet = false;
hit.play();
}
if (dist(bulletx, chary, badx3, bady3) < 30) {
badx3 = bad3respawn;
bulletx = charx;
score = score + 100;
bullet = false;
hit.play();
}
// char collision
if (dist(charx, chary, badx, bady) < 80) {
badx = badrespawn;
lives--;
death.play();
}
if (dist(charx, chary, badx2, bady2) < 80) {
badx2 = badrespawn;
lives--;
death.play();
}
if (dist(charx, chary, badx3, bady3) < 80) {
badx3 = badrespawn;
lives--;
death.play();
}
// char
charx = mouseX;
chary = mouseY;
fill(200);
ellipse(charx, chary, 90);
fill(255);
rect(charx + 33, chary, 12, 30);
ellipse(charx+3, chary-3, 84);
fill(0);
ellipse(charx + 19, chary, 20);
fill(255,253,209);
ellipse(charx + 19, chary, 17);
fill(0);
ellipse(charx + 18, chary + 1, 17);
// asteroid movement
if(score < 1000){
badx = badx - 3;
badx2 = badx2 - 3;
badx3 = badx3 - 3;
}
else if(score >= 1000){
badx = badx - 5;
badx2 = badx2 - 5;
badx3 = badx3 - 5;
}
else if(score >= 5000){
badx = badx - 10;
badx2 = badx2 - 10;
badx3 = badx3 - 10;
badrespawn = 1200;
bad2respawn = 2500;
bad3respawn = 1800;
}
else if(score >= 10000){
badx = badx - 12;
badx2 = badx2 - 12;
badx3 = badx3 - 12;
badrespawn = 1200;
bad2respawn = 2000;
bad3respawn = 1600;
}
else if(score >= 12500){
badx = badx - 15;
badx2 = badx2 - 15;
badx3 = badx3 - 15;
}
else if(score >= 15000){
badx = badx - 20;
badx2 = badx2 - 20;
badx3 = badx3 - 20;
badrespawn = 1200;
bad2respawn = 2000;
bad3respawn = 1400;
}
else if(score >= 20000){
badx = badx - 25;
badx2 = badx2 - 25;
badx3 = badx3 - 25;
badrespawn = 1200;
bad2respawn = 1800;
bad3respawn = 1600;
}
else if(score >= 25000){
badx = badx - 30;
badx2 = badx2 - 30;
badx3 = badx3 - 30;
badrespawn = 1200;
bad2respawn = 1800;
bad3respawn = 1600;
}
// asteroids
strokeWeight(1);
if (badx < -200) {
badx = badrespawn;
lives--;
death.play();
}
fill(236, 215, 54);
triangle(badx, bady - 35, badx, bady + 35, badx + 100, (bady - 23) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 115, (bady) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 100, (bady + 23) + random(4));
fill(244, 179, 21);
triangle(badx, bady - 35, badx, bady + 35, badx + 82, (bady - 20) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 88, (bady) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 83, (bady + 20) + random(4));
fill(232, 141, 13);
triangle(badx, bady - 35, badx, bady + 35, badx + 60, (bady - 16) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 67, (bady) + random(4));
triangle(badx, bady - 35, badx, bady + 35, badx + 65, (bady + 16) + random(4));
fill(232, 141, 13);
ellipse(badx, bady, 70);
fill(140);
ellipse(badx, bady, 60);
fill(170);
ellipse(badx+1.5, bady-2, 56);
fill(0);
ellipse(badx - 6, bady, 30);
fill(255);
ellipse(badx - 6, bady, 26);
fill(0);
ellipse(badx - 8, bady + 1, 25)
fill(170);
triangle(badx - 21, bady + 5, badx - 21, bady - 15, badx + 15, bady - 15);
if (badx2 < -200) {
badx2 = bad2respawn;
lives--;
death.play();
}
fill(236, 215, 54);
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 100, (bady2 - 23) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 115, (bady2) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 100, (bady2 + 23) + random(4));
fill(244, 179, 21);
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 82, (bady2 - 20) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 88, (bady2) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 83, (bady2 + 20) + random(4));
fill(232, 141, 13);
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 60, (bady2 - 16) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 67, (bady2) + random(4));
triangle(badx2, bady2 - 35, badx2, bady2 + 35, badx2 + 65, (bady2 + 16) + random(4));
fill(232, 141, 13);
ellipse(badx2, bady2, 70);
fill(140);
ellipse(badx2, bady2, 60);
fill(170);
ellipse(badx2+1.5, bady2-2, 56);
fill(0);
ellipse(badx2 - 6, bady2, 30);
fill(255);
ellipse(badx2 - 6, bady2, 26);
fill(0);
ellipse(badx2 - 8, bady2 + 1, 25)
fill(170);
triangle(badx2 - 21, bady2 + 5, badx2 - 21, bady2 - 15, badx2 + 15, bady2 - 15);
if (badx3 < -200) {
badx3 = bad3respawn;
lives--;
death.play();
}
fill(236, 215, 54);
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 100, (bady3 - 23) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 115, (bady3) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 100, (bady3 + 23) + random(4));
fill(244, 179, 21);
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 82, (bady3 - 20) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 88, (bady3) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 83, (bady3 + 20) + random(4));
fill(232, 141, 13);
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 60, (bady3 - 16) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 67, (bady3) + random(4));
triangle(badx3, bady3 - 35, badx3, bady3 + 35, badx3 + 65, (bady3 + 16) + random(4));
fill(232, 141, 13);
ellipse(badx3, bady3, 70);
fill(140);
ellipse(badx3, bady3, 60);
fill(170);
ellipse(badx3+1.5, bady3-2, 56);
fill(0);
ellipse(badx3 - 6, bady3, 30);
fill(255);
ellipse(badx3 - 6, bady3, 26);
fill(0);
ellipse(badx3 - 8, bady3 + 1, 25)
fill(170);
triangle(badx3 - 21, bady3 + 5, badx3 - 21, bady3 - 15, badx3 + 15, bady3 - 15);
if(score >= 20000 && score<= 20300){
image(img,width*0.25,height*.04,img.width,img.height/1.5);
}
}
}
}