No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

player2.gd 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. extends KinematicBody2D
  2. var vitesse = Vector2.ZERO
  3. var score = 0
  4. export var jump_vitesse = 600.0
  5. export var gravite = 20.0
  6. enum {
  7. RUN,
  8. JUMP,
  9. IDLE
  10. }
  11. var state = RUN
  12. var au_sol = true
  13. # Declare member variables here. Examples:
  14. # var a = 2
  15. # var b = "text"
  16. onready var animation = $AnimatedSprite
  17. # Called when the node enters the scene tree for the first time.
  18. func _ready():
  19. Signals.connect("gain",self,"increase_score")
  20. Signals.connect("die",self,"player_die")
  21. func _physics_process(delta):
  22. match state:
  23. RUN:
  24. animation.play("run")
  25. print("run")
  26. JUMP:
  27. vitesse = Vector2.ZERO
  28. vitesse.y -= jump_vitesse
  29. animation.play("jump")
  30. state = IDLE
  31. print("jump")
  32. IDLE:
  33. pass
  34. vitesse.y += gravite
  35. move_and_collide(vitesse*delta)
  36. func _input(event):
  37. if state == RUN and event.is_action_pressed("jump"):
  38. state = JUMP
  39. # Called every frame. 'delta' is the elapsed time since the previous frame.
  40. #func _process(delta):
  41. # pass
  42. func _on_Area2D_body_entered(body):
  43. print("landing")
  44. if body is StaticBody2D:
  45. print("Yep a dino is landing")
  46. state = RUN
  47. func _on_Area2D_body_exited(body):
  48. print("jumping")
  49. if body is StaticBody2D:
  50. print("Yep a dino is jumping")
  51. state = JUMP
  52. func increase_score(scoretoadd):
  53. score+=scoretoadd
  54. Signals.emit_signal("update_score",score)
  55. print(score)
  56. func player_die():
  57. queue_free()