Game #2: Piggy
This commit is contained in:
parent
21399f904f
commit
a00ebe12f3
12 changed files with 375 additions and 0 deletions
45
piggy/Objects/Pig.gd
Normal file
45
piggy/Objects/Pig.gd
Normal file
|
@ -0,0 +1,45 @@
|
|||
extends Area2D
|
||||
|
||||
export (int) var SPEED = 100
|
||||
onready var animationPlayer = $Animation
|
||||
var moving = false
|
||||
var goingLeft = false
|
||||
|
||||
func _process(delta):
|
||||
moving = false
|
||||
|
||||
if Input.is_action_pressed("ui_right"):
|
||||
goingLeft = false
|
||||
move(SPEED, 0, delta)
|
||||
|
||||
if Input.is_action_pressed("ui_left"):
|
||||
goingLeft = true
|
||||
move(-SPEED, 0, delta)
|
||||
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
move(0, -SPEED, delta)
|
||||
|
||||
if Input.is_action_pressed("ui_down"):
|
||||
move(0, SPEED, delta)
|
||||
|
||||
if moving:
|
||||
animationPlayer.play("Run")
|
||||
else:
|
||||
animationPlayer.play("Idle")
|
||||
|
||||
$Sprite.flip_h = goingLeft
|
||||
|
||||
# var areas = get_overlapping_areas()
|
||||
# for area in areas:
|
||||
# area.queue_free()
|
||||
|
||||
func move(xspeed, yspeed, delta):
|
||||
moving = true
|
||||
position.x += xspeed * delta
|
||||
position.y += yspeed * delta
|
||||
|
||||
|
||||
func _on_Pig_area_entered(apple):
|
||||
apple.queue_free()
|
||||
scale *= 1.1
|
||||
SPEED *= 0.9
|
Loading…
Add table
Add a link
Reference in a new issue