You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.1 KiB
GDScript
54 lines
2.1 KiB
GDScript
extends KinematicBody2D
|
|
|
|
var playerX = 32
|
|
var playerY = 32
|
|
var playerCelda = 1
|
|
|
|
|
|
# Función que controla los movimientos del player
|
|
func playerMovements():
|
|
if Input.is_action_just_pressed('left'):
|
|
if playerX != 32:
|
|
playerX = playerX - 64 ; $player.position = Vector2(playerX,playerY) ; playerCelda=(playerCelda - 1) ; printPosition(playerX,playerY,playerCelda)
|
|
checkCelda()
|
|
|
|
if Input.is_action_just_pressed('right'):
|
|
if playerX != 608:
|
|
playerX = playerX + 64 ; $player.position = Vector2(playerX,playerY) ; playerCelda=(playerCelda + 1 ) ; printPosition(playerX,playerY,playerCelda)
|
|
checkCelda()
|
|
|
|
if Input.is_action_just_pressed('up'):
|
|
if playerY != 32:
|
|
playerY = playerY - 64 ; $player.position = Vector2(playerX,playerY) ; playerCelda=(playerCelda - 10) ; printPosition(playerX,playerY,playerCelda)
|
|
checkCelda()
|
|
|
|
if Input.is_action_just_pressed('down'):
|
|
if playerY != 480:
|
|
playerY = playerY + 64 ; $player.position = Vector2(playerX,playerY) ; playerCelda=(playerCelda + 10) ; printPosition(playerX,playerY,playerCelda)
|
|
checkCelda()
|
|
|
|
# Función que comprueba si se ha pisado ya esa celda porque inicialmente van seteadas en color negro (0,0,0,1)
|
|
func checkCelda():
|
|
var celdaIDName=("celda_"+str(playerCelda))
|
|
var celdaActualColor = str(get_parent().get_node(celdaIDName).color)
|
|
if celdaActualColor == "0,0,0,1":
|
|
get_parent().get_node(celdaIDName).color = "#00FF00"
|
|
# cesped bajo el sol - verde claro - #00da6a
|
|
# cesped a la sombra - verde oscuro - #009a4b
|
|
# asfalto bajo el sol - gris oscuro pero no tan oscuro - #515151
|
|
# asfalto a la sombra - gris oscuro - #474747
|
|
# parquet bajo el sol - marrón claro - #f3b987
|
|
# parquet a la sombra - marrón oscuro - #d58c4d
|
|
# cemento bajo el sol - gris claro - #929292
|
|
# cemento a la sombra - gris oscuro - #656565
|
|
# granito bajo el sol - blanco - #ffffff
|
|
# granito a la sombra - gris muy muy claro - eeeeee
|
|
# agua - azul - #6d69f7
|
|
|
|
# Función que imprime la posición del player
|
|
func printPosition(x,y,celda):
|
|
get_parent().get_node("playerPosition").text = str(celda) + " " + "(x:" + str(x) + " y:" + str(y) + ")"
|
|
|
|
func _process(delta):
|
|
playerMovements()
|