; JUSTIN and the last Abbey - GAME Scripts

;
; PAINT SCRIPTS
;

ENTERING SCREEN 3 ; Entramos en la pantalla 4
   IF FLAG 2 = 0  ; Si el usuario no cogio el objeto
   THEN
      SET TILE (7, 8) = 39 ; pon el grafico 22 en (7,8)
      SET_FIRE_ZONE 105, 113, 127, 143 ; cuadrado del punto 7 y 8
   END                                 ; por 16 y mas menos 15
END

ENTERING SCREEN 7
   ; Pintar espada y zona activa
   IF FLAG 3 = 0
   THEN
      SET TILE (11, 8) = 38
      SET_FIRE_ZONE 169, 116, 191, 143
   END

   ; Borrar barril si cayo
   IF FLAG 5 = 1
   THEN
      SOUND 7
      SET TILE (12, 4) = 0
   END
END

ENTERING SCREEN 12
   IF FLAG 4 = 0
   THEN
      SET TILE (13, 2) = 37
      SET_FIRE_ZONE 201, 17, 223, 47
   END
END

; BARREL SPECIAL CODE

ENTERING SCREEN 35
   IF FLAG 5 = 0
   THEN
       SET TILE (14, 3) = 20
   END
   
   IF FLAG 5 = 1
   THEN
       SOUND 8
       SET TILE (12, 2) = 7
       SET TILE (14, 2) = 7
       SET TILE (13, 5) = 14
   END
END


;
; GET SWORD CODE
;

PRESS_FIRE AT SCREEN 3 ; Entramos en la pantalla 4
   IF FLAG 2 = 0      ; Si el usuario no cogio el objeto
   IF PLAYER_TOUCHES 7, 8 ; Si el usuario toca el tile 
   THEN
       SET FLAG 2 = 1 ; seteamos que la hemos cogido
       INC FLAG 1     ; incrementamos los objetos recogidos
       EXTERN 0       ; actualizamos el marcador y mandamos mensaje (case 0)
       SOUND 7        ; petamos el beeper!
       SET TILE (7, 8) = 0 ; borramos la espada de pantalla
   END
END

PRESS_FIRE AT SCREEN 7
   IF FLAG 3 = 0 ; Coger trozo de espada
   IF PLAYER_TOUCHES 11, 8
   THEN
       SET FLAG 3 = 1
       INC FLAG 1
       EXTERN 2
       SOUND 7
       SET TILE (11, 8) = 0
   END

   IF FLAG 5 = 0 ; Tirar barril, animacion
   IF PLAYER_TOUCHES 11, 4
   THEN
       SET TILE (12, 4) = 0
       SET FLAG 5 = 1
       EXTERN 10
   END
END

PRESS_FIRE AT SCREEN 12
   IF FLAG 4 = 0
   IF PLAYER_TOUCHES 13, 2
   THEN
       SET FLAG 4 = 1
       SET FLAG 1 = 3
       EXTERN 4
       SOUND 7
       SET TILE (13, 2) = 0
   END
END


;
; Laberinth scripts
;

ENTERING SCREEN 9
   IF FLAG 6 = 0
   THEN
       SET TILE (1, 6) = 29
       SET TILE (4, 1) = 24
       SET TILE (8, 4) = 24
   END
   IF FLAG 6 = 1
   THEN
       SET TILE (1, 6) = 30
       SET TILE (4, 1) = 24
   END
   IF FLAG 6 = 2
   THEN
       SET TILE (1, 6) = 30
   END
END

ENTERING SCREEN 37 ; Parte baja del laberinto
   IF FLAG 6 < 2
   THEN
       SET TILE (13, 1) = 29
   END
   IF FLAG 6 = 2
   THEN
       SET TILE (13, 1) = 30
   END
END

PRESS_FIRE AT SCREEN 9 ; Abre primera puerta
   IF FLAG 6 = 0
   IF PLAYER_TOUCHES 1, 6
   THEN
       SET FLAG 6 = 1
       SOUND 7
       SET TILE (8, 4) = 0
       SET TILE (1, 6) = 30
       EXTERN 15 ; Puntua 100 pts
   END
END

PRESS_FIRE AT SCREEN 37 ; Abre segunda puerta
   IF FLAG 6 = 1
   IF PLAYER_TOUCHES 13, 1
   THEN
       SET FLAG 6 = 2
       SOUND 6
       SET TILE (13, 1) = 30
       EXTERN 15 ; Puntua 100 pts
   END
END


;
; Secret Door
;


ENTERING SCREEN 11 ; Puerta secreta, pone BOTON tile especial
   IF TRUE
   THEN 
       EXTERN 11
   END
   IF FLAG 7 = 99 ; Prepare (evita bug loop)
   THEN
       SET FLAG 7 = 1
   END
END

PRESS_FIRE AT SCREEN 11 ; Pulsa el boton
   IF FLAG 7 = 2            ; Flag check 2 arriba para evitar el loop check bug
   IF PLAYER_TOUCHES 2, 8
   THEN
       SOUND 6
       SET TILE (11, 8) = 0 ; Borramos pinchos
       SET TILE (11, 9) = 0 ; Finalmente se abre!
       SET FLAG 7 = 99
   END
   IF FLAG 7 = 0
   IF PLAYER_TOUCHES 2, 8
   THEN
       SOUND 6
       SET TILE (11, 8) = 10 ; Ponemos pinchos XD
       SET FLAG 7 = 99       ; BORRAR ESTO!!
   END
   IF FLAG 7 = 1
   IF PLAYER_TOUCHES 2, 8
   THEN
       SET TILE (11, 8) = 10 ; Ponemos pinchos pa despistar XD
       SOUND 7               ; Pero cambiamos el sonido
       SET FLAG 7 = 2
   END
END

ENTERING SCREEN 38 ; Puerta secreta, pone BOTON tile especial
   IF FLAG 7 = 0
   THEN 
       EXTERN 38
   END
   IF FLAG 7 = 1
   THEN 
       EXTERN 39
   END
END

PRESS_FIRE AT SCREEN 38 ; Pulsa el boton
   IF FLAG 7 = 99
   IF PLAYER_TOUCHES 1, 4
   THEN
       SET FLAG 7 = 0 ; PREPARE
   END
   IF FLAG 7 = 1
   IF PLAYER_TOUCHES 1, 4
   THEN
       SOUND 6
       SET FLAG 7 = 99 ; SET OFF
       EXTERN 38
   END
   IF FLAG 7 = 0
   IF PLAYER_TOUCHES 1, 4
   THEN
       SOUND 6
       SET FLAG 7 = 1 ; Puerta secreta 1 de 2
       EXTERN 39
   END
END

;
; Ending scripts
;

ENTERING SCREEN 26 ; Abrir salida de cueva
   IF FLAG 1 < 4   ; mientras que no hayas abierto la trampilla
   THEN
      SET TILE (5, 2) = 27             ; Lugar donde poner la espada
      SET TILE (2, 4) = 26             ; Trampilla
   END
   IF FLAG 1 = 4   ; tres partes de la espada y trampilla abierta
   THEN
      SET TILE (5, 2) = 28             ; Faltaria colocar el tile nuevo
   END
END

PRESS_FIRE AT SCREEN 26 ; Si el jugador se acerca 
   IF FLAG 1 = 3                ; Tiene las tres partes de la espada
   IF PLAYER_TOUCHES 5, 2
   THEN
       SET FLAG 1 = 4                   ; Condicion para abrir cueva
       SET TILE (2, 4) = 0              ; Trampilla fuera...
       SOUND 8
       SET TILE (5, 2) = 28             ; Lugar donde poner la espada
       EXTERN 15 ; Puntua 100 pts
       END
END

ENTERING SCREEN 13 ; Pantalla final, Win Game condition!
   IF FLAG = 4
   THEN
       WIN GAME
   END
END

