Salto a 310
This commit is contained in:
parent
4728fa138b
commit
2f57e4ca3f
@ -2,21 +2,21 @@ extends CharacterBody2D
|
|||||||
|
|
||||||
|
|
||||||
const SPEED = 110.0
|
const SPEED = 110.0
|
||||||
const JUMP_VELOCITY = -300.0
|
const JUMP_VELOCITY = -310.0
|
||||||
|
|
||||||
enum player_states {idle, run, jump, crouch, aimUp, water, dead}
|
enum player_states {idle, run, jump, crouch, aimUp, water, dead}
|
||||||
var current_state = player_states.idle
|
var current_state = player_states.idle
|
||||||
|
|
||||||
var canShot = true
|
var canShot = true
|
||||||
|
|
||||||
var normalBullet = preload("res://scenes/bullet_normal.tscn")
|
var normalBullet = preload(“res://scenes/bullet_normal.tscn”)
|
||||||
var bulletP1 = preload("res://scenes/bullet_p1.tscn")
|
var bulletP1 = preload(“res://scenes/bullet_p1.tscn”)
|
||||||
var bulletP2 = preload("res://scenes/bullet_p2.tscn")
|
var bulletP2 = preload(“res://scenes/bullet_p2.tscn”)
|
||||||
|
|
||||||
var currentBullet = normalBullet
|
var currentBullet = normalBullet
|
||||||
|
|
||||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
|
||||||
|
|
||||||
var direction
|
var direction
|
||||||
var vDirection
|
var vDirection
|
||||||
@ -25,45 +25,45 @@ var minCamera
|
|||||||
var maxCamera
|
var maxCamera
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var allPlayers = get_tree().get_nodes_in_group("player")
|
var allPlayers = get_tree().get_nodes_in_group(“player”)
|
||||||
for p in allPlayers:
|
for p in allPlayers:
|
||||||
add_collision_exception_with(p)
|
add_collision_exception_with(p)
|
||||||
var cam = get_tree().get_nodes_in_group("camera")
|
var cam = get_tree().get_nodes_in_group(“camera”)
|
||||||
minCamera = cam[0].get_node("min")
|
minCamera = cam[0].get_node(“min”)
|
||||||
maxCamera = cam[0].get_node("max")
|
maxCamera = cam[0].get_node(“max”)
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor() && current_state != player_states.water:
|
if not is_on_floor() && current_state != player_states.water:
|
||||||
velocity.y += gravity * delta
|
velocity.y += gravity * delta
|
||||||
if(current_state != player_states.dead):
|
if(current_state != player_states.dead):
|
||||||
$AnimationPlayer.play("jump")
|
$AnimationPlayer.play(“jump”)
|
||||||
current_state = player_states.jump
|
current_state = player_states.jump
|
||||||
else:
|
else:
|
||||||
get_tree().get_nodes_in_group("spawnPoint")[0].global_position.x = global_position.x
|
get_tree().get_nodes_in_group(“spawnPoint”)[0].global_position.x = global_position.x
|
||||||
|
|
||||||
# Handle Jump.
|
# Handle Jump.
|
||||||
if(current_state != player_states.dead):
|
if(current_state != player_states.dead):
|
||||||
if Input.is_action_just_pressed("H") and (is_on_floor() || current_state == player_states.water):
|
if Input.is_action_just_pressed(“H”) and (is_on_floor() || current_state == player_states.water):
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
current_state = player_states.jump
|
current_state = player_states.jump
|
||||||
|
|
||||||
direction = Input.get_axis("A", "D")
|
direction = Input.get_axis(“A”, “D”)
|
||||||
vDirection = Input.get_axis("W", "S")
|
vDirection = Input.get_axis(“W”, “S”)
|
||||||
|
|
||||||
if(vDirection):
|
if(vDirection):
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if vDirection > 0:
|
if vDirection > 0:
|
||||||
if(current_state == player_states.idle):
|
if(current_state == player_states.idle):
|
||||||
$AnimationPlayer.play("crouch")
|
$AnimationPlayer.play(“crouch”)
|
||||||
current_state = player_states.crouch
|
current_state = player_states.crouch
|
||||||
else:
|
else:
|
||||||
if(current_state == player_states.idle):
|
if(current_state == player_states.idle):
|
||||||
$AnimationPlayer.play("aim_up")
|
$AnimationPlayer.play(“aim_up”)
|
||||||
current_state = player_states.aimUp
|
current_state = player_states.aimUp
|
||||||
elif current_state == player_states.water:
|
elif current_state == player_states.water:
|
||||||
if(vDirection > 0):
|
if(vDirection > 0):
|
||||||
$AnimationPlayer.play("swim_hide")
|
$AnimationPlayer.play(“swim_hide”)
|
||||||
else:
|
else:
|
||||||
if current_state == player_states.crouch || current_state == player_states.aimUp:
|
if current_state == player_states.crouch || current_state == player_states.aimUp:
|
||||||
current_state = player_states.idle
|
current_state = player_states.idle
|
||||||
@ -74,32 +74,32 @@ func _physics_process(delta):
|
|||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if(!vDirection):
|
if(!vDirection):
|
||||||
if(current_state != player_states.water):
|
if(current_state != player_states.water):
|
||||||
$AnimationPlayer.play("run")
|
$AnimationPlayer.play(“run”)
|
||||||
current_state = player_states.run
|
current_state = player_states.run
|
||||||
else:
|
else:
|
||||||
$AnimationPlayer.play("swim")
|
$AnimationPlayer.play(“swim”)
|
||||||
elif(current_state == player_states.water):
|
elif(current_state == player_states.water):
|
||||||
$AnimationPlayer.play("swim")
|
$AnimationPlayer.play(“swim”)
|
||||||
elif(vDirection > 0):
|
elif(vDirection > 0):
|
||||||
$AnimationPlayer.play("down_right")
|
$AnimationPlayer.play(“down_right”)
|
||||||
current_state = player_states.run
|
current_state = player_states.run
|
||||||
elif(vDirection < 0):
|
elif(vDirection < 0):
|
||||||
$AnimationPlayer.play("up_right")
|
$AnimationPlayer.play(“up_right”)
|
||||||
current_state = player_states.run
|
current_state = player_states.run
|
||||||
elif (current_state == player_states.water):
|
elif (current_state == player_states.water):
|
||||||
if(!vDirection):
|
if(!vDirection):
|
||||||
$AnimationPlayer.play("swim")
|
$AnimationPlayer.play(“swim”)
|
||||||
$spr.flip_h = (direction > 0)
|
$spr.flip_h = (direction > 0)
|
||||||
else:
|
else:
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
if is_on_floor() && current_state != player_states.aimUp:
|
if is_on_floor() && current_state != player_states.aimUp:
|
||||||
if(current_state != player_states.water):
|
if(current_state != player_states.water):
|
||||||
$AnimationPlayer.play("idle")
|
$AnimationPlayer.play(“idle”)
|
||||||
current_state = player_states.idle
|
current_state = player_states.idle
|
||||||
else:
|
else:
|
||||||
$AnimationPlayer.play("swim_idle")
|
$AnimationPlayer.play(“swim_idle”)
|
||||||
elif(current_state == player_states.water && !vDirection):
|
elif(current_state == player_states.water && !vDirection):
|
||||||
$AnimationPlayer.play("swim_idle")
|
$AnimationPlayer.play(“swim_idle”)
|
||||||
|
|
||||||
if(global_position.x < minCamera.global_position.x && velocity.x < 0):
|
if(global_position.x < minCamera.global_position.x && velocity.x < 0):
|
||||||
velocity.x = 0
|
velocity.x = 0
|
||||||
@ -111,51 +111,51 @@ func _physics_process(delta):
|
|||||||
if(collision):
|
if(collision):
|
||||||
for i in get_slide_collision_count():
|
for i in get_slide_collision_count():
|
||||||
var collidedObj = get_slide_collision(i)
|
var collidedObj = get_slide_collision(i)
|
||||||
if(collidedObj.get_collider().is_in_group("water")):
|
if(collidedObj.get_collider().is_in_group(“water”)):
|
||||||
current_state = player_states.water
|
current_state = player_states.water
|
||||||
elif(collidedObj.get_collider().is_in_group("powerup")):
|
elif(collidedObj.get_collider().is_in_group(“powerup”)):
|
||||||
currentBullet = get("bulletP" + str(collidedObj.get_collider().powerType))
|
currentBullet = get(“bulletP” + str(collidedObj.get_collider().powerType))
|
||||||
collidedObj.get_collider().queue_free()
|
collidedObj.get_collider().queue_free()
|
||||||
elif(collidedObj.get_collider().is_in_group("enemy") || collidedObj.get_collider().is_in_group("enemy_bullet")):
|
elif(collidedObj.get_collider().is_in_group(“enemy”) || collidedObj.get_collider().is_in_group(“enemy_bullet”)):
|
||||||
death()
|
death()
|
||||||
|
|
||||||
if(Input.is_action_just_pressed("G") && canShot):
|
if(Input.is_action_just_pressed(“G”) && canShot):
|
||||||
var newBullet = currentBullet.instantiate()
|
var newBullet = currentBullet.instantiate()
|
||||||
var lvl = get_tree().get_first_node_in_group("level")
|
var lvl = get_tree().get_first_node_in_group(“level”)
|
||||||
lvl.add_child(newBullet)
|
lvl.add_child(newBullet)
|
||||||
var faceDirection = getFacingDirection()
|
var faceDirection = getFacingDirection()
|
||||||
for c in newBullet.get_child_count():
|
for c in newBullet.get_child_count():
|
||||||
newBullet.get_child(c).setVelocity(faceDirection)
|
newBullet.get_child(c).setVelocity(faceDirection)
|
||||||
newBullet.get_child(c).add_to_group("id_p2")
|
newBullet.get_child(c).add_to_group(“id_p2”)
|
||||||
newBullet.global_position = get_node("SpawnPositions/Aim_" + faceDirection).global_position
|
newBullet.global_position = get_node(“SpawnPositions/Aim_” + faceDirection).global_position
|
||||||
canShot = false
|
canShot = false
|
||||||
$Timer.start()
|
$Timer.start()
|
||||||
|
|
||||||
|
|
||||||
func getFacingDirection():
|
func getFacingDirection():
|
||||||
var fDirection = ""
|
var fDirection = “”
|
||||||
|
|
||||||
if(!vDirection && !direction):
|
if(!vDirection && !direction):
|
||||||
if($spr.flip_h):
|
if($spr.flip_h):
|
||||||
fDirection = "Right"
|
fDirection = “Right”
|
||||||
else:
|
else:
|
||||||
fDirection = "Left"
|
fDirection = “Left”
|
||||||
elif(direction):
|
elif(direction):
|
||||||
if(direction > 0):
|
if(direction > 0):
|
||||||
fDirection = "Right"
|
fDirection = “Right”
|
||||||
else:
|
else:
|
||||||
fDirection = "Left"
|
fDirection = “Left”
|
||||||
|
|
||||||
if(vDirection):
|
if(vDirection):
|
||||||
if(vDirection < 0):
|
if(vDirection < 0):
|
||||||
fDirection += "Up"
|
fDirection += “Up”
|
||||||
else:
|
else:
|
||||||
fDirection += "Down"
|
fDirection += “Down”
|
||||||
elif(vDirection):
|
elif(vDirection):
|
||||||
if(vDirection < 0):
|
if(vDirection < 0):
|
||||||
fDirection += "Up"
|
fDirection += “Up”
|
||||||
else:
|
else:
|
||||||
fDirection += "Down"
|
fDirection += “Down”
|
||||||
|
|
||||||
return fDirection
|
return fDirection
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func _on_timer_timeout():
|
|||||||
canShot = true
|
canShot = true
|
||||||
|
|
||||||
func death():
|
func death():
|
||||||
$AnimationPlayer.play("death")
|
$AnimationPlayer.play(“death”)
|
||||||
current_state = player_states.dead
|
current_state = player_states.dead
|
||||||
velocity.x = 0
|
velocity.x = 0
|
||||||
set_collision_layer_value(1, false)
|
set_collision_layer_value(1, false)
|
||||||
@ -172,7 +172,7 @@ func death():
|
|||||||
|
|
||||||
|
|
||||||
func _on_respawn_timeout():
|
func _on_respawn_timeout():
|
||||||
var main = get_tree().get_nodes_in_group("main")[0]
|
var main = get_tree().get_nodes_in_group(“main”)[0]
|
||||||
main.lives_p2 -= 1
|
main.lives_p2 -= 1
|
||||||
main.respawnP2()
|
main.respawnP2()
|
||||||
queue_free()
|
queue_free()
|
||||||
|
Loading…
Reference in New Issue
Block a user