make weak enemies faster

This commit is contained in:
Rokas Puzonas 2024-02-18 23:58:45 +02:00
parent f58f3d0f86
commit f8b61d6edd

View File

@ -11,15 +11,17 @@ const friction = 0.99;
const walkForce = 4000;
const maxSpeed = 200;
const handDistance = 50;
const deathBallSize: f32 = 13;
const death_ball_size: f32 = 13;
const playerSize = 20;
const virtualWidth = 350;
const virtualHeight = 350;
const safeRadius = 500;
const spawnAreaWidth = 400;
const arenaRadius = safeRadius + spawnAreaWidth;
const shadow_offset = rl.Vector2.one().scale(8);
const enemyFriction = friction;
const Enemy = struct {
@ -41,7 +43,7 @@ const Enemy = struct {
.color = rl.YELLOW,
.size = 10.0,
.acceleration = 5000.0,
.maxSpeed = 150,
.maxSpeed = 200,
};
}
@ -295,8 +297,11 @@ fn updateEnemies(self: *Self) !void {
if (self.enemyTimer <= 0 and player.alive()) {
self.enemyTimer = 0.5 + rng.float(f32) * 2;
self.spawnedEnemiesCount += 1;
const enemyPosition = rl.Vector2.randomOnUnitCircle(rng).scale(400);
try enemies.append(Enemy.initStrong(enemyPosition));
const spawn_distance = rng.floatNorm(f32) * spawnAreaWidth/8 + spawnAreaWidth/2 + safeRadius;
const spawn_angle = rng.float(f32) * 2 * rl.PI;
const enemy_position = (rl.Vector2{ .x = spawn_distance, .y = 0 }).rotate(spawn_angle);
try enemies.append(Enemy.initStrong(enemy_position));
}
const deathBallPosition = rope.lastNodePosition();
@ -307,7 +312,7 @@ fn updateEnemies(self: *Self) !void {
self.damagePlayer();
}
if (enemy.vulnerable() and player.alive() and rl.Vector2Distance(enemy.position, deathBallPosition) < enemy.size + deathBallSize) {
if (enemy.vulnerable() and player.alive() and rl.Vector2Distance(enemy.position, deathBallPosition) < enemy.size + death_ball_size) {
self.damageEnemy(enemy);
}
@ -375,8 +380,8 @@ fn damageEnemy(self: *Self, enemy: *Enemy) void {
enemy.health -= 1;
}
enemy.invincibility = 0.5;
enemy.stunned = 0.75;
enemy.invincibility = 0.75;
enemy.stunned = 0.9;
enemy.velocity = deathBallVelocity.scale(20000);
}
@ -565,7 +570,7 @@ fn drawWorld(self: *Self) void {
rl.rlSetLineWidth(1);
var enemies = &self.enemies;
var rope = &self.rope;
const deathBallPosition = rope.nodePositions.get(rope.nodePositions.len-1);
const death_ball_position = rope.lastNodePosition();
rl.ClearBackground(rl.BLACK);
rl.DrawCircle(0, 0, arenaRadius, rl.BROWN);
@ -574,7 +579,13 @@ fn drawWorld(self: *Self) void {
rl.DrawCircleLines(0, 0, safeRadius, rl.WHITE);
rl.DrawCircleLines(0, 0, safeRadius + spawnAreaWidth, rl.WHITE);
self.drawPlayer();
for (enemies.items) |*enemy| {
rl.DrawCircleV(
enemy.position.add(shadow_offset),
enemy.size,
rgba(0, 0, 0, 100)
);
}
for (enemies.items) |*enemy| {
var color = enemy.color;
@ -582,14 +593,15 @@ fn drawWorld(self: *Self) void {
color = rl.LIGHTGRAY;
}
rl.DrawCircle(
@intFromFloat(enemy.position.x),
@intFromFloat(enemy.position.y),
rl.DrawCircleV(
enemy.position,
enemy.size,
color
);
}
self.drawPlayer();
rl.rlDrawRenderBatchActive();
rl.rlSetLineWidth(3);
for (0..(rope.nodePositions.len-1)) |i| {
@ -610,17 +622,26 @@ fn drawWorld(self: *Self) void {
rl.DrawCircle(
@intFromFloat(node.x),
@intFromFloat(node.y),
5,
rgb(194, 12, 30)
6,
rgb(110, 10, 20)
);
}
const death_ball_color = rgb(239, 48, 67);
rl.DrawCircle(
@intFromFloat(deathBallPosition.x),
@intFromFloat(deathBallPosition.y),
deathBallSize,
rgb(239, 48, 67)
@intFromFloat(death_ball_position.x),
@intFromFloat(death_ball_position.y),
death_ball_size,
death_ball_color,
);
const spikes_count = 5;
const spike_size = 8;
for (0..spikes_count) |i| {
const percent = @as(f32, @floatFromInt(i)) / spikes_count;
const extent = rl.Vector2.fromAngle(percent * 2 * rl.PI).scale(death_ball_size + spike_size);
rl.DrawLineV(death_ball_position.add(extent), death_ball_position.sub(extent), death_ball_color);
}
}
pub fn tick(self: *Self) !void {