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

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