;;####################################################################
;;# GNU Free Documentation License                                   #
;;# Version 1.3, 3 November 2008                                     #
;;#                                                                  #
;;# Copyright (C) 2021 Lumina                                        #
;;# (Paula Garcia Morales, Laura Gil Lopez, Jorge Perez Dominguez)   #
;;#                                                                  #
;;# Everyone is permitted to copy and distribute verbatim copies     #
;;# of this license document, but changing it is not allowed.        #
;;####################################################################


.include "cpctelera.h.s"
.include "input.h.s"

relojitoInput: .db #0x00
menosInput: .db #0x00

;;W = 59
;;S = 60
;;A = 69
;;D = 61


;;Actualizar inputs entrantes en cada llamada del bucle principal del juego
input_update::
	call entityman_getEntityArray_IX

	call cpct_scanKeyboard_f_asm

	ld 	hl,	#Key_Q				;;Cargar Q en hl
	call cpct_isKeyPressed_asm
	jr	z,	W_NotPressed

	W_Pressed:
		call entityman_negY
		jr comprobar_x

	W_NotPressed:
		ld 	hl,	#Key_A				;;Cargar A en hl
		call cpct_isKeyPressed_asm
		jr	z,	comprobar_joystick_y

	ld 	hl,	#Key_A				;;Cargar A en hl
	call cpct_isKeyPressed_asm
	jr	z,	S_NotPressed

	S_Pressed:
		call  entityman_posY
		jr comprobar_x

	S_NotPressed:
		ld 	hl,	#Key_Q				;;Cargar Q en hl
		call cpct_isKeyPressed_asm
		jr	z,	comprobar_joystick_y




	comprobar_joystick_y:
		ld hl, #Joy0_Up
		call cpct_isKeyPressed_asm
		jr z, Up_NotPressed

		Up_Pressed:
			call entityman_negY
			jr comprobar_x

		Up_NotPressed:
			ld hl, #Joy0_Down
			call cpct_isKeyPressed_asm
			jr z, vely0

		ld hl, #Joy0_Down
		call cpct_isKeyPressed_asm
		jr z, Down_NotPressed

		Down_Pressed:
			call entityman_posY
			jr comprobar_x

		Down_NotPressed:
			ld hl, #Joy0_Up
			call cpct_isKeyPressed_asm
			jr z, vely0 

	vely0:
		call entityman_vely0


	comprobar_x:

		ld 	hl,	#Key_O				;;Cargar O en hl
		call cpct_isKeyPressed_asm
		jr	z,	A_NotPressed

		A_Pressed:
			call entityman_negX
			jr salto_input

		A_NotPressed:
			ld 	hl,	#Key_P				;;Cargar P en hl
			call cpct_isKeyPressed_asm
			jr	z,	comprobar_joystick_x

		ld 	hl,	#Key_P				;;Cargar P en hl
		call cpct_isKeyPressed_asm
		jr	z,	D_NotPressed

		D_Pressed:
			call entityman_posX  
			jr salto_input
	 
		D_NotPressed:
			ld 	hl,	#Key_O				;;Cargar O en hl
			call cpct_isKeyPressed_asm
			jr	z,	comprobar_joystick_x




	comprobar_joystick_x:
		ld hl, #Joy0_Left
		call cpct_isKeyPressed_asm
		jr z, Left_NotPressed

		Left_Pressed:
			call entityman_negX
			jr salto_input

		Left_NotPressed:
			ld hl, #Joy0_Right
			call cpct_isKeyPressed_asm
			jr z, velx0

		ld hl, #Joy0_Right
		call cpct_isKeyPressed_asm
		jr z, Right_NotPressed

		Right_Pressed:
			call entityman_posX
			jr salto_input

		Right_NotPressed:
			ld hl, #Joy0_Left
			call cpct_isKeyPressed_asm
			jr z, velx0 

	velx0:
		call entityman_velx0

	salto_input:
ret