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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. extends KinematicBody2D
  2. var vitesse = Vector2.ZERO
  3. var score = 0
  4. var score_goal = 10
  5. export var jump_vitesse = 800.0
  6. export var gravite = 20.0
  7. enum {
  8. RUN,
  9. JUMP,
  10. IDLE
  11. }
  12. enum {
  13. SCORE,
  14. TIME
  15. }
  16. var jump_key = "dialogic_next"
  17. var player_enabled = false
  18. var game_mode = "score"
  19. var state = RUN
  20. var au_sol = true
  21. # Declare member variables here. Examples:
  22. # var a = 2
  23. # var b = "text"
  24. onready var animation = $AnimatedSprite
  25. # Called when the node enters the scene tree for the first time.
  26. func _ready():
  27. stop()
  28. Signals.connect("gain",self,"increase_score")
  29. Signals.connect("die",self,"player_die")
  30. func _physics_process(delta):
  31. if player_enabled:
  32. match state:
  33. RUN:
  34. animation.play("man_run")
  35. JUMP:
  36. vitesse = Vector2.ZERO
  37. vitesse.y -= jump_vitesse
  38. animation.play("man_jump")
  39. state = IDLE
  40. IDLE:
  41. pass
  42. vitesse.y += gravite
  43. move_and_collide(vitesse*delta)
  44. func _input(event):
  45. if player_enabled and state == RUN and event.is_action_pressed(jump_key):
  46. state = JUMP
  47. func _on_Area2D_body_entered(body):
  48. if body is StaticBody2D:
  49. state = RUN
  50. func _on_Area2D_body_exited(body):
  51. if body is StaticBody2D:
  52. state = JUMP
  53. func increase_score(scoretoadd):
  54. match game_mode:
  55. "score":
  56. score+=scoretoadd
  57. Signals.emit_signal("update_score",score)
  58. if score >= score_goal:
  59. Signals.emit_signal("win")
  60. "time":
  61. pass
  62. _:
  63. print("game_mode not recognized by player2 start func")
  64. func player_win():
  65. stop()
  66. func player_die():
  67. stop()
  68. func start(mode: String, goal: int):
  69. show()
  70. match mode:
  71. "score":
  72. if (goal != 0):
  73. score_goal = goal
  74. game_mode = "score"
  75. "time":
  76. game_mode = "time"
  77. _:
  78. print("game_mode not recognized by player2 start func")
  79. score = 0
  80. player_enabled = true
  81. func stop():
  82. hide()
  83. player_enabled = false