;;-----------------------------LICENSE NOTICE------------------------------------
;;  This file is part of CPCtelera: An Amstrad CPC Game Engine 
;;  Copyright (C) 2021 Daniel José García Evans, Iván Alejandro Ontano Herrera,
;;  Sergio Izquierdo Pintado (PyroClastic Software)
;;
;;  Special Thanks to Ennio Fernando Velásquez Berlingeri (PyroBombastic)
;;
;;  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/>.

;;
;;MAIN HEADER1
;;

.include "cpctelera.h.s"
.globl cpct_disableFirmware_asm
.globl cpct_waitVSYNC_asm
;;.globl cpctm_setBorder_asm    ;;no necesita globl al ser una macro

.globl _inicio_end
;.globl _controles_end
.globl _gameover_end
;.globl _credits_end

;;
;;ENTITY MANAGER HEADER 
;;
e_cmps       = 0
e_x          = 1
e_y          = 2
e_velX       = 3
e_velY       = 4
e_sprite     = 5;;6    ;;2 bytes
e_w          = 7
e_h          = 8
e_posPrev    = 9;;10   ;;2 bytes
;;e_anime     = 11;;12    ;;2 minutos de cancion
e_points     = 11
e_clock      = 12

e_size       = 13


;; Max Number of Entities
max_entities = 9

;;--------------------------
;;  Components
;;  Declarations of entity component bits
;;--------------------------

e_cmps_alive         = 0x80  ;;<<7
e_cmps_render        = 0x40  ;;<<6
e_cmps_physics       = 0x20  ;;<<5
e_cmps_gravity       = 0x10  ;;<<4
e_cmps_collider      = 0x08  ;;<<3 que comprueba las colisiones que tenga con los collider
e_cmps_collisionable = 0x04  ;;<<2 que es un elemento con el que un collider puede hacer colision
e_cmps_enemy         = 0x02  ;;<<1
e_cmps_animation     = 0x01  ;;<<0

;; Special Values
e_cmps_invalid = 0x00
e_cmps_default = 0xFF
e_cmps_dead    = #0x7F  ;;para poner el alive a 0 sin alterar lo demas (and)

;;--------------------------
;;  Functions
;;  Declarations of global public functions
;;--------------------------

.globl cpct_getRandom_xsp40_u8_asm  ;;recomendada por el profesor
.globl man_entity_first
.globl man_entity_next
.globl man_entity_first_iy
.globl man_entity_next_iy
;;.globl man_entity_create_from_tmpl
.globl man_entity_reset_variables
.globl man_entity_init
;;.globl man_entity_create_all_enemies
.globl man_entity_update
.globl man_entity_for_all_matching
.globl man_entity_update_score
.globl man_entity_change_difficulty

.globl lives
.globl score
.globl current_map

.globl enemy_timer_max
.globl spawn_counter

.globl prob_ant
.globl prob_mosquito


;;#####JUGADOR
tmpl_hero:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_physics | e_cmps_gravity | e_cmps_collider)
   .db #38, #16 ;;pos
   .db #0, #0  ;;vel
   .dw #_main_char_00
   .db #4, #16 ;;tam sprite
   .dw #0x00C8 ;;pos previa
   .db #0, #0  ;;puntuacion y reloj

tmpl_sword:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_physics | e_cmps_collider)
   .db #38, #16 ;;pos   ;;y + h del personaje
   .db #0, #0  ;;vel
   .dw #_main_char_12
   .db #4, #16 ;;tam
   .dw #0x00C8 
   .db #0, #0  ;;puntuacion y reloj


;;_maincharacter_walk:           ;; Creamos un array con los sprites de la animación de caminar
;;    .dw #_main_char_01
;;    .dw #_main_char_02
;;    .dw #_main_char_03
;;    .dw 0x0000                  ;; Null Pointer
;;    .dw #_maincharacter_walk     ;; Puntero al principio para que se vuelva a llamar al final y se repita la animacion
;;

;;#####PLATAFORMAS
tmpl_plat_left:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_collisionable)
   .db #8, #88 ;;pos
   .db #0, #0  ;;vel
   .dw #_plat_char1_0
   .db #16, #16 ;;tam   ;;4 tiles de ancho
   .dw #0x00C8 
   .db #0, #0  ;;puntuacion y reloj

tmpl_plat_central:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_collisionable)
   .db #32, #136 ;;pos
   .db #0, #0  ;;vel
   .dw #_plat_char1_2
   .db #16, #16 ;;tam   ;;4 tiles de ancho
   .dw #0x00C8 
   .db #0, #0  ;;puntuacion y reloj


tmpl_plat_right:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_collisionable)
   .db #56, #88 ;;pos
   .db #0, #0  ;;vel
   .dw #_plat_char1_1
   .db #16, #16 ;;tam   ;;4 tiles de ancho
   .dw #0x00C8 
   .db #0, #0  ;;puntuacion y reloj


;;tmpl_plat_upper:
;;   .db #(e_cmps_alive | e_cmps_render | e_cmps_collisionable)
;;   .db #32, #40 ;;pos
;;   .db #0, #0  ;;vel
;;   .dw #_plat_char_1
;;   .db #16, #16 ;;tam   ;;4 tiles de ancho
;;   .dw #0x00C0 
;;   .db #0, #0  ;;puntuacion y reloj


;;#####ENEMIGOS
tmpl_ant:
    .db #(e_cmps_alive | e_cmps_render | e_cmps_physics | e_cmps_enemy | e_cmps_collisionable)  ;;este no necesita gravity porque siempre esta en el suelo
    .db #72, #168 ;;pos a ras de suelo
    .db #1, #0  ;;vel
    .dw #_enemies_char_06
    .db #8, #16 ;;tam
    .dw #0x00C8 
    .db #5, #1  ;;puntuacion y reloj


tmpl_mosquito:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_physics | e_cmps_enemy | e_cmps_collisionable)
   .db #0, #56 ;;pos
   .db #1, #0  ;;vel
   .dw #_enemies_char_02
   .db #8, #16 ;;tam
   .dw #0x00C8 
   .db #10, #1  ;;puntuacion y reloj


tmpl_goblin:
   .db #(e_cmps_alive | e_cmps_render | e_cmps_physics | e_cmps_enemy | e_cmps_gravity | e_cmps_collider | e_cmps_collisionable)
   .db #0, #168 ;;pos a ras de suelo
   .db #1, #0  ;;vel
   .dw #_main_char_14
   .db #4, #16 ;;tam
   .dw #0x00C8 
   .db #21, #1


;;
;;RENDER SYSTEM HEADER
;;
;; Global Sprite Tags
.globl _g_palette

.globl _main_char_00
.globl _main_char_01
.globl _main_char_02
.globl _main_char_03
.globl _main_char_04
.globl _main_char_05
.globl _main_char_06
.globl _main_char_07
.globl _main_char_08
.globl _main_char_09
.globl _main_char_10
.globl _main_char_11
.globl _main_char_12
.globl _main_char_13
.globl _main_char_14
.globl _main_char_15
.globl _main_char_16
.globl _main_char_17

.globl _char_heart_0
.globl _char_heart_1
.globl _char_heart_2
.globl _char_heart_3
.globl _char_heart_4

.globl _plat_char1_0
.globl _plat_char1_1
.globl _plat_char1_2
.globl _plat_char2_0
.globl _plat_char2_1
.globl _plat_char3_0
.globl _plat_char3_1

.globl _enemies_char_00
.globl _enemies_char_01
.globl _enemies_char_02
.globl _enemies_char_03
.globl _enemies_char_04
.globl _enemies_char_05
.globl _enemies_char_06
.globl _enemies_char_07
.globl _enemies_char_08
.globl _enemies_char_09

;; Global Animation Tags
;;.globl _maincharacter_walk
.globl _map_tiles_00
.globl _map_tiles_01
.globl _map_tiles_02
.globl _map_tiles_03
.globl _map_tiles_04
.globl _map_tiles_05
.globl _map_tiles_06
.globl _map_tiles_07
.globl _map_tiles_08
.globl _map_tiles_09

;; Global Call Functions
.globl cpct_getScreenPtr_asm
.globl cpct_drawSolidBox_asm
.globl cpct_drawSprite_asm
.globl cpct_setVideoMode_asm
.globl cpct_setPALColour_asm
.globl cpct_setPalette_asm
.globl cpct_setDrawCharM0_asm
.globl cpct_drawCharM0_asm
.globl cpct_drawStringM0_asm

;; Global Public Functions
.globl sys_render_init
.globl sys_render_update
.globl sys_render_update_entity
.globl sys_render_draw_entity
;;.globl sys_render_draw_entity_iy
.globl sys_render_clear_prev_pos_entity
.globl sys_render_clear_pos_entity
.globl sys_render_clear_pos_entity_iy
.globl sys_render_palette


;;
;;PHYSICS SYSTEM HEADER
;;
.globl sys_physics_update
.globl cpct_isKeyPressed_asm
.globl cpct_scanKeyboard_i_asm  ;;mas rapido pero usa mas memoria

;;
;;INPUT SYSTEM HEADER
;;
.globl sys_input_update

;;
;;COLISION SYSTEM HEADER
;;
.globl sys_collision_update
.globl sys_collision_check_collision

;;
;;ARTIFICIAL INTELLIGENCE SYSTEM HEADER
;;
.globl sys_ia_update


;;
;;GAME MANAGER HEADER
;;
.globl man_game_update
.globl man_game_init
.globl man_game_reset
.globl man_game_next_map

;;
;;SCREEN MANAGER HEADER
;;
.globl man_screen_init
.globl man_screen_gameOver
.globl cpct_zx7b_decrunch_s_asm

;;
;;USER INTERFACE MANAGER HEADER
;;
.globl man_ui_init
.globl man_ui_delete_heart
.globl man_ui_update_score

;;
;; GLOBALES DE LA MUSICA
;;

.globl _song_ptr
.globl cpct_akp_musicPlay_asm
.globl cpct_akp_musicInit_asm
