ben vergeten wat ik heb veranderd
This commit is contained in:
1 parent
79a327ff88
commit
0a46509b6e
2 files changed
+32
-29
No files matched your search
@@ -7,7 +7,7 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.1/p5.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.1/p5.js"></script>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body style="display:flex; justify-content: center;">
|
||||||
<!-- Hier staat de link naar het bestand met je eigen js code -->
|
<!-- Hier staat de link naar het bestand met je eigen js code -->
|
||||||
<script src="src/sketch.js"></script>
|
<script src="src/sketch.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+31
-28
@@ -39,21 +39,24 @@ function draw() {
|
|||||||
if (gasParticleSpawners.length > 0) {
|
if (gasParticleSpawners.length > 0) {
|
||||||
for (let spawner of gasParticleSpawners) {
|
for (let spawner of gasParticleSpawners) {
|
||||||
spawner.timer--
|
spawner.timer--
|
||||||
// maakt 1 particle aan en stopt die in gasParticles
|
const speed = random(-0.5, 0.5);
|
||||||
|
const spread = random(-0.3, 0.3);
|
||||||
|
|
||||||
|
// Een beetje spreiding zijwaarts, ook gedraaid met de auto
|
||||||
|
const sideX = spawner.directionY;
|
||||||
|
const sideY = -spawner.directionX;
|
||||||
|
|
||||||
gasParticles.push({
|
gasParticles.push({
|
||||||
x: spawner.x,
|
x: spawner.x,
|
||||||
y: spawner.y,
|
y: spawner.y,
|
||||||
yVel: random(-0.25, 0.25),
|
xVel: spawner.directionX * speed + sideX * spread,
|
||||||
xVel: random(-0.25, 0.25),
|
yVel: spawner.directionY * speed + sideY * spread,
|
||||||
size: random(spawner.size / 25, spawner.size / 10),
|
size: random(spawner.size / 25, spawner.size / 10),
|
||||||
color: random(50, 80),
|
color: random(50, 80),
|
||||||
transparansy: random(80, 120),
|
transparansy: random(80, 120)
|
||||||
direction: spawner.direction,
|
});
|
||||||
player: spawner.player
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// regelt het leven van de idividuele particles
|
|
||||||
if (gasParticles.length > 0) {
|
if (gasParticles.length > 0) {
|
||||||
for (let particle of gasParticles) {
|
for (let particle of gasParticles) {
|
||||||
particle.transparansy = particle.transparansy - 2.5;
|
particle.transparansy = particle.transparansy - 2.5;
|
||||||
@@ -71,25 +74,26 @@ function draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawCar(x, y, size, colorID, rotation, blinkerLeft, blinkerRight) {
|
function drawCar(x, y, size, colorID, rotation, blinkerLeft, blinkerRight) {
|
||||||
// if(direction === "up") {
|
const angle = rotation * Math.PI / 180;
|
||||||
// gasParticleSpawners.push({ x: x + size / 3.5, y: y + size, size: size, player : player})
|
// Uitlaatpositie ten opzichte van het midden van de auto
|
||||||
// }
|
const exhaustX = size / 3.5;
|
||||||
// else if(direction === "down") {
|
const exhaustY = size;
|
||||||
// gasParticleSpawners.push({ x: x - size / 3.5, y: y - size, size: size, player : player })
|
|
||||||
// }
|
|
||||||
// else if(direction === "left") {
|
|
||||||
// gasParticleSpawners.push({ x: x + size, y: y - size / 3.5, size: size, player : player })
|
|
||||||
// }
|
|
||||||
// else if(direction === "right") {
|
|
||||||
// gasParticleSpawners.push({ x: x - size, y: y + size / 3.5, size: size, player : player })
|
|
||||||
// }
|
|
||||||
// else if(direction === "rightUp") {
|
|
||||||
// gasParticleSpawners.push({ x: x - size + size * 0.25, y: y + size / 3.5 + size * 0.35, size: size, player : player })
|
|
||||||
// }
|
|
||||||
// else if(direction === "rightDown") {
|
|
||||||
// gasParticleSpawners.push({ x: x - size + size * 0.075, y: y + size / 3.5 - size * 0.4, size: size, player : player })
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// Roteer de uitlaatpositie mee met de auto
|
||||||
|
const rotatedExhaustX = exhaustX * Math.cos(angle) - exhaustY * Math.sin(angle);
|
||||||
|
const rotatedExhaustY = exhaustX * Math.sin(angle) + exhaustY * Math.cos(angle);
|
||||||
|
|
||||||
|
// Richting achteruit, vanaf de achterkant van de auto
|
||||||
|
const directionX = -Math.sin(angle);
|
||||||
|
const directionY = Math.cos(angle);
|
||||||
|
|
||||||
|
gasParticleSpawners.push({
|
||||||
|
x: x + rotatedExhaustX,
|
||||||
|
y: y + rotatedExhaustY,
|
||||||
|
size,
|
||||||
|
directionX,
|
||||||
|
directionY
|
||||||
|
});
|
||||||
let color = carColors[colorID]
|
let color = carColors[colorID]
|
||||||
push()
|
push()
|
||||||
stroke(0)
|
stroke(0)
|
||||||
@@ -98,7 +102,6 @@ function drawCar(x, y, size, colorID, rotation, blinkerLeft, blinkerRight) {
|
|||||||
rectMode(CENTER)
|
rectMode(CENTER)
|
||||||
translate(x, y)
|
translate(x, y)
|
||||||
rotate(rotation)
|
rotate(rotation)
|
||||||
gasParticleSpawners.push({ x: x + size / 3.5, y: y + size, size: size})
|
|
||||||
fill(color.red, color.green, color.blue);
|
fill(color.red, color.green, color.blue);
|
||||||
rect(0, 0, size, size * 1.6, size / 20, size / 20, size / 20, size / 20); // maakt de body
|
rect(0, 0, size, size * 1.6, size / 20, size / 20, size / 20, size / 20); // maakt de body
|
||||||
fill(0, 255, 255);
|
fill(0, 255, 255);
|
||||||
@@ -126,7 +129,7 @@ function resetPlayer() {
|
|||||||
blinkerLeft: false,
|
blinkerLeft: false,
|
||||||
blinkerRight: false,
|
blinkerRight: false,
|
||||||
playerYIndex: 1,
|
playerYIndex: 1,
|
||||||
rotation: 0
|
rotation: Math.floor(random(0, 360))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user