;;-----------------------------LICENSE NOTICE------------------------------------
;;  This file is part of Viking Hangover
;;  Copyright (C) 2021 Ahmed Begga / Érika Moreno / Adriana Morejón (@ComputosGame)
;;
;;  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 "generator.h.s"
.include "animations.h.s"
.include "../man/game.h.s"
.include "../man/entity.h.s"


animation_viking:
    .db #5                 
    .dw #_spr_viking
    .db #5                 
    .dw #_spr_viking_animation
    .db #0
    .dw #animation_viking

animation_shot1:
    .db #5                 
    .dw #_spr_vaso_rojo
    .db #5                 
    .dw #_spr_vaso_rojo_animation
    .db #0
    .dw #animation_shot5

animation_shot2:
    .db #5                 
    .dw #_spr_vaso_morado
    .db #5                 
    .dw #_spr_vaso_morado_animation
    .db #0
    .dw #animation_shot3

animation_shot3:
    .db #5                  ;;actual=0
    .dw #_spr_vaso_amarillo
    .db #5                  ;;actual=3
    .dw #_spr_vaso_amarillo_animation
    .db #0
    .dw #animation_shot1

animation_shot4:
    .db #5                 
    .dw #_spr_vaso_azul
    .db #5                 
    .dw #_spr_vaso_azul_animation
    .db #0
    .dw #animation_shot2

animation_shot5:
    .db #5                 
    .dw #_spr_vaso_verde
    .db #5                 
    .dw #_spr_vaso_verde_animation
    .db #0
    .dw #animation_shot4

animation_bottle:
    .db #5                 
    .dw #_spr_botella
    .db #5                 
    .dw #_spr_botella_animation
    .db #0
    .dw #animation_bottle

animation_explosion_shot:
    .db #3                 
    .dw #_spr_brigui
    .db #3          
    .dw #_spr_brigui
    .db #3          
    .dw #_spr_brigui
    .db #3          
    .dw #_spr_brigui

animation_explosion_botella:
    .db #3                  
    .dw #_spr_brigui_agua
    .db #3          
    .dw #_spr_brigui_agua
    .db #3          
    .dw #_spr_brigui_agua
    .db #3          
    .dw #_spr_brigui_agua


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;   Checks if any entity colided                        ;;
;;                                                       ;;
;;Required:                                              ;;
;;     -                                                 ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_animations_update_one:
    ld a, e_count_anime(ix)
    dec a
    ld e_count_anime(ix),a
    ret nz 

    ld b, #3
    ld a, e_current_anime(ix)
    add a, b
    ld e_current_anime(ix), a

    load_anim:
        ld l, e_anime2(ix)
        ld h, e_anime1(ix)
        ld c, e_current_anime(ix)
        ld b, #0

        add hl, bc
        ld a, (hl)
        or a
        jp z, reset_anim
        ld e_count_anime(ix), a
        call actualiza_sprite
    ret

actualiza_sprite:
        inc hl
        ld a, (hl)
        ld e_sprite2(ix), a
        
        inc hl
        ld a, (hl)
        ld e_sprite1(ix), a
    ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;   Checks if all entity colided                        ;;
;;                                                       ;;
;;Required:                                              ;;
;;     -                                                 ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_animations_update::
    ld a, #e_cmp_anime
    ld hl, #sys_animations_update_one
    call man_entity_forall
    ret
reset_anim:
    ld e_current_anime(ix), #0
    jp load_anim
