2020-08-29 14:36:49 +00:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
const GRAVITY = 0.0
|
|
|
|
const WALK_SPEED = 200
|
2020-09-24 19:34:34 +00:00
|
|
|
const interaction_circle_size = 150
|
|
|
|
onready var background_map = get_node("/root/Map1/background")
|
|
|
|
onready var player = get_node("/root/Map1/Player")
|
|
|
|
onready var cell_size = background_map._get_cell_size()
|
2020-10-03 12:13:19 +00:00
|
|
|
onready var plants_map = get_node("/root/Map1/interaction_map")
|
2020-10-03 12:49:11 +00:00
|
|
|
onready var interaction = get_node("/root/Map1/player_interaction")
|
2020-08-29 14:36:49 +00:00
|
|
|
|
|
|
|
var velocity = Vector2()
|
|
|
|
|
2020-09-24 19:34:34 +00:00
|
|
|
#Moving buttons
|
2020-08-29 14:36:49 +00:00
|
|
|
func _physics_process(delta):
|
2020-10-02 20:55:51 +00:00
|
|
|
if Input.is_key_pressed(KEY_SPACE):
|
|
|
|
_interaction_process()
|
2020-08-29 14:36:49 +00:00
|
|
|
velocity.y += delta * GRAVITY
|
2020-08-31 07:35:52 +00:00
|
|
|
if Input.is_action_pressed("move_left"):
|
2020-08-29 14:36:49 +00:00
|
|
|
velocity.x = -WALK_SPEED
|
2020-08-31 07:35:52 +00:00
|
|
|
elif Input.is_action_pressed("move_right"):
|
2020-08-29 14:36:49 +00:00
|
|
|
velocity.x = WALK_SPEED
|
2020-08-31 07:35:52 +00:00
|
|
|
elif Input.is_action_pressed("move_up"):
|
2020-08-29 14:36:49 +00:00
|
|
|
velocity.y = -WALK_SPEED
|
2020-08-31 07:35:52 +00:00
|
|
|
elif Input.is_action_pressed("move_down"):
|
2020-08-29 14:36:49 +00:00
|
|
|
velocity.y = WALK_SPEED
|
|
|
|
else:
|
|
|
|
velocity.x = 0
|
|
|
|
velocity.y = 0
|
|
|
|
move_and_slide(velocity, Vector2(0, -1))
|
2021-04-03 14:06:23 +00:00
|
|
|
Global.current_camera.Update()
|
2020-10-08 19:56:03 +00:00
|
|
|
# if(interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) == -1):
|
|
|
|
# interaction.clear()
|
|
|
|
# interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 0)
|
2020-09-21 21:13:11 +00:00
|
|
|
|
2020-10-10 20:23:11 +00:00
|
|
|
func InteractWithCell():
|
|
|
|
var plant_cell = plants_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
|
|
|
var background_cell = background_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
|
|
|
var interaction_cell = interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
|
|
|
print(plant_cell)
|
|
|
|
if plant_cell == 1:
|
|
|
|
Global.AddInventoryItem(3, 1)
|
|
|
|
plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 4)
|
2020-10-19 20:44:21 +00:00
|
|
|
AnimationOnInteraction(1)
|
2020-10-10 20:23:11 +00:00
|
|
|
# plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 4)
|
|
|
|
|
2020-10-02 20:55:51 +00:00
|
|
|
func _interaction_process():
|
|
|
|
if Input.is_action_pressed("map_interaction") or Input.is_key_pressed((KEY_SPACE)):
|
2020-10-10 20:23:11 +00:00
|
|
|
InteractWithCell()
|
|
|
|
# plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 10)
|
2020-10-02 20:55:51 +00:00
|
|
|
|
2020-09-24 19:34:34 +00:00
|
|
|
func _input(event):
|
2020-10-10 20:23:11 +00:00
|
|
|
pass
|
2020-10-19 20:44:21 +00:00
|
|
|
|
|
|
|
func AnimationOnInteraction(Item):
|
|
|
|
print(Item, "Animation")
|
2020-10-23 20:05:47 +00:00
|
|
|
var itemimage = TextureRect.new()
|
|
|
|
itemimage.texture = load("res://pictures/inventory_iconpictures/food_items/herbs/saffron.png")
|
|
|
|
itemimage.set_position(Vector2(randf()*20-40, randf()*40-20))
|
|
|
|
add_child(itemimage)
|
|
|
|
yield(get_tree().create_timer(1.0), "timeout")
|
|
|
|
remove_child(itemimage)
|
2020-09-24 19:34:34 +00:00
|
|
|
|
2020-10-07 20:24:10 +00:00
|
|
|
func _ready():
|
|
|
|
Global.player_inventory_items = Database.GetInventoryItems()
|
2020-10-23 20:05:47 +00:00
|
|
|
|