Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-2/cuujooceevii61
This commit is contained in:
60
web/game.js
60
web/game.js
@@ -45,11 +45,10 @@ let x4;
|
|||||||
let y4;
|
let y4;
|
||||||
let x5;
|
let x5;
|
||||||
let y5;
|
let y5;
|
||||||
|
let homescreenOn = false;
|
||||||
let chosen = false;
|
let chosen = false;
|
||||||
|
|
||||||
let bulletAmount = 10;
|
let bulletAmount = 10;
|
||||||
|
|
||||||
|
|
||||||
//let myBullet = new bullet();
|
//let myBullet = new bullet();
|
||||||
// the function setup() is called once when the page is loaded
|
// the function setup() is called once when the page is loaded
|
||||||
function setup() {
|
function setup() {
|
||||||
@@ -71,10 +70,12 @@ function score() {
|
|||||||
function life() {
|
function life() {
|
||||||
textAlign(CENTER);
|
textAlign(CENTER);
|
||||||
if (lives == 0) {
|
if (lives == 0) {
|
||||||
|
push();
|
||||||
fill(255, 0, 0);
|
fill(255, 0, 0);
|
||||||
textSize(40);
|
textSize(40);
|
||||||
textAlign(CENTER);
|
textAlign(CENTER);
|
||||||
text("Game Over", width/2, height/2);
|
text("Game Over", width/2, height/2);
|
||||||
|
pop();
|
||||||
if (key == ' ') {
|
if (key == ' ') {
|
||||||
lives = 1;
|
lives = 1;
|
||||||
time = 0;
|
time = 0;
|
||||||
@@ -142,7 +143,6 @@ async function Movementloop() {
|
|||||||
|
|
||||||
// the function draw() is called every frame
|
// the function draw() is called every frame
|
||||||
function draw() {
|
function draw() {
|
||||||
textSize(10);
|
|
||||||
keyPressed();
|
keyPressed();
|
||||||
life();
|
life();
|
||||||
// draw background
|
// draw background
|
||||||
@@ -150,18 +150,35 @@ function draw() {
|
|||||||
background(0, 0, 0, 100);
|
background(0, 0, 0, 100);
|
||||||
if (!(lives == 0)) {
|
if (!(lives == 0)) {
|
||||||
// draw player
|
// draw player
|
||||||
|
push();
|
||||||
fill(0, 255, 255)
|
fill(0, 255, 255)
|
||||||
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
|
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
|
||||||
|
pop();
|
||||||
movementCheck()
|
movementCheck()
|
||||||
// draw boss
|
// draw boss
|
||||||
|
push();
|
||||||
fill(255, 165, 0)
|
fill(255, 165, 0)
|
||||||
circle(x2, y2, 50);
|
circle(x2, y2, 50);
|
||||||
|
pop();
|
||||||
if (hasMoved == true) {
|
if (hasMoved == true) {
|
||||||
|
push();
|
||||||
score();
|
score();
|
||||||
|
textSize(10);
|
||||||
|
textAlign(LEFT);
|
||||||
|
fill(255, 0, 255)
|
||||||
|
text(int(time), 10, 20);
|
||||||
|
pop();
|
||||||
|
}
|
||||||
|
if (hasMoved == false) {
|
||||||
|
push();
|
||||||
|
score();
|
||||||
|
textSize(10);
|
||||||
|
textAlign(LEFT);
|
||||||
|
fill(255, 0, 255)
|
||||||
|
text(0, 10, 20);
|
||||||
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
textAlign(LEFT);
|
|
||||||
text(int(time), 10, 20);
|
|
||||||
|
|
||||||
randomAttackPattern()
|
randomAttackPattern()
|
||||||
if (patern == 2) {
|
if (patern == 2) {
|
||||||
@@ -177,9 +194,14 @@ function draw() {
|
|||||||
y4 = map(cosY, -1, 1, playerPosY - 100, playerPosY + 100);
|
y4 = map(cosY, -1, 1, playerPosY - 100, playerPosY + 100);
|
||||||
x5 = map(sinX, -1, 1, playerPosX - 100, playerPosX + 100);
|
x5 = map(sinX, -1, 1, playerPosX - 100, playerPosX + 100);
|
||||||
y5 = map(-cosY, -1, 1, playerPosY - 100, playerPosY + 100);
|
y5 = map(-cosY, -1, 1, playerPosY - 100, playerPosY + 100);
|
||||||
|
push();
|
||||||
|
fill(255, 165, 0)
|
||||||
circle(x3, y3, 50);
|
circle(x3, y3, 50);
|
||||||
circle(x4, y4, 50);
|
circle(x4, y4, 50);
|
||||||
circle(x5, y5, 50);
|
circle(x5, y5, 50);
|
||||||
|
pop();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
x2 = width / 2;
|
x2 = width / 2;
|
||||||
y2 = 100;
|
y2 = 100;
|
||||||
@@ -198,6 +220,24 @@ function draw() {
|
|||||||
//blijf de bullet tekenen zolang hit false is
|
//blijf de bullet tekenen zolang hit false is
|
||||||
bullets = bullets.filter(bullet => !bullet.hit);
|
bullets = bullets.filter(bullet => !bullet.hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (homescreenOn == true) {
|
||||||
|
homescreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function randPatern () {
|
||||||
|
patern = random([1,2]);
|
||||||
|
chosen = true;
|
||||||
|
if (patern == 1) {
|
||||||
|
await wait(3000);
|
||||||
|
chosen = false;
|
||||||
|
}
|
||||||
|
if (patern == 2) {
|
||||||
|
await wait(5000);
|
||||||
|
chosen = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
async function randPatern () {
|
async function randPatern () {
|
||||||
patern = random([1,2]);
|
patern = random([1,2]);
|
||||||
@@ -300,4 +340,12 @@ function spawnRandomBullet() {
|
|||||||
}
|
}
|
||||||
angle = 0;
|
angle = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function homescreen() {
|
||||||
|
push()
|
||||||
|
circle(100, 100, 100)
|
||||||
|
color(255, 0, 255, 200)
|
||||||
|
pop()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user