; ; ; ; 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 all CPCtelera constant definitions, macros and variables
.include "cpctelera.h.s"

.area _DATA
.area _CODE


;;; ==========================================
;;; ==========================================
;;; MAIN
;;; ==========================================
;;; ==========================================

_main::
   ;; Movemos la pila a #0x8000 por el doble buffer de 16k
   ld    sp, #0x8000

start:
   jp    resetGame
 cleanGame:
   ;; Pantalla de inicio (PRESS START)
   call  menu_pressStart
   
level_loop:
   ld    a, (lives)
   cp    #0
   jr    z, gameOverScreen    ; Si las vidas llegan a 0, perdemos

   ;; Empieza el nivel
   call  man_level_start

   ;; Si ya no hay más niveles, pasamos a la pantalla final
   ld    a, (currentLevel)
   cp    #6
   jr    nz, level_loop
   
   ;; Pantalla final (Créditos, puntuación final)
   call  menu_credits

   jr start

gameOverScreen:
   call  menu_death

resetGame:
   ld    a, #e_enemy_bat
   ld    (currentEnemy), a

   ld    a, #1
   ld    (currentLevel), a

   add   #0x08
   ld    (starLocation_C0), a
   ld    (starLocation_80_1), a
   ld    (starLocation_80_2), a
   ld    (starLocation_80_3), a

   xor   a
   ld    (levelProgress), a
   
   ld    a, #3
   ld    (lives), a

   ld    a, #60
   ld    (platform_x), a
   
   ld    a, #130    
   ld    (platform_y), a
   
   ld    a, #200      ; Distancia a la que estará la antigua plataforma
   ld    (distance), a


   jp    cleanGame