Après ce (très) long temps d'attente le dernier (?) tutorial de la série "SOTB", avec cette fois-ci le personnage animé !
L'image utilisée est la même que celle du tutorial précédent (le n°4 pour ceux qui suivent !) puisque celle-ci contenait déjà les sprites et les masques que nous allons utiliser ici.
Voici sans plus attendre le listing:
- Code: Tout sélectionner
' ---------------------------------
' Tutorial "SOTB" n°5 -> Le perso
' ---------------------------------
'
OPENW #1,_X / 2 - 320,_Y / 2 - 200,640,400,%001110000
TITLEW #1,"SOTB !"
'
Hscreen1& = CREATEBMP(800,600)
Hscreen2& = CREATEBMP(640,480)
Hsc1& = MEMDC(_DC(1))
Hsc2& = MEMDC(_DC(1))
SETBMP Hsc1&,Hscreen1&
SETBMP Hsc2&,Hscreen2&
'
FrameTime% = 10 ' Default is 100Hz (init Sync)
'
SETDC Hsc1&
IF EXIST("sotb.bmp")
adr& = LOADBMP("sotb.bmp")
PUT 0,0,adr&
FREEBMP adr&
ENDIF
SETDC _DC(1)
REPEAT
PEEKEVENT
IF MENU(1) = 21
@redraw
ENDIF
@anim_fond
@anim_perso
@Sync
' Transfert Logic -> Physic
BITBLT Hsc2&,0,0,640,480,_DC(1),0,0,SRCCOPY
UNTIL MENU(1) = 4 OR MOUSEK = 2
CLOSEW #1
END
'
PROCEDURE redraw
BITBLT Hsc1&,0,0,640,400,_DC(1),0,0,SRCCOPY
RETURN
'
PROCEDURE anim_fond
' ------------------------------------------------------------
' Anime le fond et le transfère dans l'écran logique 2 (Hsc2&)
' ------------------------------------------------------------
' Nuage 0
BITBLT Hsc1&,15,0,640,42,Hsc1&,10,0,SRCCOPY
BITBLT Hsc1&,10,0,640,42,Hsc1&,635,0,SRCCOPY
' Nuage 1
BITBLT Hsc1&,14,42,640,80,Hsc1&,10,42,SRCCOPY
BITBLT Hsc1&,10,42,640,80,Hsc1&,636,42,SRCCOPY
' Nuage 2
BITBLT Hsc1&,13,122,640,38,Hsc1&,10,122,SRCCOPY
BITBLT Hsc1&,10,122,640,38,Hsc1&,637,122,SRCCOPY
' Nuage 3
BITBLT Hsc1&,12,160,640,18,Hsc1&,10,160,SRCCOPY
BITBLT Hsc1&,10,160,640,18,Hsc1&,638,160,SRCCOPY
' Montagnes
BITBLT Hsc1&,11,178,640,146,Hsc1&,10,178,SRCCOPY
BITBLT Hsc1&,10,178,640,146,Hsc1&,639,178,SRCCOPY
' Herbe 0
BITBLT Hsc1&,12,324,640,4,Hsc1&,10,324,SRCCOPY
BITBLT Hsc1&,10,324,640,4,Hsc1&,638,324,SRCCOPY
' Herbe 1
BITBLT Hsc1&,13,328,640,6,Hsc1&,10,328,SRCCOPY
BITBLT Hsc1&,10,328,640,6,Hsc1&,637,328,SRCCOPY
' Herbe 2
BITBLT Hsc1&,14,334,640,14,Hsc1&,10,334,SRCCOPY
BITBLT Hsc1&,10,334,640,14,Hsc1&,636,334,SRCCOPY
' Herbe 3
BITBLT Hsc1&,15,348,640,22,Hsc1&,10,348,SRCCOPY
BITBLT Hsc1&,10,348,640,22,Hsc1&,635,348,SRCCOPY
' Transfert Fond -> logic 2
BITBLT Hsc1&,10,0,640,366,Hsc2&,0,0,SRCCOPY
RETURN
'
PROCEDURE anim_perso
' Transfert Personnage -> Logic
BITBLT Hsc1&, p& * 65,370,64,103,Hsc2&,292,250,MERGEPAINT
BITBLT Hsc1&, p& * 65,477,64,103,Hsc2&,292,250,SRCAND
INC t&
IF t& = 8
INC p&
IF p& > 5
p& = 0
ENDIF
t& = 0
ENDIF
RETURN
'
PROCEDURE Sync
DO
Time% = TIMER
Delay% = Time% - OldTime%
IF Delay% < 0 THEN Delay% = FrameTime%
PEEKEVENT
EXIT IF Delay% > FrameTime%
LOOP
OldTime% = Time%
RETURN
Ce qui change ? on a juste ajoûté une procédure anim_perso qui va gérer l'animation et l'affichage du personnage.
L'animation est bien entendu effectuée par l'affichage successif de plusieurs images représentant les déplacements successifs du personnage.
Sans entrer dans les détails, on va afficher sur l'écran logique "2" successivement un masque, puis l'image proprement dite du personnage.
Ensuite comme précédement on tranfère cet écran logique "2" dans l'écran physique.
Donc pour résumé:
On anime le fond (logique "1") -> On transfère ce fond animé dans une autre zone mémoire (logique "2") -> On affiche le personnage par dessus en changeant l'image afin de créer l'animation (c'est à celà que sert la variable p& qui varie de 0 à 5 (6 images).
La variable t& sert juste à ralentir l'animation du personnage sinon il la joue à la "Speedy Gonzales".
Voilà c'est la fin (sniff) ...
@+
Fantomas