No major updates

This commit is contained in:
EljakimHerrewijnen 2020-09-24 21:34:34 +02:00
parent fee3de7544
commit 8999e2e4a8
4 changed files with 74 additions and 10 deletions

View File

@ -2,12 +2,16 @@ extends KinematicBody2D
const GRAVITY = 0.0 const GRAVITY = 0.0
const WALK_SPEED = 200 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() var velocity = Vector2()
#Moving buttons
func _physics_process(delta): func _physics_process(delta):
velocity.y += delta * GRAVITY velocity.y += delta * GRAVITY
if Input.is_action_pressed("move_left"): if Input.is_action_pressed("move_left"):
velocity.x = -WALK_SPEED velocity.x = -WALK_SPEED
elif Input.is_action_pressed("move_right"): elif Input.is_action_pressed("move_right"):
@ -16,13 +20,24 @@ func _physics_process(delta):
velocity.y = -WALK_SPEED velocity.y = -WALK_SPEED
elif Input.is_action_pressed("move_down"): elif Input.is_action_pressed("move_down"):
velocity.y = WALK_SPEED velocity.y = WALK_SPEED
# elif Input.is_action_pressed("map_interaction"):
# print("Interacted")
# print(InputEventMouseButton.position)
else: else:
velocity.x = 0 velocity.x = 0
velocity.y = 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)) 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)

View File

@ -7,7 +7,6 @@ onready var screen_size = self.get_viewport_rect().size
func _ready(): func _ready():
calculate_bounds() calculate_bounds()
print(screen_size)
var once = true var once = true
var lockedPlayerCamera = false var lockedPlayerCamera = false
@ -18,6 +17,7 @@ var max_y = 0
var max_x_pixel = 0 var max_x_pixel = 0
var max_y_pixel = 0 var max_y_pixel = 0
#function that calculates the borders/bounds of the map
func calculate_bounds(): func calculate_bounds():
var used_cells = background_map.get_used_cells() var used_cells = background_map.get_used_cells()
for pos in used_cells: for pos in used_cells:
@ -38,7 +38,7 @@ func _process(delta):
CameraToPlayer() CameraToPlayer()
if once: if once:
once = false 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 pass
func get_global_pos(): 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.interpolate_property(get_node("/root/Map1/Camera2D"), key, source, destination, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start() tween.start()
#Move camera close to player
func CameraToPlayer(): func CameraToPlayer():
if lockedPlayerCamera == false: if lockedPlayerCamera == false:
MoveCamera(player.position.x, player.position.y) MoveCamera(player.position.x, player.position.y)
func GetExactMapPosition_FromScreen(map_pos, target_pos):
pass

34
background_script.gd Normal file
View 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