No major updates
This commit is contained in:
parent
fee3de7544
commit
8999e2e4a8
@ -2,12 +2,16 @@ extends KinematicBody2D
|
||||
|
||||
const GRAVITY = 0.0
|
||||
const WALK_SPEED = 200
|
||||
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()
|
||||
|
||||
var velocity = Vector2()
|
||||
|
||||
#Moving buttons
|
||||
func _physics_process(delta):
|
||||
velocity.y += delta * GRAVITY
|
||||
|
||||
if Input.is_action_pressed("move_left"):
|
||||
velocity.x = -WALK_SPEED
|
||||
elif Input.is_action_pressed("move_right"):
|
||||
@ -16,13 +20,24 @@ func _physics_process(delta):
|
||||
velocity.y = -WALK_SPEED
|
||||
elif Input.is_action_pressed("move_down"):
|
||||
velocity.y = WALK_SPEED
|
||||
# elif Input.is_action_pressed("map_interaction"):
|
||||
# print("Interacted")
|
||||
# print(InputEventMouseButton.position)
|
||||
else:
|
||||
velocity.x = 0
|
||||
velocity.y = 0
|
||||
|
||||
# We don't need to multiply velocity by delta because "move_and_slide" already takes delta time into account.
|
||||
|
||||
# The second parameter of "move_and_slide" is the normal pointing up.
|
||||
# In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
|
||||
move_and_slide(velocity, Vector2(0, -1))
|
||||
|
||||
func _input(event):
|
||||
# Mouse in viewport coordinates.
|
||||
if event is InputEventMouseButton:
|
||||
var pos = event.position
|
||||
if Input.is_action_pressed("map_interaction"):
|
||||
pass
|
||||
|
||||
# elif event is InputEventMouseMotion:
|
||||
# print("Mouse Motion at: ", event.position)
|
||||
#
|
||||
# # Print the size of the viewport.
|
||||
# print("Viewport Resolution is: ", get_viewport_rect().size)
|
||||
|
@ -7,7 +7,6 @@ onready var screen_size = self.get_viewport_rect().size
|
||||
|
||||
func _ready():
|
||||
calculate_bounds()
|
||||
print(screen_size)
|
||||
|
||||
var once = true
|
||||
var lockedPlayerCamera = false
|
||||
@ -18,6 +17,7 @@ var max_y = 0
|
||||
var max_x_pixel = 0
|
||||
var max_y_pixel = 0
|
||||
|
||||
#function that calculates the borders/bounds of the map
|
||||
func calculate_bounds():
|
||||
var used_cells = background_map.get_used_cells()
|
||||
for pos in used_cells:
|
||||
@ -38,7 +38,7 @@ func _process(delta):
|
||||
CameraToPlayer()
|
||||
if once:
|
||||
once = false
|
||||
AnimateMoveCamera(player.position, Vector2(player.position.x - 100,player.position.y - 10), "position", 2)
|
||||
#AnimateMoveCamera(player.position, Vector2(player.position.x - 100,player.position.y - 10), "position", 2)
|
||||
pass
|
||||
|
||||
func get_global_pos():
|
||||
@ -65,8 +65,10 @@ func AnimateMoveCamera(source, destination, key, time):
|
||||
tween.interpolate_property(get_node("/root/Map1/Camera2D"), key, source, destination, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
tween.start()
|
||||
|
||||
|
||||
#Move camera close to player
|
||||
func CameraToPlayer():
|
||||
if lockedPlayerCamera == false:
|
||||
MoveCamera(player.position.x, player.position.y)
|
||||
|
||||
func GetExactMapPosition_FromScreen(map_pos, target_pos):
|
||||
|
||||
pass
|
||||
|
34
background_script.gd
Normal file
34
background_script.gd
Normal file
@ -0,0 +1,34 @@
|
||||
extends TileMap
|
||||
|
||||
onready var player = get_node("/root/Map1/Player")
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _get_cell_size():
|
||||
return cell_size
|
||||
|
||||
|
||||
|
||||
# use unhandled_input so that...
|
||||
# 1. You aren't executing this every frame, even when there is no input
|
||||
# 2. You don't interrupt global / GUI related input callbacks
|
||||
func _unhandled_input(event):
|
||||
var pl_pos = player.position
|
||||
var pl_pos_tile = Vector2(pl_pos.x / cell_size.x, pl_pos.y / cell_size.y)
|
||||
var pl_tile = get_cellv(pl_pos_tile)
|
||||
if event == Input.action_press("map_interaction"):
|
||||
if(pl_tile != -1):
|
||||
set_cellv(pl_pos_tile, -1)
|
||||
|
||||
# var mouse_pos = get_viewport().get_mouse_position()
|
||||
# var tile_pos = map_to_world(world_to_map(mouse_pos))
|
||||
## print(tile_pos)
|
||||
# #var tile = get_cell(32,32)
|
||||
# var tile = get_cell(mouse_pos.x / cell_size.x, mouse_pos.y / cell_size.y)
|
||||
# if(tile != -1):
|
||||
# set_cell(mouse_pos.x / cell_size.x, mouse_pos.y / cell_size.y, -1)
|
||||
## clear()
|
||||
## print(tile)
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user