;;####################################################################
;;# 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 "menu.h.s"
.include "src/assets/sprites/game_over_z.h.s"
.include "src/assets/sprites/game_inicio_z.h.s"
.include "src/assets/sprites/game_win_z.h.s"
.include "src/assets/sprites/game_historia_z.h.s"

Init: .asciz '1) Play'
Options: .asciz '2) Controls'
Credits: .asciz '3) Credits'

MenuOptions: .asciz 'CONTROLS'
TeclaO: .asciz '(O) Move Left'
TeclaP: .asciz '(P) Move Right'
TeclaQ: .asciz '(Q) Move Up'
TeclaA: .asciz '(A) Move Down'

OptionsCreditsReturn: .asciz 'Press Return to go back'

MenuCredits: .asciz 'CREDITS'
Paula: .asciz 'Paula Garcia Morales'
Laura: .asciz 'Laura Gil Lopez'
Jorge: .asciz 'Jorge Perez Dominguez'

Historia1: .asciz 'Legend has it that only those'
Historia2: .asciz 'who climb the great mountain will'
Historia3: .asciz 'taste the great blue cheese'

HistoriaWin1: .asciz 'We ate the legendary cheese and now'
HistoriaWin2: .asciz 'we could roll down the mountain!'


man_menu_init::
	call render_clean_screen

	call set_interr_over
	call init_music_menu

	cpctm_setBorder_asm HW_BLACK

	;;no hace falta estar pintando todo el rato lo mismo, porque no hay movimiento

	ld hl, #_game_inicio_z_end
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm



	ld bc, #0x641E        ;;y=100(0x64), x=30(0x1E)
	ld hl, #Init
	call render_text

    ld bc, #0x821E        ;;y=130(0x82), x=30(0x1E)
	ld hl, #Options
	call render_text


    ld bc, #0xA01E        ;;y=160(0xA0), x=30(0x1E)
	ld hl, #Credits
	call render_text

    _menu_init:
		;;control de teclado

	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_1				;;Cargar tecla 1 en hl
		call cpct_isKeyPressed_asm
		jr	nz,	Play_Pressed

		ld hl, #Key_2
		call cpct_isKeyPressed_asm
		jr nz, Options_Pressed

		ld hl, #Key_3
		call cpct_isKeyPressed_asm
		jr nz, Credits_Pressed

    jr _menu_init

    Play_Pressed:
    	call man_menu_game_historia
    	ret 

    Options_Pressed:
    	call man_menu_options
    	ret

    Credits_Pressed:
    	call man_menu_credits
    	ret 
ret


man_menu_options:
	call render_clean_screen

	;;personajillo
	ld	de,	#0xC000
	ld	 c,	#25	;;x
	ld	 b,	#25	;;y
	call cpct_getScreenPtr_asm
    
    ex	de,	hl

	ld hl, #_zacarias_victoria	

	ld b, #16       ;;h
	ld c, #4        ;;w
		
	call cpct_drawSprite_asm


	;;personajillo
	ld	de,	#0xC000
	ld	 c,	#53	;;x
	ld	 b,	#25	;;y
	call cpct_getScreenPtr_asm
    
    ex	de,	hl

	ld hl, #_zacarias_victoria1	

	ld b, #16       ;;h
	ld c, #4        ;;w
		
	call cpct_drawSprite_asm


	ld bc, #0x1E21        ;;x=35(0x23), y=30(0x1E)
	ld hl, #MenuOptions
	call render_text


	ld bc, #0x3C19        ;;y=60(0x3C), x=25(0x19)
	ld hl, #TeclaO
	call render_text

	ld bc, #0x5019        ;;y=80(0x50), x=25(0x19)
	ld hl, #TeclaP
	call render_text

	ld bc, #0x6419        ;;y=100(0x64), x=25(0x19)
	ld hl, #TeclaQ
	call render_text

	ld bc, #0x7819        ;;y=120(0x78), x=25(0x19)
	ld hl, #TeclaA
	call render_text

	ld bc, #0xB40F        ;;y=160(0xB4), x=15(0x19)
	ld hl, #OptionsCreditsReturn
	call render_text

	menu_options:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Return				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	vuelvo_options
	jr menu_options

	vuelvo_options:
		call man_menu_init
		ret
ret 

man_menu_credits:
	call render_clean_screen

	;;personajillo
	ld	de,	#0xC000
	ld	 c,	#25	;;x
	ld	 b,	#25	;;y
	call cpct_getScreenPtr_asm
    
    ex	de,	hl

	ld hl, #_zacarias_victoria	

	ld b, #16       ;;h
	ld c, #4        ;;w
		
	call cpct_drawSprite_asm


	;;personajillo
	ld	de,	#0xC000
	ld	 c,	#53	;;x
	ld	 b,	#25	;;y
	call cpct_getScreenPtr_asm
    
    ex	de,	hl

	ld hl, #_zacarias_victoria1	

	ld b, #16       ;;h
	ld c, #4        ;;w
		
	call cpct_drawSprite_asm


	ld bc, #0x1E21        ;;x=35(0x23), y=30(0x1E)
	ld hl, #MenuCredits
	call render_text


	ld bc, #0x500F        ;;y=80(0x50), x=15(0x0F)
	ld hl, #Paula
	call render_text

	ld bc, #0x640F        ;;y=100(0x64), x=15(0x0F)
	ld hl, #Laura
	call render_text

	ld bc, #0x780F        ;;y=120(0x78), x=15(0x0F)
	ld hl, #Jorge
	call render_text

	ld bc, #0xB40F        ;;y=160(0xB4), x=25(0x19)
	ld hl, #OptionsCreditsReturn
	call render_text

	menu_credits:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Return				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	vuelvo_credits
	jr menu_credits

	vuelvo_credits:
		call man_menu_init
		ret
ret

man_menu_game_historia::
	call cpct_waitVSYNC_asm
    call render_clean_screen

    cpctm_setBorder_asm HW_BLACK

    ld hl, #_game_historia_z_end
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm

    ld bc, #0x820C        ;;y=130(0x82), x=C(0x12)
	ld hl, #Historia1
	call render_text

	ld bc, #0x8C08        ;;y=140(0x8C), x=8(0x08)
	ld hl, #Historia2
	call render_text

	ld bc, #0x960E        ;;y=150(0x96), x=E(0x14)
	ld hl, #Historia3
	call render_text

	call entityman_reset_game

    _game_historia:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Space				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	Space_Pressed_Historia

    jr _game_historia

    Space_Pressed_Historia:
    	call render_clean_screen
    	call cpct_waitVSYNC_asm
ret

;;Funcion de game over que muestra un texto
man_menu_game_over_life::
	call set_interr_over
	call init_music_perder
	
	call cpct_waitVSYNC_asm
    call render_clean_screen

    cpctm_setBorder_asm HW_BLACK

    ld hl, #_game_over_z_end
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm

	call entityman_reset_game

    _game_over:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Return				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	Space_Pressed_Over

    jr _game_over

    Space_Pressed_Over:
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl

    	jp llamadas_principales
ret

;;Funcion de game over que muestra un texto
man_menu_game_over_clock::
	call set_interr_over
	call init_music_perder
	
	call cpct_waitVSYNC_asm
    call render_clean_screen

    cpctm_setBorder_asm HW_BLACK

    ld hl, #_game_over_z_end
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm

	call entityman_reset_game

    _game_over_clock:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Return				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	Space_Pressed_Over_Clock

    jr _game_over_clock

    Space_Pressed_Over_Clock:
    	pop hl
    	pop hl
    	pop hl
    	pop hl

    	jp llamadas_principales
ret

;;Funcion de game win que muestra un texto
man_menu_game_win::
	call cpct_waitVSYNC_asm
    call render_clean_screen

    call set_interr_over
	call init_music_ganar

    cpctm_setBorder_asm HW_BLACK

    ld hl, #_game_win_z_end
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm


    ld bc, #0x8C05        ;;y=140(0x8C), x=5(0x05)
	ld hl, #HistoriaWin1
	call render_text

	ld bc, #0x9609        ;;y=150(0x96), x=9(0x09)
	ld hl, #HistoriaWin2
	call render_text

	call entityman_reset_game

    _game_win:
	    call cpct_scanKeyboard_f_asm

		ld 	hl,	#Key_Return				;;Cargar Space en hl
		call cpct_isKeyPressed_asm
		jr	nz,	Space_Pressed_Win

    jr _game_win

    Space_Pressed_Win:
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl
    	pop hl

    	jp llamadas_principales
ret