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 "core:math/rand"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
SPEED_INC :: 30
|
||||||
|
EFFECTS_SPEED :: 300
|
||||||
|
|
||||||
init_ball :: proc() -> Entity {
|
init_ball :: proc() -> Entity {
|
||||||
return Entity{
|
return Entity{
|
||||||
type = .Ball,
|
type = .Ball,
|
||||||
active = true,
|
active = true,
|
||||||
pos = rl.Vector2{(VIEWPORT_W / 2), (VIEWPORT_H / 2)},
|
pos = rl.Vector2{(VIEWPORT_W / 2), (VIEWPORT_H / 2)},
|
||||||
speed = 100,
|
speed = 200,
|
||||||
max_speed = 550,
|
max_speed = 550,
|
||||||
vel = rl.Vector2{0,0},
|
vel = rl.Vector2{0,0},
|
||||||
shape = .Circle,
|
shape = .Circle,
|
||||||
@@ -59,16 +62,17 @@ update_ball :: proc(ball: ^Entity, level: ^Level, dt: f32) {
|
|||||||
level.player.color = rl.Color{255,255,255,255}
|
level.player.color = rl.Color{255,255,255,255}
|
||||||
ball.tween_elapsed = 0.0
|
ball.tween_elapsed = 0.0
|
||||||
resolve_collision(ball, level.player, true)
|
resolve_collision(ball, level.player, true)
|
||||||
|
if ball.speed >= EFFECTS_SPEED {
|
||||||
spawn_max_speed_sparks(&level.particles, level.player, ball.pos.y, true)
|
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) {
|
} else if check_ball_paddle_collision(ball, level.opponent) {
|
||||||
level.opponent.color = rl.Color{255,255,255,255}
|
level.opponent.color = rl.Color{255,255,255,255}
|
||||||
ball.tween_elapsed = 0.0
|
ball.tween_elapsed = 0.0
|
||||||
resolve_collision(ball, level.opponent, false)
|
resolve_collision(ball, level.opponent, false)
|
||||||
|
if ball.speed >= EFFECTS_SPEED {
|
||||||
spawn_max_speed_sparks(&level.particles, level.opponent, ball.pos.y, false)
|
spawn_max_speed_sparks(&level.particles, level.opponent, ball.pos.y, false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
level.opponent.color = rl.Color{255,255,255,0}
|
level.opponent.color = rl.Color{255,255,255,0}
|
||||||
level.player.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,
|
height = paddle.size.y,
|
||||||
}
|
}
|
||||||
collided := rl.CheckCollisionCircleRec(ball.pos, ball.size.x, paddle_rec)
|
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
|
return collided
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +119,7 @@ increment_score :: proc(score_side: ^int, max_score: int, player: bool, ball: ^E
|
|||||||
|
|
||||||
increment_speed :: proc(ball: ^Entity) {
|
increment_speed :: proc(ball: ^Entity) {
|
||||||
if ball.speed <= ball.max_speed {
|
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
|
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) {
|
update_ball_trail :: proc(ball: ^Entity, dt: f32) {
|
||||||
if ball.speed < 300 {
|
if ball.speed < EFFECTS_SPEED {
|
||||||
ball.trail_count = 0
|
ball.trail_count = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user