1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- extends KinematicBody2D
-
- var vitesse = Vector2.ZERO
-
- var score = 0
-
- export var jump_vitesse = 600.0
- export var gravite = 20.0
-
- enum {
- RUN,
- JUMP,
- IDLE
- }
-
- var state = RUN
- var au_sol = true
-
- # Declare member variables here. Examples:
- # var a = 2
- # var b = "text"
- onready var animation = $AnimatedSprite
-
- # Called when the node enters the scene tree for the first time.
- func _ready():
- Signals.connect("gain",self,"increase_score")
- Signals.connect("die",self,"player_die")
-
- func _physics_process(delta):
- match state:
- RUN:
- animation.play("run")
- print("run")
- JUMP:
- vitesse = Vector2.ZERO
- vitesse.y -= jump_vitesse
- animation.play("jump")
- state = IDLE
- print("jump")
- IDLE:
- pass
- vitesse.y += gravite
- move_and_collide(vitesse*delta)
-
- func _input(event):
- if state == RUN and event.is_action_pressed("jump"):
- state = JUMP
-
-
-
-
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- # pass
-
-
- func _on_Area2D_body_entered(body):
- print("landing")
- if body is StaticBody2D:
- print("Yep a dino is landing")
- state = RUN
-
-
-
- func _on_Area2D_body_exited(body):
- print("jumping")
- if body is StaticBody2D:
- print("Yep a dino is jumping")
- state = JUMP
-
- func increase_score(scoretoadd):
- score+=scoretoadd
- Signals.emit_signal("update_score",score)
- print(score)
-
- func player_die():
- queue_free()
|