tomato-dungeon

a game made in 1 day
git clone git://git.vgx.fr/tomato-dungeon
Log | Files | Refs | README

Spell.gd (1103B)


      1 extends Area2D
      2 
      3 var speed = 100.0
      4 var movement = Vector2(1, 0)
      5 var strength = 10.0
      6 var lvl = 0
      7 
      8 var thrower = null
      9 
     10 var mage
     11 var mage_head
     12 
     13 # Called when the node enters the scene tree for the first time.
     14 func _ready():
     15 	rotation = movement.angle()
     16 	mage = get_node("../mage")
     17 	mage_head = mage.get_node("Sprite/HeadArea")
     18 	match lvl:
     19 		0:
     20 			$Sprite.play("white")
     21 		1:
     22 			$Sprite.play("green")
     23 		2:
     24 			$Sprite.play("blue")
     25 		3:
     26 			$Sprite.play("purple")
     27 		_:
     28 			$Sprite.play("red")
     29 	
     30 	if lvl != 0:
     31 		strength = mage.strength * 0.5 * lvl
     32 			
     33 
     34 
     35 # Called every frame. 'delta' is the elapsed time since the previous frame.
     36 func _process(delta):
     37 	position += movement*delta
     38 	if get_parent().get_closest_point(position) != position:
     39 		queue_free()
     40 	if lvl == 0: # monster spell
     41 		if overlaps_area(mage_head):
     42 			mage.life -= strength
     43 			if !mage.over:
     44 				mage.get_node("HitSound").play()
     45 			queue_free()
     46 	#else: # mage spell
     47 	for monstre in get_tree().get_nodes_in_group("monstres"):
     48 		if monstre != thrower and overlaps_area(monstre.get_node("Sprite/HitArea")):
     49 			monstre.life -= strength
     50 			queue_free()