first commit
This commit is contained in:
105
shrek.gd
Executable file
105
shrek.gd
Executable file
@@ -0,0 +1,105 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
var swampSound = preload("res://sounds/chaseMusic.mp3")
|
||||
|
||||
var sirenSound = preload("res://sounds/siren head.mp3")
|
||||
|
||||
var sirenActive = false
|
||||
|
||||
# -1 = do nothing
|
||||
# 0 = hunting
|
||||
# 1 = found
|
||||
# 2 = run away
|
||||
|
||||
const huntModeSpeed = 6
|
||||
const foundModeSpeed = 4.5
|
||||
const runAwayModeSpeed = 15
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
func _ready():
|
||||
visible = false
|
||||
Globals.huntMode = -1
|
||||
Globals.shrekInitPos = position
|
||||
Globals.shrekInitRotation = rotation
|
||||
|
||||
func getRandomPlace():
|
||||
return Vector2(350*((randf()*2)-1), 350*((randf()*2)-1))
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
Globals.shrekPos = position
|
||||
visible = Globals.huntMode != -1
|
||||
if Globals.huntMode == -1: return
|
||||
$siren_head_model.visible = sirenActive
|
||||
$shrek_model.visible = !sirenActive
|
||||
$eyes.visible = !sirenActive
|
||||
var x = Globals.playerPos.x - position.x
|
||||
var z = Globals.playerPos.z - position.z
|
||||
var distance = sqrt(x*x+z*z)
|
||||
if Globals.difficulty == 2:
|
||||
$eyes.visible = false
|
||||
else:
|
||||
$eyes/SpotLight3D.light_energy = float(Globals.onionsFound)/float(Globals.onionsToFind-1)
|
||||
$eyes/SpotLight3D2.light_energy = $eyes/SpotLight3D.light_energy
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
else:
|
||||
match Globals.huntMode:
|
||||
0: hunting()
|
||||
1: found()
|
||||
2: runAway()
|
||||
move_and_slide()
|
||||
Globals.shrekPos = position
|
||||
|
||||
|
||||
func hunting():
|
||||
var angle = atan2( Globals.playerPos.x - position.x, Globals.playerPos.z - position.z)
|
||||
var x = Globals.playerPos.x - position.x
|
||||
var z = Globals.playerPos.z - position.z
|
||||
var aggressionSpeed = 17.5 * (Globals.onionsFound/(Globals.onionsToFind-1))
|
||||
rotation.y = angle
|
||||
velocity.x = (huntModeSpeed+aggressionSpeed)*sin(angle)
|
||||
velocity.z = (huntModeSpeed+aggressionSpeed)*cos(angle)
|
||||
var distance = sqrt(x*x+z*z)
|
||||
if distance <= 30:
|
||||
$AudioStreamPlayer3D.stream = swampSound if !sirenActive else sirenSound
|
||||
$AudioStreamPlayer3D.play()
|
||||
Globals.huntMode = 1
|
||||
|
||||
|
||||
func found():
|
||||
var angle = atan2( Globals.playerPos.x - position.x, Globals.playerPos.z - position.z)
|
||||
var x = Globals.playerPos.x - position.x
|
||||
var z = Globals.playerPos.z - position.z
|
||||
var aggressionSpeed = 0.5 * (Globals.onionsFound/(Globals.onionsToFind-1))
|
||||
|
||||
var calcSpeed = foundModeSpeed+aggressionSpeed if !sirenActive else 6.5
|
||||
|
||||
rotation.y = angle
|
||||
velocity.x = (calcSpeed)*sin(angle)
|
||||
velocity.z = (calcSpeed)*cos(angle)
|
||||
var distance = sqrt(x*x+z*z)
|
||||
if distance >= (35 + (15 * (Globals.onionsFound/(Globals.onionsToFind-1)))) or !$AudioStreamPlayer3D.playing:
|
||||
Globals.runTo = getRandomPlace()
|
||||
$AudioStreamPlayer3D.stop()
|
||||
Globals.huntMode = 2
|
||||
|
||||
func runAway():
|
||||
var x = Globals.runTo.x - position.x
|
||||
var z = Globals.runTo.y - position.z
|
||||
var angle = atan2(x, z)
|
||||
rotation.y = angle
|
||||
velocity.x = runAwayModeSpeed*sin(angle)
|
||||
velocity.z = runAwayModeSpeed*cos(angle)
|
||||
var distance = sqrt(x*x+z*z)
|
||||
if distance <= 10:
|
||||
Globals.huntMode = 0
|
||||
sirenActive = randf()<(1.0/(30-(20*(Globals.onionsFound/(Globals.onionsToFind-1)))))
|
||||
|
||||
|
||||
func _on_area_3d_body_entered(body):
|
||||
if body.is_in_group("player") && Globals.huntMode == 1:
|
||||
Globals.gameOver(true)
|
||||
Reference in New Issue
Block a user