;; MIT License
;; 
;; Copyright (c) 2021 capAI / Aitana Devis  Ávila (@AitanaDevis) / Carlos Peñarrubia Morcillo  (@carlospm12) / Pablo Ruiz Ponce (@pabloruizp)
;; 
;; 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.

;;/////////////////////
;; CONSTANS AND GLOBALS
;;/////////////////////

.globl cpct_memcpy_asm

NIVEL_SUELO = #170
P_H_INITIAL = #16
nullptr = #0x00
GRAVITY = #-1


;;/////////////////////
;; PLAYER DEFINITION
;;/////////////////////

;;; MACRO FOR DEFINING A PLAYER 

.macro DefinePlayer _NAME, P_X, P_Y, P_W, P_H, P_JUMP, P_PREV, P_VY, P_JUMP_COUNTER, P_STATE, P_SPR, P_ANIM, P_ANIM_STATE, P_ANIM_COUNTER, P_PREV_POINTER1, P_PREV_POINTER2
_NAME::
    .db P_X
    .db P_Y
    .db P_W
    .db P_H
    .db P_JUMP ;;if its jumping
    .dw P_PREV
    .db P_VY
    .db P_JUMP_COUNTER ;;if its jumping
    .db P_STATE ;;0 if standing, 1 if crouched (agachado)
    .dw P_SPR ;;puntero al sprite
    .dw P_ANIM ;;puntero a la animación 
    .db P_ANIM_STATE
    .db P_ANIM_COUNTER
    .dw P_PREV_POINTER1
    .dw P_PREV_POINTER2
.endm

defaultFrames == 10 ;;animation duration frames

.globl _player
BASE_WIDTH_PLAYER = 4

P_X = 0 
P_Y = 1 
P_W = 2 
P_H = 3 
P_JUMP = 4       ;; VARIABLE PARA COMPROBAR SI ESTA EN EL AIRE
P_PREV = 5      ;;(2) check if still alive
P_VY = 7
P_JUMP_COUNTER = 8
P_STATE = 9        ;; 0 si está de pie, 1 si está agachado
P_SPR = 10 ;;(2)
P_ANIM = 12 ;;(2)
P_ANIM_STATE = 14
P_ANIM_COUNTER = 15
P_PREV_POINTER1 = 16
P_PREV_POINTER2 = 18

SIZE_PLAYER = 20

;;/////////////////////
;; ENTITY DEFINITION
;;/////////////////////
.macro DefineEntity E_TIPO, E_COMPONENTE, E_X, E_Y, E_OFFSET_L, E_OFFSET_H, E_W, E_H, E_PREV, E_SPR, E_AI_COUNTER 
    .db E_TIPO
    .db E_COMPONENTE
    .db E_X
    .db E_Y
    .db E_OFFSET_L
    .db E_OFFSET_H
    .db E_W 
    .db E_H
    .dw E_PREV 
    .dw E_SPR
    .db E_AI_COUNTER
.endm

E_TIPO = 0
E_COMPONENTE = 1
;; COMPONENTE 1 (IA)
;; COMPONENTE 2 (NO-RENDER)
E_X = 2
E_Y = 3
E_OFFSET_L = 4           ;; (2)
E_OFFSET_H = 5
E_W = 6
E_H = 7
E_PREV = 8            ;; (2) indicates whether there's AI or not
E_SPR_L = 10        ;;sprite pointer (2)
E_SPR_H = 11
E_AI_COUNTER = 12


SIZE_ENTITY = 13 


;; POR ULTIMO HAY QUE AÑADIR UN ENTERO QUE FUNCIONE COMO MASCARA PARA DETECTAR COLISIONES
;; ESTE ATRIBUTO NOS INDICA CONTRA QUE TIPOS COLISIONO


E_TYPE_INVALID = #0x00
E_TYPE_DEAD = #0x01
E_TYPE_DEFAULT = #0x02

E_CMP_RENDER = #0x01      ;; ENTIDAD SIN MOVIMIENTO
E_CMP_MOVABLE = #0x02     ;; ENTIDAD QUE SE MUEVE POR PANTALLA
E_CMP_COLLIDER = #0x20     ;; DEFINE SI EN ESTA ENTIDAD HAY QUE COMPROBAR COLISIONES
E_CMP_DEFAULT = #0x7F

;;/////////////////////
;;      MAPAS
;;/////////////////////
SIZE_MAPA_1 = #SIZE_ENTITY*12 
.globl _mapa1

SIZE_MAPA_2 = #SIZE_ENTITY*29
.globl _mapa2

SIZE_MAPA_3 = #SIZE_ENTITY*21  
.globl _mapa3

SIZE_MAPA_4 = #SIZE_ENTITY*25  
.globl _mapa4

SIZE_MAPA_5 = #SIZE_ENTITY*33  
.globl _mapa5

SIZE_MAPA_6 = #SIZE_ENTITY*35
.globl _mapa6

SIZE_MAPA_7 = #SIZE_ENTITY*32
.globl _mapa7

SIZE_MAPA_8 = #SIZE_ENTITY*33
.globl _mapa8

SIZE_MAPA_9 = #SIZE_ENTITY*36 
.globl _mapa9

MAX_NIVEL = #9 