;;####################################################################
;;# 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 "game.h.s"

relojitoMusica: .db #0x05



interr_musica::
    push af
    push bc
    push de 
    push hl

    ld a, (relojitoMusica)
    dec a
    jr nz, cambiar_contador
    ld (relojitoMusica), a

    call cpct_akp_musicPlay_asm

    ld a, #0x05    

    cambiar_contador:
    ld (relojitoMusica), a

    pop hl
    pop de 
    pop bc
    pop af

    ei
reti

interr_musica_over::
    push af
    push bc
    push de 
    push hl

    ld a, (relojitoMusica)
    dec a
    jr nz, cambiar_contador_over
    ld (relojitoMusica), a

    call cpct_akp_musicPlay_asm

    ld a, #0x06    

    cambiar_contador_over:
    ld (relojitoMusica), a

    pop hl
    pop de 
    pop bc
    pop af

    ei
reti


init_music:
    ld de, #_cancionjuego
    call cpct_akp_musicInit_asm
ret

init_music_perder::
    ld de, #_cancionperder
    call cpct_akp_musicInit_asm
ret

init_music_ganar::
    ld de, #_cancionvictoria
    call cpct_akp_musicInit_asm
ret

init_music_menu::
    ld de, #_cancionmenu
    call cpct_akp_musicInit_asm
ret


;;Iniciar el juego
man_game_init::
    call cpct_akp_stop_asm
    
    call init_music


    call screen_init

    call render_init

    call entityman_init

    call lifes_init

    call level_init
    
    call init_camera

    
    call render_tilemap
ret

;;Bucle principal del juego
man_game_play::
    cpctm_setBorder_asm HW_PASTEL_CYAN

    call clock_init

	loop:     
        ;;cpctm_setBorder_asm HW_RED
        call render_update

        ;;cpctm_setBorder_asm HW_PINK
        call paint_level

        call paint_clock

        call paint_lifes      

        ;;cpctm_setBorder_asm HW_BLUE
        call collisions_update

        ;;cpctm_setBorder_asm HW_WHITE
        call input_update

        ;;cpctm_setBorder_asm HW_YELLOW
        call physics_update

        ;;cpctm_setBorder_asm HW_PURPLE
        call clock_update

        ;;cpctm_setBorder_asm HW_LIME
        call entityman_update

        ;;cpctm_setBorder_asm HW_WHITE
        call paint_level
        
        call paint_clock

        call cpct_waitVSYNC_asm

    jr    loop
ret 
