-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.gd
39 lines (29 loc) · 1.02 KB
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready
var detect = $DetectPlots
func _physics_process(delta):
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var directionX = Input.get_axis("ui_left", "ui_right")
if directionX:
velocity.x = directionX * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
# As good practice, you should replace UI actions with custom gameplay actions.
var directionY = Input.get_axis("ui_up", "ui_down")
if directionY:
velocity.y = directionY * SPEED
else:
velocity.y = move_toward(velocity.y, 0, SPEED)
move_and_slide()
func _unhandled_key_input(event):
if event.keycode == KEY_E:
detect.plow_soil()
if event.keycode == KEY_Q:
detect.water_soil()
if event.keycode == KEY_F:
detect.seed_soil()