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