Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | bazoka33 |
Player script:
extends Area2D
export (int) var Speed
var Movement = Vector2 ()
var limit
hit signal
func _ready ():
hide()
limit = get_viewport_rect (). size
happen
func _process (delta):
Movement = Vector2 ()
If Input.is_action_pressed (“ui_right”):
Movement.x + = 1
If Input.is_action_pressed (“ui_left”):
Movement.x - = 1
If Input.is_action_pressed (“ui_down”):
Movement.y + = 1
If Input.is_action_pressed (“ui_up”):
Movement.y - = 1
if Move.length ()> 0:
Movement = Movement.normalized () * Speed
position + = delta * movement
position.x = clamp (position.x, 0, limit.x)
position.y = clamp (position.y, 0, limit.y)
yes Movement.x! = 0:
$ AnimatedSprite.animation = “side”
$ AnimatedSprite.flip_h = Movement.x <0
$ AnimatedSprite.flip_v = false
elif Movement.y! = 0:
$ AnimatedSprite.animation = “back”
$ AnimatedSprite.flip_v = Movement.y> 0
plus:
$ AnimatedSprite.animation = “front”
func _on_Player_body_entered (body):
hide()
emit_signal (“hit”)
$ CollisionShape2D.disabled = true
happen
start func (pos):
position = pos
to show()
$ CollisionShape2D.disabled = false;
Enemies script:
extends RigidBody2D
export (int) var v_min
export (int) var v_max
var tipo_abeja = [“abeja”, “mosca”]
func _ready():
$AnimatedSprite.animation = tipo_abeja[randi() % tipo_abeja.size()]
func _on_Visibilidad_screen_exited():
queue_free() #eliminar abeja
World script:
extends Node
export (PackedScene) var Abeja
var Score
func _ready():
randomize()
func nuevo_juego():
Score = 0
$Player.inicio($PosicionDeInicio.position) #posicion de inicio del Player
$InicioTimer.start()
$Interfaz.mostrar_mensaje(“Listo!”)
$Interfaz.update_score(Score)
func game_over():
$ScoreTimer.stop()
$AbejaTimer.stop()
$Interfaz.game_over()
func _on_InicioTimer_timeout():
$AbejaTimer.start()
$ScoreTimer.start()
func _on_ScoreTimer_timeout():
Score += 1
$Interfaz.update_score(Score)
func _on_AbejaTimer_timeout():
$Camino/AbejaPosicion.set_offset(randi())
var A = Abeja.instance()
add_child(A)
var d = $Camino/AbejaPosicion.rotation
A.position = $Camino/AbejaPosicion.position
d += rand_range(0.78539816, 0.78539816)
A.rotation = d
A.set_linear_velocity(Vector2(rand_range(A.v_min, A.v_max), 0).rotated(d))