; ; ; ; MIT License
; ; ; ; 
; ; ; ; Copyright (c) 2021 Ramiro Hernán García Iten / Raúl Ripoll Pérez / Alexandru Marius Cozma
; ; ; ; 
; ; ; ; Permission is hereby granted, free of charge, to any person obtaining a copy
; ; ; ; of this software and associated documentation files (the "Software"), to deal
; ; ; ; in the Software without restriction, including without limitation the rights
; ; ; ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; ; ; ; copies of the Software, and to permit persons to whom the Software is
; ; ; ; furnished to do so, subject to the following conditions:
; ; ; ; 
; ; ; ; The above copyright notice and this permission notice shall be included in all
; ; ; ; copies or substantial portions of the Software.
; ; ; ;
; ; ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; ; ; ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; ; ; ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; ; ; ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; ; ; ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; ; ; ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; ; ; ; SOFTWARE.

; ; ; ; ----------------- AUTHORS ------------------
; ; ; ;     Ramiro Hernán García Iten: rhgi1@alu.ua.es
; ; ; ;     Raúl Ripoll Pérez: rrp42@alu.ua.es
; ; ; ;     Alexandru Marius Cozma: amc246@alu.ua.es
; ; ; ; 
; ; ; ; Art by Sara Alfosea - IG: @Slinfir
; ; ; ; ---------------------------------------------

; ; ; ; Third Party source code used
; ; ; ; ----------------------------
; ; ; ; CPCtelera - owned by ronaldo / (Cheesetea, Fremos, ByteRealms) - GNU Lesser General Public License.


;;-----------------------------LICENSE NOTICE------------------------------------
;;  This file is part of CPCtelera: An Amstrad CPC Game Engine 
;;  Copyright (C) 2018 ronaldo / Fremos / Cheesetea / ByteRealms (@FranGallegoBR)
;;
;;  This program is free software: you can redistribute it and/or modify
;;  it under the terms of the GNU Lesser General Public License as published by
;;  the Free Software Foundation, either version 3 of the License, or
;;  (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU Lesser General Public License for more details.
;;
;;  You should have received a copy of the GNU Lesser General Public License
;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
;;-------------------------------------------------------------------------------








.include "cpctelera.h.s"
   

;;; ==========================================
;;; ==========================================
;;; TRANSITIONS COMPONENT
;;; ==========================================
;;; ==========================================

; Muestra la imagen de inicio
menu_pressStart::
   ; Cargamos la canción de inicio en DE
   ld    de, #_song_menu
   ; Llama al manager de interrupciones
   call  man_interruption_init
   call  change_screen_to_C000

   ; Borde negro
   cpctm_setBorder_asm HW_BLACK

   ; Establece la paleta a utilizar
   ld    hl, #black
   ld    de, #4
   call  cpct_setPalette_asm

   ; Carga la imagen de inicio
   ld    hl, #_screen_pressStart_z_end
   ld    de, #0xFFFF
   call  cpct_zx7b_decrunch_s_asm

   ; Establece la paleta a utilizar
   ld    hl, #pressStart
   call  transition_layers_toPallete

pressStart_loop:
   ; Escanea el teclado
   call cpct_scanKeyboard_f_asm

   ; Comprueba si se ha pulsado alguna tecla...
   ; NOTA: en los juegos siempre dice PULSA START pero no siempre hay tecla START,
   ; así que acepta cualquiera que le eches xdd
   call  cpct_isAnyKeyPressed_asm
   jr    z, pressStart_loop
   call  man_interruption_stop
   ret   ; Si se ha pulsado, empezamos el juego


; Muestra la pantalla inicial antes de empezar un nivel
menu_levelStart::
   call  change_screen_to_C000

   ld    c, #(HW_BLACK + 64)
   call  transition_layers
   
   ;    Con ldir cargo la información a la que apunta HL a la 
   ; posición a la que apunta DE tantos bytes como diga BC
   ld    de, #menuBase        ; Los dos primeros colores de fondo 
   inc   de                   ; son comunes para todos.
   inc   de

   ld    hl, #menuDiff        ; Los dos últimos los marca el nivel
   ld    bc, #0x0000          
   ld    a, (currentLevel)    ; que estemos a punto de empezar.
   dec   a
   sla   a
   ld    c, a
   add   hl, bc
   ld    c, #0x02
   ldir  

   ld    hl, #menuBase      
   ld    de, #4               
   call  cpct_setPalette_asm

   ld    a, (currentLevel)    ; Cambiamos el texto según el nivel
   add   #0x30                ; que vayamos a empezar.
   ld    (levelNumber), a
   add   #3
   ld    (timeNumber), a

   ld    de, #0xC2F1                ; Texto
   ld    hl, #levelText              
   ld    bc, #0x0002
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xF2A1
   ld    hl, #levelText
   ld    bc, #0x0003
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xC430
   ld    hl, #timeText              
   ld    bc, #0x0002
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xF3E0
   ld    hl, #timeText
   ld    bc, #0x0003
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xE732
   ld    a, (currentLevel)
   cp    #1
   jr    nz, lvl1Hint
      ld   hl, #level1Hint
      jp    endHints
 lvl1Hint:
   cp    #2
   jr    nz, lvl2Hint
      ld   hl, #level2Hint
      jp    endHints
 lvl2Hint:
   cp    #3
   jr    nz, lvl3Hint
      ld   hl, #level3Hint
      jp    endHints
 lvl3Hint:
   cp    #4
   jr    nz, lvl4Hint
      ld   hl, #level4Hint
      jp    endHints
 lvl4Hint:
      ld   hl, #level5Hint
      jp    endHints
 endHints:
   ld    de, #0xC5AB
   ld    bc, #0x0003
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xF3E0
   ld    hl, #timeText
   ld    bc, #0x0003
   call  cpct_drawStringM1_f_asm 

   ld    a, (lives)
   add   #0x30
   ld    (livesNumber), a

   ld    de, #0xE776
   ld    hl, #livesText
   ld    bc, #0x0003
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xC000
   ld    b, #187
   ld    c, #64
   call  cpct_getScreenPtr_asm
   ex    de, hl

   ld    hl, #_lives
   ld    b, #10
   ld    c, #5
   call cpct_drawSprite_asm

   ld    b, #0xFF
   call  cpct_waitHalts_asm      ; Dejamos la pantalla escrita un segundo (aprox xd)
   ld    b, #0xFF
   call  cpct_waitHalts_asm      ; (0xFF + 0x2D = 0x12C = 300 (1s))

   ld    c, #(HW_BLACK + 64)
   call  transition_inmediate    ; Transición a negro

   ret

;; Pantalla final de GAME OVER
menu_death::
   call  change_screen_to_C000

   ld    hl, #gameOver      
   ld    de, #3              
   call  cpct_setPalette_asm

   ld    de, #0xFB8F
   ld    hl, #gameOverText              
   ld    bc, #0x0001
   call  cpct_drawStringM1_f_asm 

   ld    de, #0xEB8F
   ld    hl, #gameOverText              
   ld    bc, #0x0002
   call  cpct_drawStringM1_f_asm 
   
   ld    b, #0xFF
   call  cpct_waitHalts_asm      ; Dejamos la pantalla escrita un segundo (aprox xd)
   ld    b, #0xFF
   call  cpct_waitHalts_asm      ; (0xFF + 0x2D = 0x12C = 300 (1s))

   ld    c, #(HW_BLACK + 64)
   call  transition_inmediate    ; Transición a negro
   ret

; Muestra la pantalla final de créditos
menu_credits::
   ; Cargamos la canción de inicio en DE
   ld    de, #_song_menu
   ; Llama al manager de interrupciones
   call  man_interruption_init
   call  change_screen_to_C000

   ; Borde negro
   cpctm_setBorder_asm HW_BLACK

   ; Establece la paleta a utilizar
   ld    hl, #black
   ld    de, #4
   call  cpct_setPalette_asm

   ; Carga la imagen de inicio
   ld    hl, #_screen_credits_z_end
   ld    de, #0xFFFF
   call  cpct_zx7b_decrunch_s_asm

   ; Establece la paleta a utilizar
   ld    hl, #credits
   call  transition_layers_toPallete

credits_loop:
   ; Escanea el teclado
   call cpct_scanKeyboard_f_asm

   ; Comprueba si se ha pulsado alguna tecla...
   call  cpct_isAnyKeyPressed_asm
   jr    z, credits_loop
   call  man_interruption_stop
   ret