2021-04-05 20:59:49 +00:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
const GRAVITY = 0.0
|
|
|
|
const WALK_SPEED = 200
|
|
|
|
const interaction_circle_size = 150
|
2022-10-12 18:06:51 +00:00
|
|
|
#onready var background_map = get_node("/root/base_scene/background")
|
|
|
|
onready var background_map = get_parent().get_node("background")
|
2022-10-12 20:52:13 +00:00
|
|
|
#onready var background_map = get_node("background")
|
2022-10-12 18:06:51 +00:00
|
|
|
onready var vegetation_map = get_parent().get_node("vegetation")
|
|
|
|
onready var interaction_map = get_parent().get_node("interaction_map")
|
|
|
|
onready var player_interaction_map = get_parent().get_node("player_interaction")
|
2021-04-05 20:59:49 +00:00
|
|
|
onready var cell_size = background_map._get_cell_size()
|
|
|
|
|
|
|
|
var velocity = Vector2()
|
|
|
|
var world_position
|
2021-04-08 19:18:46 +00:00
|
|
|
var ItemClass = preload("res://MiscScenes/Item.tscn")
|
2021-04-23 20:16:43 +00:00
|
|
|
var previous_position = Vector2(0,0)
|
2021-04-05 20:59:49 +00:00
|
|
|
|
|
|
|
#Moving buttons
|
|
|
|
func _physics_process(delta):
|
2021-04-23 20:16:43 +00:00
|
|
|
var cur = Vector2(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
|
|
|
if(cur != previous_position):
|
2022-10-12 18:06:51 +00:00
|
|
|
player_interaction_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y) , 0)
|
|
|
|
player_interaction_map.set_cell(previous_position.x, previous_position.y, -1)
|
2021-04-23 20:16:43 +00:00
|
|
|
previous_position = Vector2(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
2022-10-08 18:42:29 +00:00
|
|
|
if Input.is_action_just_pressed("interact_with_cell"):
|
2021-04-05 20:59:49 +00:00
|
|
|
_interaction_process()
|
|
|
|
velocity.y += delta * GRAVITY
|
|
|
|
if Input.is_action_pressed("move_left"):
|
|
|
|
velocity.x = -WALK_SPEED
|
|
|
|
elif Input.is_action_pressed("move_right"):
|
|
|
|
velocity.x = WALK_SPEED
|
|
|
|
elif Input.is_action_pressed("move_up"):
|
|
|
|
velocity.y = -WALK_SPEED
|
|
|
|
elif Input.is_action_pressed("move_down"):
|
|
|
|
velocity.y = WALK_SPEED
|
|
|
|
else:
|
|
|
|
velocity.x = 0
|
|
|
|
velocity.y = 0
|
|
|
|
move_and_slide(velocity, Vector2(0, -1))
|
2021-04-23 20:16:43 +00:00
|
|
|
|
2021-04-05 20:59:49 +00:00
|
|
|
Global.current_camera.Update()
|
|
|
|
|
|
|
|
func InteractWithCell():
|
2022-10-12 20:52:13 +00:00
|
|
|
for _i in self.get_children():
|
|
|
|
print(_i)
|
2022-10-12 18:06:51 +00:00
|
|
|
print(background_map)
|
|
|
|
print(interaction_map)
|
2022-01-15 21:25:42 +00:00
|
|
|
var plant_cell_mouse = interaction_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[0] / cell_size.y))
|
|
|
|
var plant_cell_character = interaction_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
2021-04-05 20:59:49 +00:00
|
|
|
|
|
|
|
var background_cell = background_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
2022-10-12 18:06:51 +00:00
|
|
|
var interaction_cell = player_interaction_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
2022-01-15 21:25:42 +00:00
|
|
|
|
|
|
|
print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36))
|
|
|
|
print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell)
|
2022-10-11 17:21:46 +00:00
|
|
|
GlobalGameFunctions.SoundOnInteraction(self, "standard")
|
2021-04-23 20:16:43 +00:00
|
|
|
|
2021-04-05 20:59:49 +00:00
|
|
|
if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0:
|
2021-04-08 19:18:46 +00:00
|
|
|
Global.AddInventoryItem(plant_cell_mouse/2, 1)
|
2022-01-15 21:25:42 +00:00
|
|
|
interaction_map.set_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y), (plant_cell_mouse-1))
|
2021-04-05 20:59:49 +00:00
|
|
|
AnimationOnInteraction(1)
|
2021-04-08 20:58:04 +00:00
|
|
|
Global.Save()
|
2021-04-05 20:59:49 +00:00
|
|
|
elif plant_cell_character > 0 and plant_cell_character % 2 == 0:
|
2021-04-08 19:18:46 +00:00
|
|
|
Global.AddInventoryItem(plant_cell_character/2, 1)
|
2022-01-15 21:25:42 +00:00
|
|
|
interaction_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), (plant_cell_character-1))
|
2021-04-05 20:59:49 +00:00
|
|
|
AnimationOnInteraction(1)
|
2021-05-28 21:01:56 +00:00
|
|
|
else:
|
|
|
|
pass
|
2021-04-05 20:59:49 +00:00
|
|
|
|
|
|
|
func _interaction_process():
|
2022-10-08 18:42:29 +00:00
|
|
|
world_position = get_global_mouse_position()
|
|
|
|
InteractWithCell()
|
2021-04-05 20:59:49 +00:00
|
|
|
|
|
|
|
func AnimationOnInteraction(Item):
|
|
|
|
print("Item = ", Item, " Animation")
|
|
|
|
var itemimage = TextureRect.new()
|
2021-04-08 19:18:46 +00:00
|
|
|
var item = null
|
2021-06-04 20:57:48 +00:00
|
|
|
|
2021-04-05 20:59:49 +00:00
|
|
|
func _ready():
|
2021-04-08 20:58:04 +00:00
|
|
|
Global.player_inventory_items = Database.GetInventoryItems().duplicate()
|
2022-10-13 15:09:42 +00:00
|
|
|
print("Map = ", Global.map_name)
|