among-eux

Game made in 1 day with flx
git clone git://git.vgx.fr/among-eux
Log | Files | Refs

President.gd (979B)


      1 extends RigidBody2D
      2 
      3 export var max_speed = 30.0
      4 
      5 var gameover_scn = preload("res://GameOverScreen.tscn")
      6 
      7 func _ready():
      8 	contact_monitor = true
      9 	contacts_reported = 10
     10 
     11 func _process(_delta):
     12 	var direction = int(rad2deg(linear_velocity.angle())+360+45)%360/90
     13 	if direction == 0:
     14 		$Sprite.animation = "right"
     15 	elif direction == 1:
     16 		$Sprite.animation = "down"
     17 	elif direction == 2:
     18 		$Sprite.animation = "left"
     19 	elif direction == 3:
     20 		$Sprite.animation = "up"
     21 
     22 func _integrate_forces(state):
     23 	#print_debug(state.linear_velocity.x)
     24 	if state.linear_velocity.x < max_speed:
     25 		applied_force.x = 30.0
     26 	else:
     27 		applied_force.x = 0
     28 
     29 func _on_President_body_entered(body):
     30 	if body is Evil:
     31 		var lvl = get_parent().get_parent().lvl
     32 		#get_tree().change_scene("res://GameOverScreen.tscn")
     33 		#get_viewport().get_child(0).lvl = lvl
     34 		var gameover = gameover_scn.instance()
     35 		gameover.lvl = get_parent().get_parent().lvl
     36 		get_parent().get_parent().add_child(gameover)
     37 		max_speed = 0