Setup constants and conditions for effects.
This commit is contained in:
+11
-7
@@ -4,12 +4,15 @@ import "core:math"
|
||||
import "core:math/rand"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
SPEED_INC :: 30
|
||||
EFFECTS_SPEED :: 300
|
||||
|
||||
init_ball :: proc() -> Entity {
|
||||
return Entity{
|
||||
type = .Ball,
|
||||
active = true,
|
||||
pos = rl.Vector2{(VIEWPORT_W / 2), (VIEWPORT_H / 2)},
|
||||
speed = 100,
|
||||
speed = 200,
|
||||
max_speed = 550,
|
||||
vel = rl.Vector2{0,0},
|
||||
shape = .Circle,
|
||||
@@ -59,16 +62,17 @@ update_ball :: proc(ball: ^Entity, level: ^Level, dt: f32) {
|
||||
level.player.color = rl.Color{255,255,255,255}
|
||||
ball.tween_elapsed = 0.0
|
||||
resolve_collision(ball, level.player, true)
|
||||
if ball.speed >= EFFECTS_SPEED {
|
||||
spawn_max_speed_sparks(&level.particles, level.player, ball.pos.y, true)
|
||||
}
|
||||
|
||||
// if ball.speed >= ball.max_speed - 100 {
|
||||
// spawn_max_speed_sparks(&level.particles, ball.pos, true)
|
||||
// }
|
||||
} else if check_ball_paddle_collision(ball, level.opponent) {
|
||||
level.opponent.color = rl.Color{255,255,255,255}
|
||||
ball.tween_elapsed = 0.0
|
||||
resolve_collision(ball, level.opponent, false)
|
||||
if ball.speed >= EFFECTS_SPEED {
|
||||
spawn_max_speed_sparks(&level.particles, level.opponent, ball.pos.y, false)
|
||||
}
|
||||
} else {
|
||||
level.opponent.color = rl.Color{255,255,255,0}
|
||||
level.player.color = rl.Color{255,255,255,0}
|
||||
@@ -101,7 +105,7 @@ check_ball_paddle_collision :: proc(ball: ^Entity, paddle: Entity) -> bool {
|
||||
height = paddle.size.y,
|
||||
}
|
||||
collided := rl.CheckCollisionCircleRec(ball.pos, ball.size.x, paddle_rec)
|
||||
if collided do emit_event(.Ball_Collision)
|
||||
if collided do emit_event(Ball_Collision_Data{speed = ball.speed})
|
||||
return collided
|
||||
}
|
||||
|
||||
@@ -115,7 +119,7 @@ increment_score :: proc(score_side: ^int, max_score: int, player: bool, ball: ^E
|
||||
|
||||
increment_speed :: proc(ball: ^Entity) {
|
||||
if ball.speed <= ball.max_speed {
|
||||
ball.speed += 45
|
||||
ball.speed += SPEED_INC
|
||||
ball.vel = rl.Vector2Normalize({ball.vel.x, ball.vel.y}) * ball.speed
|
||||
}
|
||||
}
|
||||
@@ -148,7 +152,7 @@ resolve_collision :: proc(ball: ^Entity, paddle: Entity, is_player: bool) {
|
||||
}
|
||||
|
||||
update_ball_trail :: proc(ball: ^Entity, dt: f32) {
|
||||
if ball.speed < 300 {
|
||||
if ball.speed < EFFECTS_SPEED {
|
||||
ball.trail_count = 0
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user