ben vergeten wat ik heb veranderd
This commit is contained in:
1 parent
79a327ff88
commit
0a46509b6e
2 files changed
+39
-36
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>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<body style="display:flex; justify-content: center;">
|
||||
<!-- Hier staat de link naar het bestand met je eigen js code -->
|
||||
<script src="src/sketch.js"></script>
|
||||
</body>
|
||||
|
||||
+38
-35
@@ -37,23 +37,26 @@ function draw() {
|
||||
player.rotation++
|
||||
if(player.rotation > 360) player.rotation = 0
|
||||
if (gasParticleSpawners.length > 0) {
|
||||
for (let spawner of gasParticleSpawners) {
|
||||
spawner.timer--
|
||||
// maakt 1 particle aan en stopt die in gasParticles
|
||||
gasParticles.push({
|
||||
x: spawner.x,
|
||||
y: spawner.y,
|
||||
yVel: random(-0.25, 0.25),
|
||||
xVel: random(-0.25, 0.25),
|
||||
size: random(spawner.size / 25, spawner.size / 10),
|
||||
color: random(50, 80),
|
||||
transparansy: random(80, 120),
|
||||
direction: spawner.direction,
|
||||
player: spawner.player
|
||||
})
|
||||
for (let spawner of gasParticleSpawners) {
|
||||
spawner.timer--
|
||||
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({
|
||||
x: spawner.x,
|
||||
y: spawner.y,
|
||||
xVel: spawner.directionX * speed + sideX * spread,
|
||||
yVel: spawner.directionY * speed + sideY * spread,
|
||||
size: random(spawner.size / 25, spawner.size / 10),
|
||||
color: random(50, 80),
|
||||
transparansy: random(80, 120)
|
||||
});
|
||||
}
|
||||
}
|
||||
// regelt het leven van de idividuele particles
|
||||
if (gasParticles.length > 0) {
|
||||
for (let particle of gasParticles) {
|
||||
particle.transparansy = particle.transparansy - 2.5;
|
||||
@@ -71,25 +74,26 @@ function draw() {
|
||||
}
|
||||
|
||||
function drawCar(x, y, size, colorID, rotation, blinkerLeft, blinkerRight) {
|
||||
// if(direction === "up") {
|
||||
// gasParticleSpawners.push({ x: x + size / 3.5, y: y + size, size: size, player : player})
|
||||
// }
|
||||
// else if(direction === "down") {
|
||||
// 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 })
|
||||
// }
|
||||
const angle = rotation * Math.PI / 180;
|
||||
// Uitlaatpositie ten opzichte van het midden van de auto
|
||||
const exhaustX = size / 3.5;
|
||||
const exhaustY = size;
|
||||
|
||||
// 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]
|
||||
push()
|
||||
stroke(0)
|
||||
@@ -98,7 +102,6 @@ function drawCar(x, y, size, colorID, rotation, blinkerLeft, blinkerRight) {
|
||||
rectMode(CENTER)
|
||||
translate(x, y)
|
||||
rotate(rotation)
|
||||
gasParticleSpawners.push({ x: x + size / 3.5, y: y + size, size: size})
|
||||
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
|
||||
fill(0, 255, 255);
|
||||
@@ -126,7 +129,7 @@ function resetPlayer() {
|
||||
blinkerLeft: false,
|
||||
blinkerRight: false,
|
||||
playerYIndex: 1,
|
||||
rotation: 0
|
||||
rotation: Math.floor(random(0, 360))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user