Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generalize dentata-snakes bounce logic into a util function #85

Merged
merged 9 commits into from
Feb 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data merge storage utils:damage { damage: 2.5 }
function entity:utils/damage with storage utils:damage

# Bounce if hit edge of arena
execute unless entity @s[x=-21,dx=42,z=-3,dz=21] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/bounce
execute unless entity @s[x=-21,dx=42,z=-3,dz=21] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/maybe_bounce

# Move forward at defined `attack.speed.z` velocity
execute store result storage utils:move z float 0.01 run scoreboard players get @s attack.speed.z
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# If we bounced, play bounce sound
# Only the bullet-head makes bounce sounds/shakes the player's screen (see `maybe_bounce.mcfunction`)
playsound omega-flowey:attack.dentata-snakes.bounce hostile @a ~ ~ ~ 5 1
execute as @a unless entity @s[team=!player,team=!dead,team=!spectator] at @s run function entity:utils/shake_screen

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't bounce if we've already escaped the arena (past top wall)
execute if entity @s[x=-1000,dx=2000,y=30,dy=10,z=-4,dz=-1000,tag=can-escape-arena] run return 0

# TODO(42): adjust arena bounds based on new animated java model (visually, it clips into the wall right now)
data merge storage attack:dentata-snakes.bounce { x_negative_x: -21, x_negative_dx: 50 }
data merge storage attack:dentata-snakes.bounce { x_positive_x: 21, x_positive_dx: -50 }
data merge storage attack:dentata-snakes.bounce { z_negative_z: -3, z_negative_dz: 25 }
data merge storage attack:dentata-snakes.bounce { z_positive_z: 18, z_positive_dz: -25 }
data merge storage attack:dentata-snakes.bounce { y: 30, dy: 10 }
data merge storage attack:dentata-snakes.bounce { command_after_bouncing: 'execute if entity @s[tag=attack-bullet-head] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/after_bounce_as_bullet_head' }

function entity:utils/bounce with storage attack:dentata-snakes.bounce
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Reflects an entity's facing direction (yaw only) against the walls of a specified bounding box
# i.e. (flips x-direction/z-direction as necessary)
# ---
# params:
# * x_negative_x: x coordinate for the bounding box's safe region outside of the -X wall
# * x_negative_dx: x width for the bounding box's safe region outside of the -X wall
# * x_positive_x: x coordinate for the bounding box's safe region outside of the +X wall
# * x_positive_dx: x width for the bounding box's safe region outside of the +X wall
# * z_negative_z: z coordinate for the bounding box's safe region outside of the -Z wall
# * z_negative_dz: z width for the bounding box's safe region outside of the -Z wall
# * z_positive_z: z coordinate for the bounding box's safe region outside of the +Z wall
# * z_positive_dz: z width for the bounding box's safe region outside of the +Z wall
# * y/dy: generous y lower-bound + height for each bounding box
# (y/dy need to be generous because of target selectors being janky with volume selections)

# Save initial yaw
execute store result score @s util.bounce.yaw.initial run data get entity @s Rotation[0]
scoreboard players operation @s util.bounce.yaw = @s util.bounce.yaw.initial

# -X wall
$execute unless entity @s[x=$(x_negative_x),dx=$(x_negative_dx),y=$(y),dy=$(dy),z=-1000,dz=2000] if entity @s[y_rotation=0..180] run function entity:utils/bounce/x_negative

# +X wall
$execute unless entity @s[x=$(x_positive_x),dx=$(x_positive_dx),y=$(y),dy=$(dy),z=-1000,dz=2000] if entity @s[y_rotation=-180..0] run function entity:utils/bounce/x_positive

# -Z wall
$execute unless entity @s[x=-1000,dx=2000,y=$(y),dy=$(dy),z=$(z_negative_z),dz=$(z_negative_dz)] unless entity @s[y_rotation=-90..90] run function entity:utils/bounce/z_negative

# +Z wall
$execute unless entity @s[x=-1000,dx=2000,y=$(y),dy=$(dy),z=$(z_positive_z),dz=$(z_positive_dz)] if entity @s[y_rotation=-90..90] run function entity:utils/bounce/z_positive

# Store bounced angle
execute store result entity @s Rotation[0] float 1 run scoreboard players get @s util.bounce.yaw

# If `util.bounce.yaw != util.bounce.yaw.initial`, we bounced
$execute unless score @s util.bounce.yaw = @s util.bounce.yaw.initial run $(command_after_bouncing)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scoreboard players operation @s util.bounce.yaw *= #-1 mathf.const
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scoreboard players operation @s util.bounce.yaw -= #180 mathf.const
scoreboard players operation @s util.bounce.yaw *= #-1 mathf.const
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function entity:utils/bounce/shared/x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function entity:utils/bounce/shared/x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function entity:utils/bounce/shared/z
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function entity:utils/bounce/shared/z
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ scoreboard objectives add player.shake.yaw dummy
scoreboard objectives add random dummy
scoreboard objectives add random.min dummy
scoreboard objectives add random.range dummy

# the final yaw an entity has after running bounce calculations
scoreboard objectives add util.bounce.yaw dummy
# the initial yaw an entity starts with before running bounce calculations
scoreboard objectives add util.bounce.yaw.initial dummy