FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC

Développement d'applications avec le langage Panoramic
 
AccueilAccueil  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  MembresMembres  Connexion  
Derniers sujets
» Editeur EliP 6 : Le Tiny éditeur avec 25 onglets de travail
chasseur d’astéroïdes V3 Emptypar Yannick Aujourd'hui à 18:32

» Philharmusique
chasseur d’astéroïdes V3 Emptypar jjn4 Aujourd'hui à 13:58

» PANORAMIC V 1
chasseur d’astéroïdes V3 Emptypar papydall Hier à 3:22

» select intégrés [résolu]
chasseur d’astéroïdes V3 Emptypar jjn4 Mer 8 Mai 2024 - 17:00

» number_mouse_up
chasseur d’astéroïdes V3 Emptypar jjn4 Mer 8 Mai 2024 - 11:59

» Aide de PANORAMIC
chasseur d’astéroïdes V3 Emptypar jjn4 Mer 8 Mai 2024 - 11:16

» trop de fichiers en cours
chasseur d’astéroïdes V3 Emptypar lepetitmarocain Mer 8 Mai 2024 - 10:43

» Je teste PANORAMIC V 1 beta 1
chasseur d’astéroïdes V3 Emptypar papydall Mer 8 Mai 2024 - 4:17

» bouton dans autre form que 0
chasseur d’astéroïdes V3 Emptypar leclode Lun 6 Mai 2024 - 13:59

» KGF_dll - nouvelles versions
chasseur d’astéroïdes V3 Emptypar Klaus Lun 6 Mai 2024 - 11:41

» Gestion d'un système client-serveur.
chasseur d’astéroïdes V3 Emptypar Klaus Lun 6 Mai 2024 - 10:23

» @Jack
chasseur d’astéroïdes V3 Emptypar Jack Mar 30 Avr 2024 - 20:40

» Une calculatrice en une ligne de programme
chasseur d’astéroïdes V3 Emptypar jean_debord Dim 28 Avr 2024 - 8:47

» Form(résolu)
chasseur d’astéroïdes V3 Emptypar leclode Sam 27 Avr 2024 - 17:59

» Bataille navale SM
chasseur d’astéroïdes V3 Emptypar jjn4 Ven 26 Avr 2024 - 17:39

Navigation
 Portail
 Index
 Membres
 Profil
 FAQ
 Rechercher
Rechercher
 
 

Résultats par :
 
Rechercher Recherche avancée
Mai 2024
LunMarMerJeuVenSamDim
  12345
6789101112
13141516171819
20212223242526
2728293031  
CalendrierCalendrier
Le Deal du moment : -39%
Ordinateur portable ASUS Chromebook Vibe CX34 Flip
Voir le deal
399 €

 

 chasseur d’astéroïdes V3

Aller en bas 
4 participants
AuteurMessage
Jean Claude

Jean Claude


Nombre de messages : 5950
Age : 69
Localisation : 83 Var
Date d'inscription : 07/05/2009

chasseur d’astéroïdes V3 Empty
MessageSujet: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 15:30

Bonjour à tous,

Vous trouverez sur mon Webdav chasseur d’astéroïdes V3.ZIP (24,6Mb)

Vous y trouverez asterV3.exe pour jouer directement.

Cette version a plusieurs niveaux, mais vous n'avez pas à vous en soucier.
Le niveau augmente avec votre score par palier.
Vous pouvez visualiser cela dans le bandeau.

Mettez le son.

Quelques nouveautés:
La touche P met le jeu en pause
La touche S (Silence) interrompt la répétition en boucle de la musique. (la boucle se termine)
La touche M (Musique) fait repartir la musique

Pour le reste: lisez le générique. (10 secondes environ)

Bug connu: Rarement le jeu s'arrête, mais sans plantage. Je n'ai pas encore trouvé pourquoi.

La mission est très simple, c'est d'améliorer votre score, car il n'y a pas de limites.
Néanmoins les astéroïdes détruit payent plus que les vaisseaux ennemis, c'est le but du jeu.


Voilà, j'espère que ce jeu vous plaira.
Je ne compte pas le modifier, sauf des bricoles. Par contre retournez ici vos réactions, les bug(s) et vos souhait d'amélioration (on ne sait jamais).

Allez chasser l'astéroïde ! Wink
Revenir en haut Aller en bas
papydall

papydall


Nombre de messages : 7008
Age : 73
Localisation : Moknine (Tunisie) Entre la chaise et le clavier
Date d'inscription : 03/03/2012

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 18:39

Je testerai tard dans la soirée.
Revenir en haut Aller en bas
http://papydall-panoramic.forumarabia.com/
Jean Claude

Jean Claude


Nombre de messages : 5950
Age : 69
Localisation : 83 Var
Date d'inscription : 07/05/2009

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 19:08

En début de partie, il faut que tu atteigne 16 points, donc 8 astéroïdes pour que ça commence à bouger.

Je suis entrain de régler les paliers, car ça n'évolue pas assez vite.

voici le dernier réglage (attention, ça ne marche que si tu as téléchargé le dernier ZIP, car il y a des fichiers supplémentaires)

Code:
' AsterV3.bas (Jean Claude, Jicehel, Papydall) (JUIN 2015)

rem ============================================================================

dim n%,i%,at%
dim pi : pi = acos(-1)              : ' mémorise la valeur pi
dim x%,y%,vit_vai%                  : ' position et vitesse du vaisseau
dim d  : d = pi/2                  : ' direction (c'est le cap) de départ du vaisseau (vers le haut)
dim Nb_tirs%,Cpt_tirs% : Nb_tirs%=5 : ' Nombre de tirs autorisés et compteur de tirs actifs
dim tir$,tir%(Nb_tirs%), tir_x(Nb_tirs%),tir_y(Nb_tirs%),tir_d(Nb_tirs%),vit_mis% : ' Resultat du tir, Tir actif ou non, coord en x et en y du tir et mémoristion de la direction et vitesse
dim Nb_Asteroides%,Cpt_asteroides% : Nb_Asteroides% = 3    : ' Nombre d'Asteroides actifs
dim xA%(Nb_Asteroides%),yA%(Nb_Asteroides%)                : ' Position des asteroides
dim vit_ast_x%(Nb_Asteroides%), vit_ast_y%(Nb_Asteroides%)  : ' Vitesse des asteroides
dim SpriteV%        :' Pour savoir quelle image du vaisseau ami est en service (car d change dans la sub move)
dim score%          :' Pour le score
dim cpt_t_asteroide : ' ralentisseur pour les mouvements de l'asteroid
dim niveau%        :' Niveau du jeu
dim xE%,yE%            :' Position de l'ennemi
dim vit_E%,vit_E_max%,vit_E_min%  :' Vitesse de l'ennemi et son maximum et minimum
dim tirE%              :' Tir ennemi
dim SpriteVE% :' Pour savoir quelle image du vaisseau ennmi est en service

' Déclaration des étiquettes
label touche,boucle_principale,fin,Attente,Repart,Musique
on_error_goto fin

' fichiers audios
sound 197 : file_load 197,"audio/dreamland.wav": ' explosion du vaisseau
sound 198 : file_load 198,"audio/explosion_vaisseau.wav": ' explosion du vaisseau
sound 199 : file_load 199,"audio/explosion_aster.wav"  : ' explosion des asteroides

' création des vaisseaux amis
SPRITE 1 : SPRITE_FILE_LOAD 1,"image/VBG.bmp" : SPRITE_HIDE 1
SPRITE 2 : SPRITE_FILE_LOAD 2,"image/VB.bmp"  : SPRITE_HIDE 2
SPRITE 3 : SPRITE_FILE_LOAD 3,"image/VBD.bmp" : SPRITE_HIDE 3
SPRITE 4 : SPRITE_FILE_LOAD 4,"image/VG.bmp"  : SPRITE_HIDE 4
SPRITE 5 : SPRITE_FILE_LOAD 5,"image/VD.bmp"  : SPRITE_HIDE 5
SPRITE 6 : SPRITE_FILE_LOAD 6,"image/VHG.bmp" : SPRITE_HIDE 6
SPRITE 7 : SPRITE_FILE_LOAD 7,"image/VH.bmp"  : SPRITE_HIDE 7
SPRITE 8 : SPRITE_FILE_LOAD 8,"image/VHD.bmp" : SPRITE_HIDE 8

SPRITE_ANIMATED 11 : SPRITE_ANIMATED_FILE_LOAD 11,5,5,"image/meteore.bmp"  : SPRITE_HIDE 11  : ' explosion astéroide
SPRITE_ANIMATED 12 : SPRITE_ANIMATED_FILE_LOAD 12,5,5,"image/meteore2.bmp" : SPRITE_HIDE 12  : ' explosion vaisseau

i%=19
FOR n% = 0 TO 9
i%=i%+1
SPRITE i% : SPRITE_FILE_LOAD i%,"image/"+str$(n%)+".bmp" : SPRITE_HIDE i%  : ' chiffres pour le score
NEXT n%

FOR n% = 1 TO Nb_Asteroides%
  SPRITE_ANIMATED 29 + n% : ' Créé un sprite pour un astéroide
  SPRITE_ANIMATED_FILE_LOAD 29 + n% ,1,8,"image/rock8.bmp"    : ' Charge le sprite animé correspondant à l'astéroide
  new_asteroide(n%) : SPRITE_SHOW 29 + n%  : ' Créé l'astéroid initial
NEXT n%
Cpt_asteroides% = Nb_Asteroides%

FOR n% = 1 TO Nb_tirs%
  SPRITE 39 + n% : SPRITE_FILE_LOAD 39 + n%,"image/balle.bmp"
  SPRITE_HIDE 39 + n%  : ' le  missile 1 à 5
  tir%(n%) = 0 : ' Au début pas de tir actif
NEXT n%

' Sprites pour le générique.
SPRITE 51 : SPRITE_FILE_LOAD 51,"image/gen3.bmp" : SPRITE_POSITION 51,(screen_x/2)-350,screen_y+200 :' SPRITE_HIDE 51
SPRITE 50 : SPRITE_FILE_LOAD 50,"image/gen1.bmp" : SPRITE_POSITION 50,(screen_x/2)-350,screen_y-40 :' SPRITE_HIDE 50

' création des vaisseaux ennemis
SPRITE 61 : SPRITE_FILE_LOAD 61,"image/VEBG.bmp" : SPRITE_HIDE 61
SPRITE 62 : SPRITE_FILE_LOAD 62,"image/VEB.bmp"  : SPRITE_HIDE 62
SPRITE 63 : SPRITE_FILE_LOAD 63,"image/VEBD.bmp" : SPRITE_HIDE 63
SPRITE 64 : SPRITE_FILE_LOAD 64,"image/VEG.bmp"  : SPRITE_HIDE 64
SPRITE 65 : SPRITE_FILE_LOAD 65,"image/VED.bmp"  : SPRITE_HIDE 65
SPRITE 66 : SPRITE_FILE_LOAD 66,"image/VEHG.bmp" : SPRITE_HIDE 66
SPRITE 67 : SPRITE_FILE_LOAD 67,"image/VEH.bmp"  : SPRITE_HIDE 67
SPRITE 68 : SPRITE_FILE_LOAD 68,"image/VEHD.bmp" : SPRITE_HIDE 68
' boulet ennemi
SPRITE 69 : SPRITE_FILE_LOAD 69,"image/balleE.bmp" : SPRITE_HIDE 69

' scene2D
BACKGND_LOAD "image/espace.bmp"

niveau%=1 : niveau() : cpt_t_asteroide = 0 : Cpt_tirs% = 0

play 197 : generique()

' init
x%=(screen_x/2)+32 : y%=700 : sprite_position 7,x%,y% : SpriteV% = 7 : SPRITE_SHOW 7
scene2d_interval 80
affiscore()
on_key_down touche              : ' Active la gestion de l'appuie des touches

timer 2 : timer_interval 2,20 : on_timer 2,boucle_principale  : ' Activation du timer qui activera les tours de jeu
timer 3 : timer_interval 3,100000 : on_timer 3,Musique  : ' Musique d'ambiance (recommance toutes les minutes)


END

rem ================================ Musique ===================================
Musique:
  play 197
return

rem ================================= PAUSE ====================================
Attente:
timer_off 2 : timer_off 3
on_key_down Repart
return

Repart:
timer_on 3 : timer_on 2 : on_key_down touche
return

rem =============================== Générique ==================================
SUB generique()
DIM_LOCAL X1,Y1,X2,Y2,Y3,Y4
  scene2d_interval 20 : scene2d_on
  X1=0 : Y1=0 : X2=2184 : Y2=1167 : view X1,Y1,X2,Y2
  Y2=600 : Y3=70 : Y4=screen_y+100
' traveling arrière
  repeat
      Y1=Y1+1 : Y2=Y2+1 : view X1,Y1,X2,Y2 : pause 1
      Y3=Y3+2 : SPRITE_POSITION 50,(screen_x/2)-350,Y3
      Y4=Y4-2 : SPRITE_POSITION 51,(screen_x/2)-350,Y4
      pause 1
  until y2>1000 or scancode<>0
  scene2d_off
  pause 2000
  X1=0 : Y1=0 : X2=screen_x : Y2=screen_y : view X1,Y1,X2,Y2
  SPRITE_HIDE 50 : SPRITE_HIDE 51
END_SUB

rem ========================== Réglage des Niveaux =============================
SUB niveau()
    if niveau%=1 then vit_vai%=7 : vit_mis%=14
    if niveau%=2 then vit_vai%=8 : vit_mis%=16
    if niveau%=3 then vit_vai%=9 : vit_mis%=18  : vit_E_max%=8 : vit_E_min%=1
    if niveau%=4 then vit_vai%=10 : vit_mis%=20  : vit_E_max%=9 : vit_E_min%=2
    if niveau%=5 then vit_vai%=11 : vit_mis%=21 : vit_E_max%=10 : vit_E_min%=3
    if niveau%=6 then vit_vai%=12 : vit_mis%=21 : vit_E_max%=12 : vit_E_min%=4
    if niveau%=7 then vit_vai%=13 : vit_mis%=22 : vit_E_max%=16 : vit_E_min%=6
    if niveau%=8 then vit_vai%=14 : vit_mis%=22 : vit_E_max%=18 : vit_E_min%=8
    if niveau%=9 then vit_vai%=15 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=9
    if niveau%=10 then vit_vai%=16 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=10

' réglages
' vit_vai% = 8 :' + => plus rapide
' vit_mis%=20  :' + => plus rapide
' vit_E_min%=2 : ' vitesse ennemi: minimum 2
' vit_E_max%=12 :' vitesse ennemi: + => plus rapide (mais aléatoire >vit_E_min%)

END_SUB

rem ============== Score et réglage des paliers pour les viveaux ===============
SUB affiscore()
    ' affichage du score et progression du niveau par paliers
    if score%=1 then niveau%=niveau%+1  :' 2
    if score%=3 then niveau%=niveau%+1  :' 3
    if score%=5 then niveau%=niveau%+1  :' 4
    if score%=8 then niveau%=niveau%+1 :' 5
    if score%=15 then niveau%=niveau%+1 :' 6
    if score%=20 then niveau%=niveau%+1 :' 7
    if score%=25 then niveau%=niveau%+1 :' 8
    if score%=30 then niveau%=niveau%+1 :' 9
    if score%=35 then niveau%=niveau%+1 :' 10
    caption "CHASSEUR D'ASTEROIDES  -  Score: "+str$(score%)+"  -  Niveau: "+str$(niveau%)
    niveau()
END_SUB

rem ================== Attribution des touches du clavier ======================
touche:
' Touches du pavé numérique
  if KEY_DOWN_CODE = 97 then move(1)                        : ' 1 End
  if KEY_DOWN_CODE = 40 or KEY_DOWN_CODE = 98 then move(2)  : ' 2 Bas
  if KEY_DOWN_CODE = 99 then move(3)                        : ' 3 PgDn
  if KEY_DOWN_CODE = 37 or KEY_DOWN_CODE = 100 then move(4) : ' 4 gauche
  if KEY_DOWN_CODE = 39 or KEY_DOWN_CODE = 102 then move(5) : ' 5 droite
  if KEY_DOWN_CODE = 103 then move(6)                      : ' 6 Home
  if KEY_DOWN_CODE = 38 or KEY_DOWN_CODE = 104 then move(7) : ' 7 haut
  if KEY_DOWN_CODE = 105 then move(8)                      : ' 8 PgUp
  if KEY_DOWN_CODE = 27 then gosub fin                      : ' Echap
  if KEY_DOWN_CODE = 80 then gosub Attente : return
  if KEY_DOWN_CODE = 83 then timer_off 3
  if KEY_DOWN_CODE = 77 then timer_on 3 : play 197
  if KEY_DOWN_CODE = 32 AND Cpt_tirs% < Nb_tirs%
      Cpt_tirs% = Cpt_tirs% + 1
      tir%(Cpt_tirs%) = 1 :  tir_d(Cpt_tirs%) = d  : ' On mémorise qu'un tir est actif et la direction de ce tir
      ' On ajuste la position initale du tir en fonction de la direction du vaisseau
      if d = 5*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 33
      if d = 3*pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y% + 44
      if d = 7*pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 33
      if d = pi then tir_x(Cpt_tirs%) = x%      : tir_y(Cpt_tirs%) = y% + 22
      if d = 0 then tir_x(Cpt_tirs%) = x% + 44 : tir_y(Cpt_tirs%) = y% + 22
      if d = 3*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 11
      if d = pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y%
      if d = pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 11
      sprite_position 39+Cpt_tirs%,tir_x(Cpt_tirs%), tir_y(Cpt_tirs%) : SPRITE_SHOW 39+Cpt_tirs%
  end_if    : ' Fin du traitement d'un appuie sur espace
on_key_down touche
return

rem ==================== Boucle_principale (tour) ==============================
boucle_principale:
timer_off 2: off_key_down
  if niveau%>2
    ' on gére le vaisseau ennemi pour ce tour
    if SpriteVE%=0 then new_ennemi()
    ennemi()
  end_if
  cpt_t_asteroide = cpt_t_asteroide + 1
  if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
  if cpt_t_asteroide = 2 then asteroide(3): ' On gère notre asteroid pour ce tour
  if cpt_t_asteroide = 2 then asteroide(2)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
  FOR i% = 1 TO Nb_Asteroides%
      Test_collision_vaisseau(i%)
  next i%
  if Cpt_tirs% > 0
    for i% = 1 to Cpt_tirs%
      if tir%(i%) = 1 then tir(i%) :  ' Si un tir est actif, on gère son tour
        cpt_t_asteroide = cpt_t_asteroide + 1
        if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(3): ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(2)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
    next i%
  end_if
timer_on 2 : on_key_down touche
return

rem ============================================================================
SUB vaisseau_detruit(Aster%)
    ' animation de la destruction de la cible
    off_key_down
    sprite_position 29 + Aster%,xA%(Aster%)+20,yA%(Aster%)+20 : SPRITE_HIDE SpriteV%
    scene2d_interval 250 : scene2d_on
    sprite_position 12,(xA%(Aster%) - 60),(yA%(Aster%) - 60) : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
    scene2d_off
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau(Aster%)
  Collision_AABB(xA%(Aster%),yA%(Aster%),22,24,x%,y%,32,32) :' vérifier si le vaisseau ami n'est pas en collision avec l'astéroide
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit(Aster%)
    message "Votre vaisseau est détruit!"+chr$(13)+chr$(13)+"Votre score: "+str$(score%) :' fin de partie
    gosub fin
  end_if
' test collision VE avec Aster
  if SpriteVE%<>0
    Collision_AABB(xA%(Aster%),yA%(Aster%),16,16,xE%,yE%,28,28) :' vérifier si le vaisseau ennemi n'est pas en collision avec l'astéroide
    if tir$="OK"
      play 198 : ' explosion vaisseau
    ' animation de la destruction du vaisseau ennemi par aster
    off_key_down
    SPRITE_HIDE SpriteVE%
    scene2d_interval 250 : scene2d_on
    sprite_position 12,xE%-60,yE%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 400 : SPRITE_HIDE 12 : scene2d_off
    SpriteVE%=0 : tirE%=0
    end_if
  end_if
END_SUB

rem ============================================================================
' New_astéroide
SUB new_asteroide(Aster%)
scene2d_interval 500 : scene2d_on
  vit_ast_x%(Aster%)= 0 : vit_ast_y%(Aster%)= 0  : ' On initialise le compteur pour un lancé aléatoire
  while (abs(vit_ast_x%(Aster%)) + abs(vit_ast_y%(Aster%))) < 5      : ' On fixe une vitesse minimale en dessous
    vit_ast_x%(Aster%)=rnd(20) - 10 : vit_ast_y%(Aster%)=rnd(20) - 10 : ' de laquelle on n'accepte pas le tirage
  end_while                                                  : ' la vitesse peut être positive ou négative
  xA%(Aster%) = screen_x + 10 : yA%(Aster%) = screen_y + 10  : ' on fixe la position de départ de l'astéroid en bas à droite
  if vit_ast_x%(Aster%) > 0 then xA%(Aster%)=-10              : ' si la vitesse en x est positive, on change le point de départ à gauche
  if vit_ast_y%(Aster%) > 0 then yA%(Aster%)=-10              : ' si la vitesse en y est positive, on change le point de départ en haut
  sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)        : ' on positionne notre asteroide
END_SUB

rem ============================================================================
' astéroide
SUB asteroide(Aster%)
      if ((xA%(Aster%) < (0-10)) and (vit_ast_x%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((xA%(Aster%) > (screen_x + 10)) and (vit_ast_x%(Aster%) > 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) < (0-10))  and (vit_ast_y%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) > (screen_y + 10)) and (vit_ast_y%(Aster%) > 0)) then new_asteroide(Aster%)
      xA%(Aster%)=xA%(Aster%)+vit_ast_x%(Aster%) : yA%(Aster%)=yA%(Aster%)+vit_ast_y%(Aster%)
      sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)
      Test_collision_vaisseau(Aster%)
scene2d_off
END_SUB

rem ============================================================================
' libère un tir
SUB Annule_tir(N_t%)
 tir_d(N_t%) = tir_d(Cpt_tirs%) :  tir_x(N_t%) = tir_x(Cpt_tirs%) : tir_y(N_t%) = tir_y(Cpt_tirs%)
 SPRITE_POSITION 39 + N_t%,tir_x(N_t%), tir_y(N_t%) : SPRITE_HIDE 39 + Cpt_tirs%
 tir%(Cpt_tirs%) = 0 : Cpt_tirs% = Cpt_tirs% - 1
END_SUB

rem ============================================================================
' Tirer une balle dans l'une des 8 directions possibles du sprite
SUB tir(N_t%)
dim_local pxbe%,pybe%,pxve%,pyve%
  tir_x(N_t%) = tir_x(N_t%) + cos(tir_d(N_t%))* vit_mis%  : tir_y(N_t%) = tir_y(N_t%) - sin(tir_d(N_t%)) * vit_mis%
  if (cos(tir_d(N_t%)) > 0 and tir_x(N_t%) > screen_x) or (cos(tir_d(N_t%)) < 0 and tir_x(N_t%) < 0 ) or (sin(tir_d(N_t%)) < 0 and tir_y(N_t%) > screen_y) or (sin(tir_d(N_t%)) > 0 and tir_y(N_t%) < 0 )
    Annule_tir(N_t%)
  end_if
  sprite_position 39+N_t%,tir_x(N_t%), tir_y(N_t%) : ' Mouvement de la balle du tir
  FOR n% = 1 TO Nb_Asteroides%
      Collision_AABB(tir_x(N_t%),tir_y(N_t%),16,16,xA%(n%),yA%(n%), 22,24)
      if tir$="OK" then tir_ok(N_t%,n%)
  NEXT n%
  ' verif si collision avec vaisseau ennemi
if SpriteVE%<>0
    pxbe%=sprite_x_position(39+N_t%) : pybe%=sprite_y_position(39+N_t%)
    pxve%=sprite_x_position(SpriteVE%) : pyve%=sprite_y_position(SpriteVE%)
    Collision_AABB(pxbe%,pybe%,10,10,pxve%,pyve%,40,40)
    if tir$="OK"
      Annule_tir(N_t%)
      off_key_down
      play 198 : ' explosion vaisseau
    '  animation de la destruction du vaisseau ami par un ennemi
      SPRITE_HIDE SpriteVE% : tirE%=0  : SPRITE_HIDE 69
      scene2d_interval 250 : scene2d_on
      sprite_position 12,pxbe%-60,pybe%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
      pause 400 : SPRITE_HIDE 12 : SpriteVE%=0
      on_key_down touche
      scene2d_off :score%=score%+1 : affiscore()
    end_if
end_if
END_SUB

rem ============================================================================
SUB tir_ok(N_t%,N_a%)
    ' animation de la destruction de la cible
play 199 :' explosion_aster
    Annule_tir(N_t%)
    off_key_down
    sprite_position 11,(xA%(N_a%) - 40),(yA%(N_a%) - 40) : SPRITE_SHOW 11 : sprite_animated_frames 11,8,14
    pause 200 : SPRITE_HIDE 29 + N_a% : SPRITE_HIDE 11
    on_key_down touche
    score%=score%+2 : affiscore()
    new_asteroide(N_a%):  SPRITE_SHOW 29 + N_a%
END_SUB

rem ============================================================================
SUB Collision_AABB(r1_x%,r1_y%,r1_width,r1_height,r2_x%,r2_y%, r2_width,r2_height)
  Tir$="OK"
  IF ((r2_x% >= (r1_x% + r1_width)) OR ((r2_x% + r2_width) <= r1_x%) OR (r2_y% >= (r1_y% + r1_height)) OR ((r2_y% + r2_height) <= r1_y%)) THEN Tir$=""
END_SUB

rem ============================================================================
' d est la direction (le cap) que prendra le sprite
SUB move(nsp%)
    select nsp%
        case 1 : x% = x% - vit_vai% : y% = y% + vit_vai%  : d = 5*pi/4
        case 2 : y% = y% + vit_vai%                  : d = 3*pi/2
        case 3 : x% = x% + vit_vai% : y% = y% + vit_vai%  : d = 7*pi/4
        case 4 : x% = x% - vit_vai%                  : d = pi
        case 5 : x% = x% + vit_vai%                  : d = 0
        case 6 : x% = x% - vit_vai% : y% = y% - vit_vai%  : d = 3*pi/4
        case 7 : y% = y% - vit_vai%                  : d = pi/2
        case 8 : x% = x% + vit_vai% : y% = y% - vit_vai%  : d = pi/4
    end_select
'    caption str$(nsp%) + ":" + str$(SpriteV%)
    if nsp% <> SpriteV%
        sprite_hide SpriteV% : SpriteV% = nsp%  : sprite_position nsp%,x%,y% :sprite_show nsp%
    else
        sprite_position nsp%,x%,y%
    end_if
' Le mode ENROULE : si le sprite sort de la zone , il réapparait de l'autre côté
    if x% < 0  then x% = screen_x
    if x% > screen_x then x% = 0
    if y% < 0 then y% = screen_y
    if y% > screen_y then y% = 0

END_SUB
rem ============================================================================
SUB ennemi()
    SPRITE_SHOW SpriteVE%
    ' bouger le vaisseau
    if SpriteVE%=63 then xE%=xE%+vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=62 then yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=61 then xE%=xE%-vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=64 then xE%=xE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=66 then xE%=xE%-vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=67 then yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=68 then xE%=xE%+vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=65 then xE%=xE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    sprite_position SpriteVE%,xE%,yE%
'  Pas de collision donc
'  si en dehors du cadre SpriteVE%=0
    if xE%<(0-64) or xE%>(screen_x+64) or yE%<(0-64) or yE%>(screen_y+64)
      SpriteVE%=0 : tirE%=0 : SPRITE_HIDE 69
    else
    ' faire un tir ou pas
      if xE%>128 and xE%<(screen_x-128) and yE%>128 and yE%<(screen_y-128)
        if tirE%=0
            init_tir_ennemi() : tir_ennemi()
        else
            tir_ennemi()
        end_if
      end_if
    end_if
END_SUB

rem ============================================================================
SUB tir_ennemi()
dim_local pxbe%,pybe%
    pxbe%=sprite_x_position(69) : pybe%=sprite_y_position(69)
    ' vérifier si la balle est sortie
    if SpriteVE%=63 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBD)
    if SpriteVE%=62 then pybe%=pybe%+(vit_E%*2)                          :' (VEB)
    if SpriteVE%=61 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBG)
    if SpriteVE%=64 then pxbe%=pxbe%-(vit_E%*2)                          :' (VEG)
    if SpriteVE%=66 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHG)
    if SpriteVE%=67 then pybe%=pybe%-(vit_E%*2)                          :' (VEH)
    if SpriteVE%=68 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHD)
    if SpriteVE%=65 then pxbe%=pxbe%+(vit_E%*2)                          :' (VED)
    sprite_position 69,pxbe%,pybe%
    Collision_AABB(pxbe%,pybe%,32,32,x%,y%,32,32)
    if tir$="OK"
      tirE%=0 : vaisseau_detruit_par_E(69)
      message "Vos ennemis sont d'excellent tireur ! c'est terminé pour vous"+chr$(13)+chr$(13)+"Votre score: "+str$(score%)
      gosub fin
    end_if
END_SUB

rem ============================================================================
SUB init_tir_ennemi()
dim_local pxbe%,pybe%
    tirE%=tirE%+1
    ' position de départ
    if SpriteVE%=63 then pxbe%=xE%+45 : pybe%=yE%+45
    if SpriteVE%=62 then pxbe%=xE%+25 : pybe%=yE%+55
    if SpriteVE%=61 then pxbe%=xE%+2  : pybe%=yE%+48
    if SpriteVE%=64 then pxbe%=xE%-7  : pybe%=yE%+24
    if SpriteVE%=66 then pxbe%=xE%    : pybe%=yE%
    if SpriteVE%=67 then pxbe%=xE%+24 : pybe%=yE%-12
    if SpriteVE%=68 then pxbe%=xE%+47 : pybe%=yE%
    if SpriteVE%=65 then pxbe%=xE%+56 : pybe%=yE%+24
    SPRITE_SHOW 69 : sprite_position 69,pxbe%,pybe%
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau_E(nspE%)
    ' test collision entre vaisseaux
  Collision_AABB(x%,y%,28,28,xE%,yE%,28,28)
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit_par_E(nspE%)
    message "HA ! HA ! Il y a des kamikazes, chez vos ennemis !"+chr$(13)+chr$(13)+"Votre score: "+str$(score%): ' fin de partie
    gosub fin
  end_if
END_SUB
rem ============================================================================
SUB vaisseau_detruit_par_E(NE%)
dim_local px%,py%
    px%=sprite_x_position(SpriteV%) : py%=sprite_y_position(SpriteV%)
    ' animation de la destruction du vaisseau ami par un ennemi
      play 198 : ' explosion vaisseau
    off_key_down : tirE%=0 : SPRITE_HIDE 69
    SPRITE_HIDE SpriteV% : SPRITE_HIDE NE% :' les deux sont détruit
    scene2d_interval 250 : scene2d_on
    sprite_position 12,px%-60,py%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
    scene2d_off
END_SUB

rem ============================================================================
' nouveau vaisseau ennemi
SUB new_ennemi()
dim_local pde%
    ' choix aléatoire du vaisseau
    repeat : pde%=rnd(9): until pde%>0 and pde%<9
    if pde%<1 or pde%>8 then message "Echec choix aléatoire pde%="+str$(pde%) : terminate
    ' positionner (aléatoirement) le vaisseau en dehors de l'écran suivant le choix
    if pde%=1 then SpriteVE%=63 : xE%=-64 : yE%=-64                      :' Coin HG (VEBD)
    if pde%=2 then SpriteVE%=62 : xE%=rnd(screen_x) : yE%=-64            :' Haut    (VEB)
    if pde%=3 then SpriteVE%=61 : xE%=screen_x+64 : yE%=-64              :' Coin HD (VEBG)
    if pde%=4 then SpriteVE%=64 : xE%=screen_x+64 : yE%=rnd(screen_y)    :' Droite  (VEG)
    if pde%=5 then SpriteVE%=66 : xE%=screen_x+64 : yE%=screen_y+64      :' Coin BD (VEHG)
    if pde%=6 then SpriteVE%=67 : xE%=rnd(screen_x) : yE%=screen_y+64    :' Bas (VEH)
    if pde%=7 then SpriteVE%=68 : xE%=-64 : yE%=screen_y+64              :' Coin BG (VEHD)
    if pde%=8 then SpriteVE%=65 : xE%=-64 : yE%=rnd(screen_y)            :' Gauche (VED)
    sprite_position SpriteVE%,xE%,yE%
    ' déterminer une vitesse aléatoire
    repeat : vit_E%=rnd(vit_E_max%) : until vit_E%>vit_E_min%
END_SUB

rem ============================================================================

fin:
  terminate
return

A+
Revenir en haut Aller en bas
Jicehel

Jicehel


Nombre de messages : 5947
Age : 51
Localisation : 77500
Date d'inscription : 18/04/2011

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 19:35

Jean-Claude, j'ai un peu modifié ton code pour l'introduction et pour le chargement des sprites (pour ne pas les voir s'afficher en haut à gauche, je savais bien que Jack avait fait une instruction. C'est en clair dans la doc Smile c'est SPRITE_CREATE_HIDE) J'ai aussi supprimé tout les scene_2d_on et scene_2d_off car je n'ai pas compris à quoi il te servaient. J'ai laissé les interval car ça peut servir. J'ai modifié un peu la boucle principal pour récupérer un peu de vitesse car par fois c'est un peu trop lent sinon à mon gout.
Ca donne ça (par contre je n'ai vu que maintenant que tu avais fait des réglages, ils ne sont donc pas inclus dans le code)
Code:
' AsterV3.bas (Jean Claude, Jicehel, Papydall) (JUIN 2015)

rem ============================================================================

dim n%,i%,at%
dim pi : pi = acos(-1)              : ' mémorise la valeur pi
dim x%,y%,vit_vai%                  : ' position et vitesse du vaisseau
dim d  : d = pi/2                  : ' direction (c'est le cap) de départ du vaisseau (vers le haut)
dim Nb_tirs%,Cpt_tirs% : Nb_tirs%=5 : ' Nombre de tirs autorisés et compteur de tirs actifs
dim tir$,tir%(Nb_tirs%), tir_x(Nb_tirs%),tir_y(Nb_tirs%),tir_d(Nb_tirs%),vit_mis% : ' Resultat du tir, Tir actif ou non, coord en x et en y du tir et mémoristion de la direction et vitesse
dim Nb_Asteroides%,Cpt_asteroides% : Nb_Asteroides% = 3    : ' Nombre d'Asteroides actifs
dim xA%(Nb_Asteroides%),yA%(Nb_Asteroides%)                : ' Position des asteroides
dim vit_ast_x%(Nb_Asteroides%), vit_ast_y%(Nb_Asteroides%)  : ' Vitesse des asteroides
dim SpriteV%        :' Pour savoir quelle image du vaisseau ami est en service (car d change dans la sub move)
dim score%          :' Pour le score
dim cpt_t_asteroide : ' ralentisseur pour les mouvements de l'asteroid
dim niveau%        :' Niveau du jeu
dim xE%,yE%            :' Position de l'ennemi
dim vit_E%,vit_E_max%,vit_E_min%  :' Vitesse de l'ennemi et son maximum et minimum
dim tirE%              :' Tir ennemi
dim SpriteVE% :' Pour savoir quelle image du vaisseau ennmi est en service

' Déclaration des étiquettes
label touche,boucle_principale,fin,Attente,Repart,Musique
on_error_goto fin

' fichiers audios
sound 197 : file_load 197,"audio/dreamland.wav": ' explosion du vaisseau
sound 198 : file_load 198,"audio/explosion_vaisseau.wav": ' explosion du vaisseau
sound 199 : file_load 199,"audio/explosion_aster.wav"  : ' explosion des asteroides

SPRITE_CREATE_HIDE

' création des vaisseaux amis
SPRITE 1 : SPRITE_FILE_LOAD 1,"image/VBG.bmp"
SPRITE 2 : SPRITE_FILE_LOAD 2,"image/VB.bmp"
SPRITE 3 : SPRITE_FILE_LOAD 3,"image/VBD.bmp"
SPRITE 4 : SPRITE_FILE_LOAD 4,"image/VG.bmp"
SPRITE 5 : SPRITE_FILE_LOAD 5,"image/VD.bmp"
SPRITE 6 : SPRITE_FILE_LOAD 6,"image/VHG.bmp"
SPRITE 7 : SPRITE_FILE_LOAD 7,"image/VH.bmp"
SPRITE 8 : SPRITE_FILE_LOAD 8,"image/VHD.bmp"

SPRITE_ANIMATED 11 : SPRITE_ANIMATED_FILE_LOAD 11,5,5,"image/meteore.bmp"  : ' explosion astéroide
SPRITE_ANIMATED 12 : SPRITE_ANIMATED_FILE_LOAD 12,5,5,"image/meteore2.bmp" : ' explosion vaisseau

i%=19
FOR n% = 0 TO 9
i%=i%+1
SPRITE i% : SPRITE_FILE_LOAD i%,"image/"+str$(n%)+".bmp" : ' chiffres pour le score
NEXT n%

FOR n% = 1 TO Nb_Asteroides%
  SPRITE_ANIMATED 29 + n% : ' Créé un sprite pour un astéroide
  SPRITE_ANIMATED_FILE_LOAD 29 + n% ,1,8,"image/rock8.bmp"    : ' Charge le sprite animé correspondant à l'astéroide
  new_asteroide(n%) : SPRITE_SHOW 29 + n%  : ' Créé les astéroides du début
NEXT n%
Cpt_asteroides% = Nb_Asteroides%

FOR n% = 1 TO Nb_tirs%
  SPRITE 39 + n% : SPRITE_FILE_LOAD 39 + n%,"image/balle.bmp"
  tir%(n%) = 0 : ' Au début pas de tir actif
NEXT n%

' Sprites pour le générique.
SPRITE 51 : SPRITE_FILE_LOAD 51,"image/gen3.bmp" : SPRITE_POSITION 51,(screen_x/2)-350,screen_y+200
SPRITE 50 : SPRITE_FILE_LOAD 50,"image/gen1.bmp" : SPRITE_POSITION 50,(screen_x/2)-350,screen_y-40

' création des vaisseaux ennemis
SPRITE 61 : SPRITE_FILE_LOAD 61,"image/VEBG.bmp"
SPRITE 62 : SPRITE_FILE_LOAD 62,"image/VEB.bmp"
SPRITE 63 : SPRITE_FILE_LOAD 63,"image/VEBD.bmp"
SPRITE 64 : SPRITE_FILE_LOAD 64,"image/VEG.bmp"
SPRITE 65 : SPRITE_FILE_LOAD 65,"image/VED.bmp"
SPRITE 66 : SPRITE_FILE_LOAD 66,"image/VEHG.bmp"
SPRITE 67 : SPRITE_FILE_LOAD 67,"image/VEH.bmp"
SPRITE 68 : SPRITE_FILE_LOAD 68,"image/VEHD.bmp"
' boulet ennemi
SPRITE 69 : SPRITE_FILE_LOAD 69,"image/balleE.bmp"

' scene2D
BACKGND_LOAD "image/espace.bmp"

niveau%=1 : niveau() : cpt_t_asteroide = 0 : Cpt_tirs% = 0

play 197 : SPRITE_SHOW 51 : SPRITE_SHOW 50 : generique()

' init
x%=(screen_x/2)+32 : y%=700 : sprite_position 7,x%,y% : SpriteV% = 7 : SPRITE_SHOW 7
scene2d_interval 80
affiscore()
on_key_down touche              : ' Active la gestion de l'appuie des touches

timer 2 : timer_interval 2,20 : on_timer 2,boucle_principale  : ' Activation du timer qui activera les tours de jeu
timer 3 : timer_interval 3,100000 : on_timer 3,Musique  : ' Musique d'ambiance (recommance toutes les minutes)


END

rem ================================ Musique ===================================
Musique:
  play 197
return

rem ================================= PAUSE ====================================
Attente:
timer_off 2 : timer_off 3
on_key_down Repart
return

Repart:
timer_on 3 : timer_on 2 : on_key_down touche
return

rem =============================== Générique ==================================
SUB generique()
DIM_LOCAL X1,Y1,X2,Y2,Y3,Y4
  scene2d_interval 20
  X1=0 : Y1=0 : X2=2184 : Y2=1167 : view X1,Y1,X2,Y2
  Y2=600 : Y3=70 : Y4=screen_y+100
  SPRITE_POSITION 50,(screen_x/2)-350,Y3
' traveling arrière
  repeat
      Y1=Y1+1 : Y2=Y2+1 : view X1,Y1,X2,Y2
      Y4=Y4-2 : SPRITE_POSITION 51,(screen_x/2)-350,Y4
  until y2>1000 or scancode<>0
  pause 2000
  X1=0 : Y1=0 : X2=screen_x : Y2=screen_y : view X1,Y1,X2,Y2
  SPRITE_HIDE 50 : SPRITE_HIDE 51
END_SUB

rem ========================== Réglage des Niveaux =============================
SUB niveau()
    if niveau%=1 then vit_vai%=6 : vit_mis%=14
    if niveau%=2 then vit_vai%=7 : vit_mis%=16
    if niveau%=3 then vit_vai%=8 : vit_mis%=18  : vit_E_max%=8 : vit_E_min%=1
    if niveau%=4 then vit_vai%=9 : vit_mis%=20  : vit_E_max%=9 : vit_E_min%=2
    if niveau%=5 then vit_vai%=10 : vit_mis%=21 : vit_E_max%=10 : vit_E_min%=3
    if niveau%=6 then vit_vai%=11 : vit_mis%=21 : vit_E_max%=12 : vit_E_min%=4
    if niveau%=7 then vit_vai%=12 : vit_mis%=22 : vit_E_max%=16 : vit_E_min%=6
    if niveau%=8 then vit_vai%=13 : vit_mis%=22 : vit_E_max%=18 : vit_E_min%=8
    if niveau%=9 then vit_vai%=14 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=9
    if niveau%=10 then vit_vai%=15 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=10

' réglages
' vit_vai% = 8 :' + => plus rapide
' vit_mis%=20  :' + => plus rapide
' vit_E_min%=2 : ' vitesse ennemi: minimum 2
' vit_E_max%=12 :' vitesse ennemi: + => plus rapide (mais aléatoire >vit_E_min%)

END_SUB

rem ============== Score et réglage des paliers pour les viveaux ===============
SUB affiscore()
    ' affichage du score et progression du niveau par paliers
    if score%=1 then niveau%=niveau%+1  :' 2
    if score%=3 then niveau%=niveau%+1  :' 3
    if score%=7 then niveau%=niveau%+1  :' 4
    if score%=12 then niveau%=niveau%+1 :' 5
    if score%=17 then niveau%=niveau%+1 :' 6
    if score%=20 then niveau%=niveau%+1 :' 7
    if score%=25 then niveau%=niveau%+1 :' 8
    if score%=30 then niveau%=niveau%+1 :' 9
    if score%=35 then niveau%=niveau%+1 :' 10
    caption "CHASSEUR D'ASTEROIDES  -  Score: "+str$(score%)+"  -  Niveau: "+str$(niveau%)
    niveau()
END_SUB

rem ================== Attribution des touches du clavier ======================
touche:
' Touches du pavé numérique
  if KEY_DOWN_CODE = 97 then move(1)                        : ' 1 End
  if KEY_DOWN_CODE = 40 or KEY_DOWN_CODE = 98 then move(2)  : ' 2 Bas
  if KEY_DOWN_CODE = 99 then move(3)                        : ' 3 PgDn
  if KEY_DOWN_CODE = 37 or KEY_DOWN_CODE = 100 then move(4) : ' 4 gauche
  if KEY_DOWN_CODE = 39 or KEY_DOWN_CODE = 102 then move(5) : ' 5 droite
  if KEY_DOWN_CODE = 103 then move(6)                      : ' 6 Home
  if KEY_DOWN_CODE = 38 or KEY_DOWN_CODE = 104 then move(7) : ' 7 haut
  if KEY_DOWN_CODE = 105 then move(8)                      : ' 8 PgUp
  if KEY_DOWN_CODE = 27 then gosub fin                      : ' Echap
  if KEY_DOWN_CODE = 80 then gosub Attente : return
  if KEY_DOWN_CODE = 83 then timer_off 3
  if KEY_DOWN_CODE = 77 then timer_on 3 : play 197
  if KEY_DOWN_CODE = 32 AND Cpt_tirs% < Nb_tirs%
      Cpt_tirs% = Cpt_tirs% + 1
      tir%(Cpt_tirs%) = 1 :  tir_d(Cpt_tirs%) = d  : ' On mémorise qu'un tir est actif et la direction de ce tir
      ' On ajuste la position initale du tir en fonction de la direction du vaisseau
      if d = 5*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 33
      if d = 3*pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y% + 44
      if d = 7*pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 33
      if d = pi then tir_x(Cpt_tirs%) = x%      : tir_y(Cpt_tirs%) = y% + 22
      if d = 0 then tir_x(Cpt_tirs%) = x% + 44 : tir_y(Cpt_tirs%) = y% + 22
      if d = 3*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 11
      if d = pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y%
      if d = pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 11
      sprite_position 39+Cpt_tirs%,tir_x(Cpt_tirs%), tir_y(Cpt_tirs%) : SPRITE_SHOW 39+Cpt_tirs%
  end_if    : ' Fin du traitement d'un appuie sur espace
on_key_down touche
return

rem ==================== Boucle_principale (tour) ==============================
boucle_principale:
timer_off 2: off_key_down
  if niveau%>2
    ' on gére le vaisseau ennemi pour ce tour
    if SpriteVE%=0 then new_ennemi()
    ennemi()
  end_if
  if Cpt_tirs% > 0
    for i% = 1 to Cpt_tirs%
      if tir%(i%) = 1 then tir(i%) :  ' Si un tir est actif, on gère son tour
        cpt_t_asteroide = cpt_t_asteroide + 1
        if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(2)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 3 then asteroide(3)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
    next i%
  else
    cpt_t_asteroide = cpt_t_asteroide + 1
    if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
    if cpt_t_asteroide = 2 then asteroide(2)  : ' On gère notre asteroid pour ce tour
    if cpt_t_asteroide = 3 then asteroide(3)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
  end_if
  FOR i% = 1 TO Nb_Asteroides%
      Test_collision_vaisseau(i%)
  next i%
timer_on 2 : on_key_down touche
return

rem ============================================================================
SUB vaisseau_detruit(Aster%)
    ' animation de la destruction de la cible
    off_key_down
    sprite_position 29 + Aster%,xA%(Aster%)+20,yA%(Aster%)+20 : SPRITE_HIDE SpriteV%
    scene2d_interval 250
    sprite_position 12,(xA%(Aster%) - 60),(yA%(Aster%) - 60) : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau(Aster%)
  Collision_AABB(xA%(Aster%),yA%(Aster%),22,24,x%,y%,32,32) :' vérifier si le vaisseau ami n'est pas en collision avec l'astéroide
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit(Aster%)
    message "Votre vaisseau est détruit!"+chr$(13)+chr$(13)+"Votre score: "+str$(score%) :' fin de partie
    gosub fin
  end_if
' test collision VE avec Aster
  if SpriteVE%<>0
    Collision_AABB(xA%(Aster%),yA%(Aster%),16,16,xE%,yE%,28,28) :' vérifier si le vaisseau ennemi n'est pas en collision avec l'astéroide
    if tir$="OK"
      play 198 : ' explosion vaisseau
    ' animation de la destruction du vaisseau ennemi par aster
    off_key_down
    SPRITE_HIDE SpriteVE%
    scene2d_interval 250
    sprite_position 12,xE%-60,yE%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 400 : SPRITE_HIDE 12
    SpriteVE%=0 : tirE%=0
    end_if
  end_if
END_SUB

rem ============================================================================
' New_astéroide
SUB new_asteroide(Aster%)
scene2d_interval 500
  vit_ast_x%(Aster%)= 0 : vit_ast_y%(Aster%)= 0  : ' On initialise le compteur pour un lancé aléatoire
  while (abs(vit_ast_x%(Aster%)) + abs(vit_ast_y%(Aster%))) < 5      : ' On fixe une vitesse minimale en dessous
    vit_ast_x%(Aster%)=rnd(20) - 10 : vit_ast_y%(Aster%)=rnd(20) - 10 : ' de laquelle on n'accepte pas le tirage
  end_while                                                  : ' la vitesse peut être positive ou négative
  xA%(Aster%) = screen_x + 10 : yA%(Aster%) = screen_y + 10  : ' on fixe la position de départ de l'astéroid en bas à droite
  if vit_ast_x%(Aster%) > 0 then xA%(Aster%)=-10              : ' si la vitesse en x est positive, on change le point de départ à gauche
  if vit_ast_y%(Aster%) > 0 then yA%(Aster%)=-10              : ' si la vitesse en y est positive, on change le point de départ en haut
  sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)        : ' on positionne notre asteroide
END_SUB

rem ============================================================================
' astéroide
SUB asteroide(Aster%)
      if ((xA%(Aster%) < (0-10)) and (vit_ast_x%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((xA%(Aster%) > (screen_x + 10)) and (vit_ast_x%(Aster%) > 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) < (0-10))  and (vit_ast_y%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) > (screen_y + 10)) and (vit_ast_y%(Aster%) > 0)) then new_asteroide(Aster%)
      xA%(Aster%)=xA%(Aster%)+vit_ast_x%(Aster%) : yA%(Aster%)=yA%(Aster%)+vit_ast_y%(Aster%)
      sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)
      Test_collision_vaisseau(Aster%)
END_SUB

rem ============================================================================
' libère un tir
SUB Annule_tir(N_t%)
 tir_d(N_t%) = tir_d(Cpt_tirs%) :  tir_x(N_t%) = tir_x(Cpt_tirs%) : tir_y(N_t%) = tir_y(Cpt_tirs%)
 SPRITE_POSITION 39 + N_t%,tir_x(N_t%), tir_y(N_t%) : SPRITE_HIDE 39 + Cpt_tirs%
 tir%(Cpt_tirs%) = 0 : Cpt_tirs% = Cpt_tirs% - 1
END_SUB

rem ============================================================================
' Tirer une balle dans l'une des 8 directions possibles du sprite
SUB tir(N_t%)
dim_local pxbe%,pybe%,pxve%,pyve%
  tir_x(N_t%) = tir_x(N_t%) + cos(tir_d(N_t%))* vit_mis%  : tir_y(N_t%) = tir_y(N_t%) - sin(tir_d(N_t%)) * vit_mis%
  if (cos(tir_d(N_t%)) > 0 and tir_x(N_t%) > screen_x) or (cos(tir_d(N_t%)) < 0 and tir_x(N_t%) < 0 ) or (sin(tir_d(N_t%)) < 0 and tir_y(N_t%) > screen_y) or (sin(tir_d(N_t%)) > 0 and tir_y(N_t%) < 0 )
    Annule_tir(N_t%)
  end_if
  sprite_position 39+N_t%,tir_x(N_t%), tir_y(N_t%) : ' Mouvement de la balle du tir
  FOR n% = 1 TO Nb_Asteroides%
      Collision_AABB(tir_x(N_t%),tir_y(N_t%),16,16,xA%(n%),yA%(n%), 22,24)
      if tir$="OK" then tir_ok(N_t%,n%)
  NEXT n%
  ' verif si collision avec vaisseau ennemi
if SpriteVE%<>0
    pxbe%=sprite_x_position(39+N_t%) : pybe%=sprite_y_position(39+N_t%)
    pxve%=sprite_x_position(SpriteVE%) : pyve%=sprite_y_position(SpriteVE%)
    Collision_AABB(pxbe%,pybe%,10,10,pxve%,pyve%,40,40)
    if tir$="OK"
      Annule_tir(N_t%)
      off_key_down
      play 198 : ' explosion vaisseau
    '  animation de la destruction du vaisseau ami par un ennemi
      SPRITE_HIDE SpriteVE% : tirE%=0  : SPRITE_HIDE 69
      scene2d_interval 250
      sprite_position 12,pxbe%-60,pybe%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
      pause 400 : SPRITE_HIDE 12 : SpriteVE%=0
      on_key_down touche
      score%=score%+1 : affiscore()
    end_if
end_if
END_SUB

rem ============================================================================
SUB tir_ok(N_t%,N_a%)
    ' animation de la destruction de la cible
play 199 :' explosion_aster
    Annule_tir(N_t%)
    off_key_down
    sprite_position 11,(xA%(N_a%) - 40),(yA%(N_a%) - 40) : SPRITE_SHOW 11 : sprite_animated_frames 11,8,14
    pause 200 : SPRITE_HIDE 29 + N_a% : SPRITE_HIDE 11
    on_key_down touche
    score%=score%+2 : affiscore()
    new_asteroide(N_a%):  SPRITE_SHOW 29 + N_a%
END_SUB

rem ============================================================================
SUB Collision_AABB(r1_x%,r1_y%,r1_width,r1_height,r2_x%,r2_y%, r2_width,r2_height)
  Tir$="OK"
  IF ((r2_x% >= (r1_x% + r1_width)) OR ((r2_x% + r2_width) <= r1_x%) OR (r2_y% >= (r1_y% + r1_height)) OR ((r2_y% + r2_height) <= r1_y%)) THEN Tir$=""
END_SUB

rem ============================================================================
' d est la direction (le cap) que prendra le sprite
SUB move(nsp%)
    select nsp%
        case 1 : x% = x% - vit_vai% : y% = y% + vit_vai%  : d = 5*pi/4
        case 2 : y% = y% + vit_vai%                  : d = 3*pi/2
        case 3 : x% = x% + vit_vai% : y% = y% + vit_vai%  : d = 7*pi/4
        case 4 : x% = x% - vit_vai%                  : d = pi
        case 5 : x% = x% + vit_vai%                  : d = 0
        case 6 : x% = x% - vit_vai% : y% = y% - vit_vai%  : d = 3*pi/4
        case 7 : y% = y% - vit_vai%                  : d = pi/2
        case 8 : x% = x% + vit_vai% : y% = y% - vit_vai%  : d = pi/4
    end_select
'    caption str$(nsp%) + ":" + str$(SpriteV%)
    if nsp% <> SpriteV%
        sprite_hide SpriteV% : SpriteV% = nsp%  : sprite_position nsp%,x%,y% :sprite_show nsp%
    else
        sprite_position nsp%,x%,y%
    end_if
' Le mode ENROULE : si le sprite sort de la zone , il réapparait de l'autre côté
    if x% < 0  then x% = screen_x
    if x% > screen_x then x% = 0
    if y% < 0 then y% = screen_y
    if y% > screen_y then y% = 0

END_SUB
rem ============================================================================
SUB ennemi()
    SPRITE_SHOW SpriteVE%
    ' bouger le vaisseau
    if SpriteVE%=63 then xE%=xE%+vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=62 then yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=61 then xE%=xE%-vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=64 then xE%=xE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=66 then xE%=xE%-vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=67 then yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=68 then xE%=xE%+vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=65 then xE%=xE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    sprite_position SpriteVE%,xE%,yE%
'  Pas de collision donc
'  si en dehors du cadre SpriteVE%=0
    if xE%<(0-64) or xE%>(screen_x+64) or yE%<(0-64) or yE%>(screen_y+64)
      SpriteVE%=0 : tirE%=0 : SPRITE_HIDE 69
    else
    ' faire un tir ou pas
      if xE%>128 and xE%<(screen_x-128) and yE%>128 and yE%<(screen_y-128)
        if tirE%=0
            init_tir_ennemi() : tir_ennemi()
        else
            tir_ennemi()
        end_if
      end_if
    end_if
END_SUB

rem ============================================================================
SUB tir_ennemi()
dim_local pxbe%,pybe%
    pxbe%=sprite_x_position(69) : pybe%=sprite_y_position(69)
    ' vérifier si la balle est sortie
    if SpriteVE%=63 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBD)
    if SpriteVE%=62 then pybe%=pybe%+(vit_E%*2)                          :' (VEB)
    if SpriteVE%=61 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBG)
    if SpriteVE%=64 then pxbe%=pxbe%-(vit_E%*2)                          :' (VEG)
    if SpriteVE%=66 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHG)
    if SpriteVE%=67 then pybe%=pybe%-(vit_E%*2)                          :' (VEH)
    if SpriteVE%=68 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHD)
    if SpriteVE%=65 then pxbe%=pxbe%+(vit_E%*2)                          :' (VED)
    sprite_position 69,pxbe%,pybe%
    Collision_AABB(pxbe%,pybe%,32,32,x%,y%,32,32)
    if tir$="OK"
      play 198 : ' explosion vaisseau
      tirE%=0 : vaisseau_detruit_par_E(69)
      message "Vos ennemis sont d'excellent tireur ! c'est terminé pour vous"+chr$(13)+chr$(13)+"Votre score: "+str$(score%)
      gosub fin
    end_if
END_SUB

rem ============================================================================
SUB init_tir_ennemi()
dim_local pxbe%,pybe%
    tirE%=tirE%+1
    ' position de départ
    if SpriteVE%=63 then pxbe%=xE%+45 : pybe%=yE%+45
    if SpriteVE%=62 then pxbe%=xE%+25 : pybe%=yE%+55
    if SpriteVE%=61 then pxbe%=xE%+2  : pybe%=yE%+48
    if SpriteVE%=64 then pxbe%=xE%-7  : pybe%=yE%+24
    if SpriteVE%=66 then pxbe%=xE%    : pybe%=yE%
    if SpriteVE%=67 then pxbe%=xE%+24 : pybe%=yE%-12
    if SpriteVE%=68 then pxbe%=xE%+47 : pybe%=yE%
    if SpriteVE%=65 then pxbe%=xE%+56 : pybe%=yE%+24
    SPRITE_SHOW 69 : sprite_position 69,pxbe%,pybe%
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau_E(nspE%)
    ' test collision entre vaisseaux
  Collision_AABB(x%,y%,28,28,xE%,yE%,28,28)
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit_par_E(nspE%)
    message "HA ! HA ! Il y a des kamikazes, chez vos ennemis !"+chr$(13)+chr$(13)+"Votre score: "+str$(score%): ' fin de partie
    gosub fin
  end_if
END_SUB
rem ============================================================================
SUB vaisseau_detruit_par_E(NE%)
dim_local px%,py%
    px%=sprite_x_position(SpriteV%) : py%=sprite_y_position(SpriteV%)
    ' animation de la destruction du vaisseau ami par un ennemi
    off_key_down : tirE%=0 : SPRITE_HIDE 69
    SPRITE_HIDE SpriteV% : SPRITE_HIDE NE% :' les deux sont détruit
    2d_interval 250
    sprite_position 12,px%-60,py%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
END_SUB

rem ============================================================================
' nouveau vaisseau ennemi
SUB new_ennemi()
dim_local pde%
    ' choix aléatoire du vaisseau
    repeat : pde%=rnd(9): until pde%>0 and pde%<9
    if pde%<1 or pde%>8 then message "Echec choix aléatoire pde%="+str$(pde%) : terminate
    ' positionner (aléatoirement) le vaisseau en dehors de l'écran suivant le choix
    if pde%=1 then SpriteVE%=63 : xE%=-64 : yE%=-64                      :' Coin HG (VEBD)
    if pde%=2 then SpriteVE%=62 : xE%=rnd(screen_x) : yE%=-64            :' Haut    (VEB)
    if pde%=3 then SpriteVE%=61 : xE%=screen_x+64 : yE%=-64              :' Coin HD (VEBG)
    if pde%=4 then SpriteVE%=64 : xE%=screen_x+64 : yE%=rnd(screen_y)    :' Droite  (VEG)
    if pde%=5 then SpriteVE%=66 : xE%=screen_x+64 : yE%=screen_y+64      :' Coin BD (VEHG)
    if pde%=6 then SpriteVE%=67 : xE%=rnd(screen_x) : yE%=screen_y+64    :' Bas (VEH)
    if pde%=7 then SpriteVE%=68 : xE%=-64 : yE%=screen_y+64              :' Coin BG (VEHD)
    if pde%=8 then SpriteVE%=65 : xE%=-64 : yE%=rnd(screen_y)            :' Gauche (VED)
    sprite_position SpriteVE%,xE%,yE%
    ' déterminer une vitesse aléatoire
    repeat : vit_E%=rnd(vit_E_max%) : until vit_E%>vit_E_min%
END_SUB

rem ============================================================================

fin:
  terminate
return
Revenir en haut Aller en bas
Jean Claude

Jean Claude


Nombre de messages : 5950
Age : 69
Localisation : 83 Var
Date d'inscription : 07/05/2009

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 20:50

Pour le générique, j'ai retouché car il faut le voir en entier, d'autan qu'on peut le passer.
Ta modif de la sub Vaisseau_detruit_par_E() termine la partie sans afficher le score.
J'ai remis la mienne.

La jouabilité est meilleure, j'y ai intégré mes nouveaux paliers. J'adopte.

ça donne ça
Code:
' AsterV301.bas (Jean Claude, Jicehel, Papydall) (JUIN 2015)

rem ============================================================================

dim n%,i%,at%
dim pi : pi = acos(-1)              : ' mémorise la valeur pi
dim x%,y%,vit_vai%                  : ' position et vitesse du vaisseau
dim d  : d = pi/2                  : ' direction (c'est le cap) de départ du vaisseau (vers le haut)
dim Nb_tirs%,Cpt_tirs% : Nb_tirs%=5 : ' Nombre de tirs autorisés et compteur de tirs actifs
dim tir$,tir%(Nb_tirs%), tir_x(Nb_tirs%),tir_y(Nb_tirs%),tir_d(Nb_tirs%),vit_mis% : ' Resultat du tir, Tir actif ou non, coord en x et en y du tir et mémoristion de la direction et vitesse
dim Nb_Asteroides%,Cpt_asteroides% : Nb_Asteroides% = 3    : ' Nombre d'Asteroides actifs
dim xA%(Nb_Asteroides%),yA%(Nb_Asteroides%)                : ' Position des asteroides
dim vit_ast_x%(Nb_Asteroides%), vit_ast_y%(Nb_Asteroides%)  : ' Vitesse des asteroides
dim SpriteV%        :' Pour savoir quelle image du vaisseau ami est en service (car d change dans la sub move)
dim score%          :' Pour le score
dim cpt_t_asteroide : ' ralentisseur pour les mouvements de l'asteroid
dim niveau%        :' Niveau du jeu
dim xE%,yE%            :' Position de l'ennemi
dim vit_E%,vit_E_max%,vit_E_min%  :' Vitesse de l'ennemi et son maximum et minimum
dim tirE%              :' Tir ennemi
dim SpriteVE% :' Pour savoir quelle image du vaisseau ennmi est en service

' Déclaration des étiquettes
label touche,boucle_principale,fin,Attente,Repart,Musique
on_error_goto fin

' fichiers audios
sound 197 : file_load 197,"audio/dreamland.wav": ' explosion du vaisseau
sound 198 : file_load 198,"audio/explosion_vaisseau.wav": ' explosion du vaisseau
sound 199 : file_load 199,"audio/explosion_aster.wav"  : ' explosion des asteroides

SPRITE_CREATE_HIDE

' création des vaisseaux amis
SPRITE 1 : SPRITE_FILE_LOAD 1,"image/VBG.bmp"
SPRITE 2 : SPRITE_FILE_LOAD 2,"image/VB.bmp"
SPRITE 3 : SPRITE_FILE_LOAD 3,"image/VBD.bmp"
SPRITE 4 : SPRITE_FILE_LOAD 4,"image/VG.bmp"
SPRITE 5 : SPRITE_FILE_LOAD 5,"image/VD.bmp"
SPRITE 6 : SPRITE_FILE_LOAD 6,"image/VHG.bmp"
SPRITE 7 : SPRITE_FILE_LOAD 7,"image/VH.bmp"
SPRITE 8 : SPRITE_FILE_LOAD 8,"image/VHD.bmp"

SPRITE_ANIMATED 11 : SPRITE_ANIMATED_FILE_LOAD 11,5,5,"image/meteore.bmp"  : ' explosion astéroide
SPRITE_ANIMATED 12 : SPRITE_ANIMATED_FILE_LOAD 12,5,5,"image/meteore2.bmp" : ' explosion vaisseau

i%=19
FOR n% = 0 TO 9
i%=i%+1
SPRITE i% : SPRITE_FILE_LOAD i%,"image/"+str$(n%)+".bmp" : ' chiffres pour le score
NEXT n%

FOR n% = 1 TO Nb_Asteroides%
  SPRITE_ANIMATED 29 + n% : ' Créé un sprite pour un astéroide
  SPRITE_ANIMATED_FILE_LOAD 29 + n% ,1,8,"image/rock8.bmp"    : ' Charge le sprite animé correspondant à l'astéroide
  new_asteroide(n%) : SPRITE_SHOW 29 + n%  : ' Créé les astéroides du début
NEXT n%
Cpt_asteroides% = Nb_Asteroides%

FOR n% = 1 TO Nb_tirs%
  SPRITE 39 + n% : SPRITE_FILE_LOAD 39 + n%,"image/balle.bmp"
  tir%(n%) = 0 : ' Au début pas de tir actif
NEXT n%

' Sprites pour le générique.
SPRITE 51 : SPRITE_FILE_LOAD 51,"image/gen3.bmp" : SPRITE_POSITION 51,(screen_x/2)-350,screen_y+200
SPRITE 50 : SPRITE_FILE_LOAD 50,"image/gen1.bmp" : SPRITE_POSITION 50,(screen_x/2)-350,screen_y-40

' création des vaisseaux ennemis
SPRITE 61 : SPRITE_FILE_LOAD 61,"image/VEBG.bmp"
SPRITE 62 : SPRITE_FILE_LOAD 62,"image/VEB.bmp"
SPRITE 63 : SPRITE_FILE_LOAD 63,"image/VEBD.bmp"
SPRITE 64 : SPRITE_FILE_LOAD 64,"image/VEG.bmp"
SPRITE 65 : SPRITE_FILE_LOAD 65,"image/VED.bmp"
SPRITE 66 : SPRITE_FILE_LOAD 66,"image/VEHG.bmp"
SPRITE 67 : SPRITE_FILE_LOAD 67,"image/VEH.bmp"
SPRITE 68 : SPRITE_FILE_LOAD 68,"image/VEHD.bmp"
' boulet ennemi
SPRITE 69 : SPRITE_FILE_LOAD 69,"image/balleE.bmp"

' scene2D
BACKGND_LOAD "image/espace.bmp"

niveau%=1 : niveau() : cpt_t_asteroide = 0 : Cpt_tirs% = 0

play 197 : SPRITE_SHOW 51 : SPRITE_SHOW 50 : generique()

' init
x%=(screen_x/2)+32 : y%=700 : sprite_position 7,x%,y% : SpriteV% = 7 : SPRITE_SHOW 7
scene2d_interval 80
affiscore()
on_key_down touche              : ' Active la gestion de l'appuie des touches

timer 2 : timer_interval 2,20 : on_timer 2,boucle_principale  : ' Activation du timer qui activera les tours de jeu
timer 3 : timer_interval 3,100000 : on_timer 3,Musique  : ' Musique d'ambiance (recommance toutes les minutes)


END

rem ================================ Musique ===================================
Musique:
  play 197
return

rem ================================= PAUSE ====================================
Attente:
timer_off 2 : timer_off 3
on_key_down Repart
return

Repart:
timer_on 3 : timer_on 2 : on_key_down touche
return

rem =============================== Générique ==================================
SUB generique()
DIM_LOCAL X1,Y1,X2,Y2,Y3,Y4
  scene2d_interval 20
  X1=0 : Y1=0 : X2=2184 : Y2=1167 : view X1,Y1,X2,Y2
  Y2=600 : Y3=70 : Y4=screen_y+100
  SPRITE_POSITION 50,(screen_x/2)-350,Y3
' traveling arrière
  repeat
      Y1=Y1+1 : Y2=Y2+1 : view X1,Y1,X2,Y2
      Y4=Y4-2 : SPRITE_POSITION 51,(screen_x/2)-350,Y4
  pause 100
  until y2>1000 or scancode<>0
  pause 2000
  X1=0 : Y1=0 : X2=screen_x : Y2=screen_y : view X1,Y1,X2,Y2
  SPRITE_HIDE 50 : SPRITE_HIDE 51
END_SUB

rem ========================== Réglage des Niveaux =============================
SUB niveau()
    if niveau%=1 then vit_vai%=7 : vit_mis%=14
    if niveau%=2 then vit_vai%=8 : vit_mis%=16
    if niveau%=3 then vit_vai%=9 : vit_mis%=18  : vit_E_max%=8 : vit_E_min%=1
    if niveau%=4 then vit_vai%=10 : vit_mis%=20  : vit_E_max%=9 : vit_E_min%=2
    if niveau%=5 then vit_vai%=11 : vit_mis%=21 : vit_E_max%=10 : vit_E_min%=3
    if niveau%=6 then vit_vai%=12 : vit_mis%=21 : vit_E_max%=12 : vit_E_min%=4
    if niveau%=7 then vit_vai%=13 : vit_mis%=22 : vit_E_max%=16 : vit_E_min%=6
    if niveau%=8 then vit_vai%=14 : vit_mis%=22 : vit_E_max%=18 : vit_E_min%=8
    if niveau%=9 then vit_vai%=15 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=9
    if niveau%=10 then vit_vai%=16 : vit_mis%=22 : vit_E_max%=20 : vit_E_min%=10

' réglages
' vit_vai% = 8 :' + => plus rapide
' vit_mis%=20  :' + => plus rapide
' vit_E_min%=2 : ' vitesse ennemi: minimum 2
' vit_E_max%=12 :' vitesse ennemi: + => plus rapide (mais aléatoire >vit_E_min%)

END_SUB

rem ============== Score et réglage des paliers pour les viveaux ===============
SUB affiscore()
    ' affichage du score et progression du niveau par paliers
    if score%=1 then niveau%=niveau%+1  :' 2
    if score%=3 then niveau%=niveau%+1  :' 3
    if score%=7 then niveau%=niveau%+1  :' 4
    if score%=12 then niveau%=niveau%+1 :' 5
    if score%=17 then niveau%=niveau%+1 :' 6
    if score%=20 then niveau%=niveau%+1 :' 7
    if score%=25 then niveau%=niveau%+1 :' 8
    if score%=30 then niveau%=niveau%+1 :' 9
    if score%=35 then niveau%=niveau%+1 :' 10
    caption "CHASSEUR D'ASTEROIDES  -  Score: "+str$(score%)+"  -  Niveau: "+str$(niveau%)
    niveau()
END_SUB

rem ================== Attribution des touches du clavier ======================
touche:
' Touches du pavé numérique
  if KEY_DOWN_CODE = 97 then move(1)                        : ' 1 End
  if KEY_DOWN_CODE = 40 or KEY_DOWN_CODE = 98 then move(2)  : ' 2 Bas
  if KEY_DOWN_CODE = 99 then move(3)                        : ' 3 PgDn
  if KEY_DOWN_CODE = 37 or KEY_DOWN_CODE = 100 then move(4) : ' 4 gauche
  if KEY_DOWN_CODE = 39 or KEY_DOWN_CODE = 102 then move(5) : ' 5 droite
  if KEY_DOWN_CODE = 103 then move(6)                      : ' 6 Home
  if KEY_DOWN_CODE = 38 or KEY_DOWN_CODE = 104 then move(7) : ' 7 haut
  if KEY_DOWN_CODE = 105 then move(8)                      : ' 8 PgUp
  if KEY_DOWN_CODE = 27 then gosub fin                      : ' Echap
  if KEY_DOWN_CODE = 80 then gosub Attente : return
  if KEY_DOWN_CODE = 83 then timer_off 3
  if KEY_DOWN_CODE = 77 then timer_on 3 : play 197
  if KEY_DOWN_CODE = 32 AND Cpt_tirs% < Nb_tirs%
      Cpt_tirs% = Cpt_tirs% + 1
      tir%(Cpt_tirs%) = 1 :  tir_d(Cpt_tirs%) = d  : ' On mémorise qu'un tir est actif et la direction de ce tir
      ' On ajuste la position initale du tir en fonction de la direction du vaisseau
      if d = 5*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 33
      if d = 3*pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y% + 44
      if d = 7*pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 33
      if d = pi then tir_x(Cpt_tirs%) = x%      : tir_y(Cpt_tirs%) = y% + 22
      if d = 0 then tir_x(Cpt_tirs%) = x% + 44 : tir_y(Cpt_tirs%) = y% + 22
      if d = 3*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 11
      if d = pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y%
      if d = pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 11
      sprite_position 39+Cpt_tirs%,tir_x(Cpt_tirs%), tir_y(Cpt_tirs%) : SPRITE_SHOW 39+Cpt_tirs%
  end_if    : ' Fin du traitement d'un appuie sur espace
on_key_down touche
return

rem ==================== Boucle_principale (tour) ==============================
boucle_principale:
timer_off 2: off_key_down
  if niveau%>2
    ' on gére le vaisseau ennemi pour ce tour
    if SpriteVE%=0 then new_ennemi()
    ennemi()
  end_if
  if Cpt_tirs% > 0
    for i% = 1 to Cpt_tirs%
      if tir%(i%) = 1 then tir(i%) :  ' Si un tir est actif, on gère son tour
        cpt_t_asteroide = cpt_t_asteroide + 1
        if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(2)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 3 then asteroide(3)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
    next i%
  else
    cpt_t_asteroide = cpt_t_asteroide + 1
    if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
    if cpt_t_asteroide = 2 then asteroide(2)  : ' On gère notre asteroid pour ce tour
    if cpt_t_asteroide = 3 then asteroide(3)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
  end_if
  FOR i% = 1 TO Nb_Asteroides%
      Test_collision_vaisseau(i%)
  next i%
timer_on 2 : on_key_down touche
return

rem ============================================================================
SUB vaisseau_detruit(Aster%)
    ' animation de la destruction de la cible
    off_key_down
    sprite_position 29 + Aster%,xA%(Aster%)+20,yA%(Aster%)+20 : SPRITE_HIDE SpriteV%
    scene2d_interval 250
    sprite_position 12,(xA%(Aster%) - 60),(yA%(Aster%) - 60) : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau(Aster%)
  Collision_AABB(xA%(Aster%),yA%(Aster%),22,24,x%,y%,32,32) :' vérifier si le vaisseau ami n'est pas en collision avec l'astéroide
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit(Aster%)
    message "Votre vaisseau est détruit!"+chr$(13)+chr$(13)+"Votre score: "+str$(score%) :' fin de partie
    gosub fin
  end_if
' test collision VE avec Aster
  if SpriteVE%<>0
    Collision_AABB(xA%(Aster%),yA%(Aster%),16,16,xE%,yE%,28,28) :' vérifier si le vaisseau ennemi n'est pas en collision avec l'astéroide
    if tir$="OK"
      play 198 : ' explosion vaisseau
    ' animation de la destruction du vaisseau ennemi par aster
    off_key_down
    SPRITE_HIDE SpriteVE%
    scene2d_interval 250
    sprite_position 12,xE%-60,yE%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 400 : SPRITE_HIDE 12
    SpriteVE%=0 : tirE%=0
    end_if
  end_if
END_SUB

rem ============================================================================
' New_astéroide
SUB new_asteroide(Aster%)
scene2d_interval 500
  vit_ast_x%(Aster%)= 0 : vit_ast_y%(Aster%)= 0  : ' On initialise le compteur pour un lancé aléatoire
  while (abs(vit_ast_x%(Aster%)) + abs(vit_ast_y%(Aster%))) < 5      : ' On fixe une vitesse minimale en dessous
    vit_ast_x%(Aster%)=rnd(20) - 10 : vit_ast_y%(Aster%)=rnd(20) - 10 : ' de laquelle on n'accepte pas le tirage
  end_while                                                  : ' la vitesse peut être positive ou négative
  xA%(Aster%) = screen_x + 10 : yA%(Aster%) = screen_y + 10  : ' on fixe la position de départ de l'astéroid en bas à droite
  if vit_ast_x%(Aster%) > 0 then xA%(Aster%)=-10              : ' si la vitesse en x est positive, on change le point de départ à gauche
  if vit_ast_y%(Aster%) > 0 then yA%(Aster%)=-10              : ' si la vitesse en y est positive, on change le point de départ en haut
  sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)        : ' on positionne notre asteroide
END_SUB

rem ============================================================================
' astéroide
SUB asteroide(Aster%)
      if ((xA%(Aster%) < (0-10)) and (vit_ast_x%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((xA%(Aster%) > (screen_x + 10)) and (vit_ast_x%(Aster%) > 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) < (0-10))  and (vit_ast_y%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) > (screen_y + 10)) and (vit_ast_y%(Aster%) > 0)) then new_asteroide(Aster%)
      xA%(Aster%)=xA%(Aster%)+vit_ast_x%(Aster%) : yA%(Aster%)=yA%(Aster%)+vit_ast_y%(Aster%)
      sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)
      Test_collision_vaisseau(Aster%)
END_SUB

rem ============================================================================
' libère un tir
SUB Annule_tir(N_t%)
 tir_d(N_t%) = tir_d(Cpt_tirs%) :  tir_x(N_t%) = tir_x(Cpt_tirs%) : tir_y(N_t%) = tir_y(Cpt_tirs%)
 SPRITE_POSITION 39 + N_t%,tir_x(N_t%), tir_y(N_t%) : SPRITE_HIDE 39 + Cpt_tirs%
 tir%(Cpt_tirs%) = 0 : Cpt_tirs% = Cpt_tirs% - 1
END_SUB

rem ============================================================================
' Tirer une balle dans l'une des 8 directions possibles du sprite
SUB tir(N_t%)
dim_local pxbe%,pybe%,pxve%,pyve%
  tir_x(N_t%) = tir_x(N_t%) + cos(tir_d(N_t%))* vit_mis%  : tir_y(N_t%) = tir_y(N_t%) - sin(tir_d(N_t%)) * vit_mis%
  if (cos(tir_d(N_t%)) > 0 and tir_x(N_t%) > screen_x) or (cos(tir_d(N_t%)) < 0 and tir_x(N_t%) < 0 ) or (sin(tir_d(N_t%)) < 0 and tir_y(N_t%) > screen_y) or (sin(tir_d(N_t%)) > 0 and tir_y(N_t%) < 0 )
    Annule_tir(N_t%)
  end_if
  sprite_position 39+N_t%,tir_x(N_t%), tir_y(N_t%) : ' Mouvement de la balle du tir
  FOR n% = 1 TO Nb_Asteroides%
      Collision_AABB(tir_x(N_t%),tir_y(N_t%),16,16,xA%(n%),yA%(n%), 22,24)
      if tir$="OK" then tir_ok(N_t%,n%)
  NEXT n%
  ' verif si collision avec vaisseau ennemi
if SpriteVE%<>0
    pxbe%=sprite_x_position(39+N_t%) : pybe%=sprite_y_position(39+N_t%)
    pxve%=sprite_x_position(SpriteVE%) : pyve%=sprite_y_position(SpriteVE%)
    Collision_AABB(pxbe%,pybe%,10,10,pxve%,pyve%,40,40)
    if tir$="OK"
      Annule_tir(N_t%)
      off_key_down
      play 198 : ' explosion vaisseau
    '  animation de la destruction du vaisseau ami par un ennemi
      SPRITE_HIDE SpriteVE% : tirE%=0  : SPRITE_HIDE 69
      scene2d_interval 250
      sprite_position 12,pxbe%-60,pybe%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
      pause 400 : SPRITE_HIDE 12 : SpriteVE%=0
      on_key_down touche
      score%=score%+1 : affiscore()
    end_if
end_if
END_SUB

rem ============================================================================
SUB tir_ok(N_t%,N_a%)
    ' animation de la destruction de la cible
play 199 :' explosion_aster
    Annule_tir(N_t%)
    off_key_down
    sprite_position 11,(xA%(N_a%) - 40),(yA%(N_a%) - 40) : SPRITE_SHOW 11 : sprite_animated_frames 11,8,14
    pause 200 : SPRITE_HIDE 29 + N_a% : SPRITE_HIDE 11
    on_key_down touche
    score%=score%+2 : affiscore()
    new_asteroide(N_a%):  SPRITE_SHOW 29 + N_a%
END_SUB

rem ============================================================================
SUB Collision_AABB(r1_x%,r1_y%,r1_width,r1_height,r2_x%,r2_y%, r2_width,r2_height)
  Tir$="OK"
  IF ((r2_x% >= (r1_x% + r1_width)) OR ((r2_x% + r2_width) <= r1_x%) OR (r2_y% >= (r1_y% + r1_height)) OR ((r2_y% + r2_height) <= r1_y%)) THEN Tir$=""
END_SUB

rem ============================================================================
' d est la direction (le cap) que prendra le sprite
SUB move(nsp%)
    select nsp%
        case 1 : x% = x% - vit_vai% : y% = y% + vit_vai%  : d = 5*pi/4
        case 2 : y% = y% + vit_vai%                  : d = 3*pi/2
        case 3 : x% = x% + vit_vai% : y% = y% + vit_vai%  : d = 7*pi/4
        case 4 : x% = x% - vit_vai%                  : d = pi
        case 5 : x% = x% + vit_vai%                  : d = 0
        case 6 : x% = x% - vit_vai% : y% = y% - vit_vai%  : d = 3*pi/4
        case 7 : y% = y% - vit_vai%                  : d = pi/2
        case 8 : x% = x% + vit_vai% : y% = y% - vit_vai%  : d = pi/4
    end_select
'    caption str$(nsp%) + ":" + str$(SpriteV%)
    if nsp% <> SpriteV%
        sprite_hide SpriteV% : SpriteV% = nsp%  : sprite_position nsp%,x%,y% :sprite_show nsp%
    else
        sprite_position nsp%,x%,y%
    end_if
' Le mode ENROULE : si le sprite sort de la zone , il réapparait de l'autre côté
    if x% < 0  then x% = screen_x
    if x% > screen_x then x% = 0
    if y% < 0 then y% = screen_y
    if y% > screen_y then y% = 0

END_SUB
rem ============================================================================
SUB ennemi()
    SPRITE_SHOW SpriteVE%
    ' bouger le vaisseau
    if SpriteVE%=63 then xE%=xE%+vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=62 then yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=61 then xE%=xE%-vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=64 then xE%=xE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=66 then xE%=xE%-vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=67 then yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=68 then xE%=xE%+vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=65 then xE%=xE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    sprite_position SpriteVE%,xE%,yE%
'  Pas de collision donc
'  si en dehors du cadre SpriteVE%=0
    if xE%<(0-64) or xE%>(screen_x+64) or yE%<(0-64) or yE%>(screen_y+64)
      SpriteVE%=0 : tirE%=0 : SPRITE_HIDE 69
    else
    ' faire un tir ou pas
      if xE%>128 and xE%<(screen_x-128) and yE%>128 and yE%<(screen_y-128)
        if tirE%=0
            init_tir_ennemi() : tir_ennemi()
        else
            tir_ennemi()
        end_if
      end_if
    end_if
END_SUB

rem ============================================================================
SUB tir_ennemi()
dim_local pxbe%,pybe%
    pxbe%=sprite_x_position(69) : pybe%=sprite_y_position(69)
    ' vérifier si la balle est sortie
    if SpriteVE%=63 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBD)
    if SpriteVE%=62 then pybe%=pybe%+(vit_E%*2)                          :' (VEB)
    if SpriteVE%=61 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBG)
    if SpriteVE%=64 then pxbe%=pxbe%-(vit_E%*2)                          :' (VEG)
    if SpriteVE%=66 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHG)
    if SpriteVE%=67 then pybe%=pybe%-(vit_E%*2)                          :' (VEH)
    if SpriteVE%=68 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHD)
    if SpriteVE%=65 then pxbe%=pxbe%+(vit_E%*2)                          :' (VED)
    sprite_position 69,pxbe%,pybe%
    Collision_AABB(pxbe%,pybe%,32,32,x%,y%,32,32)
    if tir$="OK"
      play 198 : ' explosion vaisseau
      tirE%=0 : vaisseau_detruit_par_E(69)
      message "Vos ennemis sont d'excellent tireur ! c'est terminé pour vous"+chr$(13)+chr$(13)+"Votre score: "+str$(score%)
      gosub fin
    end_if
END_SUB

rem ============================================================================
SUB init_tir_ennemi()
dim_local pxbe%,pybe%
    tirE%=tirE%+1
    ' position de départ
    if SpriteVE%=63 then pxbe%=xE%+45 : pybe%=yE%+45
    if SpriteVE%=62 then pxbe%=xE%+25 : pybe%=yE%+55
    if SpriteVE%=61 then pxbe%=xE%+2  : pybe%=yE%+48
    if SpriteVE%=64 then pxbe%=xE%-7  : pybe%=yE%+24
    if SpriteVE%=66 then pxbe%=xE%    : pybe%=yE%
    if SpriteVE%=67 then pxbe%=xE%+24 : pybe%=yE%-12
    if SpriteVE%=68 then pxbe%=xE%+47 : pybe%=yE%
    if SpriteVE%=65 then pxbe%=xE%+56 : pybe%=yE%+24
    SPRITE_SHOW 69 : sprite_position 69,pxbe%,pybe%
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau_E(nspE%)
    ' test collision entre vaisseaux
  Collision_AABB(x%,y%,28,28,xE%,yE%,28,28)
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit_par_E(nspE%)
    message "HA ! HA ! Il y a des kamikazes, chez vos ennemis !"+chr$(13)+chr$(13)+"Votre score: "+str$(score%): ' fin de partie
    gosub fin
  end_if
END_SUB
rem ============================================================================
SUB vaisseau_detruit_par_E(NE%)
dim_local px%,py%
    px%=sprite_x_position(SpriteV%) : py%=sprite_y_position(SpriteV%)
    ' animation de la destruction du vaisseau ami par un ennemi
      play 198 : ' explosion vaisseau
    off_key_down : tirE%=0 : SPRITE_HIDE 69
    SPRITE_HIDE SpriteV% : SPRITE_HIDE NE% :' les deux sont détruit
    scene2d_interval 250 : scene2d_on
    sprite_position 12,px%-60,py%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
    scene2d_off
END_SUB
rem ============================================================================
' nouveau vaisseau ennemi
SUB new_ennemi()
dim_local pde%
    ' choix aléatoire du vaisseau
    repeat : pde%=rnd(9): until pde%>0 and pde%<9
    if pde%<1 or pde%>8 then message "Echec choix aléatoire pde%="+str$(pde%) : terminate
    ' positionner (aléatoirement) le vaisseau en dehors de l'écran suivant le choix
    if pde%=1 then SpriteVE%=63 : xE%=-64 : yE%=-64                      :' Coin HG (VEBD)
    if pde%=2 then SpriteVE%=62 : xE%=rnd(screen_x) : yE%=-64            :' Haut    (VEB)
    if pde%=3 then SpriteVE%=61 : xE%=screen_x+64 : yE%=-64              :' Coin HD (VEBG)
    if pde%=4 then SpriteVE%=64 : xE%=screen_x+64 : yE%=rnd(screen_y)    :' Droite  (VEG)
    if pde%=5 then SpriteVE%=66 : xE%=screen_x+64 : yE%=screen_y+64      :' Coin BD (VEHG)
    if pde%=6 then SpriteVE%=67 : xE%=rnd(screen_x) : yE%=screen_y+64    :' Bas (VEH)
    if pde%=7 then SpriteVE%=68 : xE%=-64 : yE%=screen_y+64              :' Coin BG (VEHD)
    if pde%=8 then SpriteVE%=65 : xE%=-64 : yE%=rnd(screen_y)            :' Gauche (VED)
    sprite_position SpriteVE%,xE%,yE%
    ' déterminer une vitesse aléatoire
    repeat : vit_E%=rnd(vit_E_max%) : until vit_E%>vit_E_min%
END_SUB

rem ============================================================================

fin:
  terminate
return


C'est de mieux en mieux. cheers

A+
Revenir en haut Aller en bas
Jicehel

Jicehel


Nombre de messages : 5947
Age : 51
Localisation : 77500
Date d'inscription : 18/04/2011

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyMer 24 Juin 2015 - 21:53

C'est le but de travailler à plusieurs. Prendre le meilleur de chaque  Wink PS: Le plantage qui nous sort du jeu a toujours lieu après l'explosion d'un asteroide mais pas de message d'erreur pour nous mettre sur la voie.
Revenir en haut Aller en bas
Nardo26

Nardo26


Nombre de messages : 2294
Age : 55
Localisation : Valence
Date d'inscription : 02/07/2010

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyJeu 25 Juin 2015 - 0:44

Je rencontre un petit pb :

J'ai téléchargé le zip.
Si je lance l'exécutable, ok cela fonctionne.

Par contre, si j'essaye de lancer le .bas, un form 0 s'ouvre 2 seconde puis se referme tout seul.

En mettant en commentaire le ON_ERROR_GOTO (ligne 25), j'obtiens le message d'erreur suivant :

(90) No SCENE2D to receive this SPRITE. Line: 35

chasseur d’astéroïdes V3 58

EDIT : J'ai rien dis !!! J'ai pas lancé le bon éditeur... Embarassed
Revenir en haut Aller en bas
http://nardo26.lescigales.org
papydall

papydall


Nombre de messages : 7008
Age : 73
Localisation : Moknine (Tunisie) Entre la chaise et le clavier
Date d'inscription : 03/03/2012

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyJeu 25 Juin 2015 - 1:02

Trop tard !
Tu as tout dis.
Mais tu me rassures : il n’y a pas que Papydall qui est parfois idruoté, tiartsid, fitnettani. Laughing
Rappel : L’arabe s’écrit de droite à gauche.
Revenir en haut Aller en bas
http://papydall-panoramic.forumarabia.com/
Jean Claude

Jean Claude


Nombre de messages : 5950
Age : 69
Localisation : 83 Var
Date d'inscription : 07/05/2009

chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 EmptyJeu 25 Juin 2015 - 9:50

Voici la dernière version.

Point principale: j'ai affiné les réglages, la montée en puissance est plus rapide.

il n'y a presque plus de "plantage", et je pense que c'est dû au fait qu'il a moins de missiles à la traîne.

C'est ici:
Code:
' AsterV3.bas (Jean Claude, Jicehel, Papydall) (JUIN 2015)

rem ============================================================================

dim n%,i%,at%
dim pi : pi = acos(-1)              : ' mémorise la valeur pi
dim x%,y%,vit_vai%                  : ' position et vitesse du vaisseau
dim d  : d = pi/2                  : ' direction (c'est le cap) de départ du vaisseau (vers le haut)
dim Nb_tirs%,Cpt_tirs% : Nb_tirs%=5 : ' Nombre de tirs autorisés et compteur de tirs actifs
dim tir$,tir%(Nb_tirs%), tir_x(Nb_tirs%),tir_y(Nb_tirs%),tir_d(Nb_tirs%),vit_mis% : ' Resultat du tir, Tir actif ou non, coord en x et en y du tir et mémoristion de la direction et vitesse
dim Nb_Asteroides%,Cpt_asteroides% : Nb_Asteroides% = 3    : ' Nombre d'Asteroides actifs
dim xA%(Nb_Asteroides%),yA%(Nb_Asteroides%)                : ' Position des asteroides
dim vit_ast_x%(Nb_Asteroides%), vit_ast_y%(Nb_Asteroides%)  : ' Vitesse des asteroides
dim SpriteV%        :' Pour savoir quelle image du vaisseau ami est en service (car d change dans la sub move)
dim score%          :' Pour le score
dim cpt_t_asteroide : ' ralentisseur pour les mouvements de l'asteroid
dim niveau%        :' Niveau du jeu
dim xE%,yE%            :' Position de l'ennemi
dim vit_E%,vit_E_max%,vit_E_min%  :' Vitesse de l'ennemi et son maximum et minimum
dim tirE%              :' Tir ennemi
dim SpriteVE% :' Pour savoir quelle image du vaisseau ennmi est en service

' Déclaration des étiquettes
label touche,boucle_principale,fin,Attente,Repart,Musique
on_error_goto fin

' fichiers audios
sound 197 : file_load 197,"audio/dreamland.wav": ' explosion du vaisseau
sound 198 : file_load 198,"audio/explosion_vaisseau.wav": ' explosion du vaisseau
sound 199 : file_load 199,"audio/explosion_aster.wav"  : ' explosion des asteroides

' création des vaisseaux amis
SPRITE 1 : SPRITE_FILE_LOAD 1,"image/VBG.bmp" : SPRITE_HIDE 1
SPRITE 2 : SPRITE_FILE_LOAD 2,"image/VB.bmp"  : SPRITE_HIDE 2
SPRITE 3 : SPRITE_FILE_LOAD 3,"image/VBD.bmp" : SPRITE_HIDE 3
SPRITE 4 : SPRITE_FILE_LOAD 4,"image/VG.bmp"  : SPRITE_HIDE 4
SPRITE 5 : SPRITE_FILE_LOAD 5,"image/VD.bmp"  : SPRITE_HIDE 5
SPRITE 6 : SPRITE_FILE_LOAD 6,"image/VHG.bmp" : SPRITE_HIDE 6
SPRITE 7 : SPRITE_FILE_LOAD 7,"image/VH.bmp"  : SPRITE_HIDE 7
SPRITE 8 : SPRITE_FILE_LOAD 8,"image/VHD.bmp" : SPRITE_HIDE 8

SPRITE_ANIMATED 11 : SPRITE_ANIMATED_FILE_LOAD 11,5,5,"image/meteore.bmp"  : SPRITE_HIDE 11  : ' explosion astéroide
SPRITE_ANIMATED 12 : SPRITE_ANIMATED_FILE_LOAD 12,5,5,"image/meteore2.bmp" : SPRITE_HIDE 12  : ' explosion vaisseau

i%=19
FOR n% = 0 TO 9
i%=i%+1
SPRITE i% : SPRITE_FILE_LOAD i%,"image/"+str$(n%)+".bmp" : SPRITE_HIDE i%  : ' chiffres pour le score
NEXT n%

FOR n% = 1 TO Nb_Asteroides%
  SPRITE_ANIMATED 29 + n% : ' Créé un sprite pour un astéroide
  SPRITE_ANIMATED_FILE_LOAD 29 + n% ,1,8,"image/rock8.bmp"    : ' Charge le sprite animé correspondant à l'astéroide
  new_asteroide(n%) : SPRITE_SHOW 29 + n%  : ' Créé l'astéroid initial
NEXT n%
Cpt_asteroides% = Nb_Asteroides%

FOR n% = 1 TO Nb_tirs%
  SPRITE 39 + n% : SPRITE_FILE_LOAD 39 + n%,"image/balle.bmp"
  SPRITE_HIDE 39 + n%  : ' le  missile 1 à 5
  tir%(n%) = 0 : ' Au début pas de tir actif
NEXT n%

' Sprites pour le générique.
SPRITE 51 : SPRITE_FILE_LOAD 51,"image/gen3.bmp" : SPRITE_POSITION 51,(screen_x/2)-350,screen_y+200 :' SPRITE_HIDE 51
SPRITE 50 : SPRITE_FILE_LOAD 50,"image/gen1.bmp" : SPRITE_POSITION 50,(screen_x/2)-350,screen_y-40 :' SPRITE_HIDE 50

' création des vaisseaux ennemis
SPRITE 61 : SPRITE_FILE_LOAD 61,"image/VEBG.bmp" : SPRITE_HIDE 61
SPRITE 62 : SPRITE_FILE_LOAD 62,"image/VEB.bmp"  : SPRITE_HIDE 62
SPRITE 63 : SPRITE_FILE_LOAD 63,"image/VEBD.bmp" : SPRITE_HIDE 63
SPRITE 64 : SPRITE_FILE_LOAD 64,"image/VEG.bmp"  : SPRITE_HIDE 64
SPRITE 65 : SPRITE_FILE_LOAD 65,"image/VED.bmp"  : SPRITE_HIDE 65
SPRITE 66 : SPRITE_FILE_LOAD 66,"image/VEHG.bmp" : SPRITE_HIDE 66
SPRITE 67 : SPRITE_FILE_LOAD 67,"image/VEH.bmp"  : SPRITE_HIDE 67
SPRITE 68 : SPRITE_FILE_LOAD 68,"image/VEHD.bmp" : SPRITE_HIDE 68
' boulet ennemi
SPRITE 69 : SPRITE_FILE_LOAD 69,"image/balleE.bmp" : SPRITE_HIDE 69

' scene2D
BACKGND_LOAD "image/espace.bmp"

niveau%=1 : niveau() : cpt_t_asteroide = 0 : Cpt_tirs% = 0

play 197 : generique()

' init
x%=(screen_x/2)+32 : y%=700 : sprite_position 7,x%,y% : SpriteV% = 7 : SPRITE_SHOW 7
scene2d_interval 80
affiscore()
on_key_down touche              : ' Active la gestion de l'appuie des touches

timer 2 : timer_interval 2,20 : on_timer 2,boucle_principale  : ' Activation du timer qui activera les tours de jeu
timer 3 : timer_interval 3,100000 : on_timer 3,Musique  : ' Musique d'ambiance (recommance toutes les minutes)


END

rem ================================ Musique ===================================
Musique:
  play 197
return

rem ================================= PAUSE ====================================
Attente:
timer_off 2 : timer_off 3
on_key_down Repart
return

Repart:
timer_on 3 : timer_on 2 : on_key_down touche
return

rem =============================== Générique ==================================
SUB generique()
DIM_LOCAL X1,Y1,X2,Y2,Y3,Y4
  scene2d_interval 20 : scene2d_on
  X1=0 : Y1=0 : X2=2184 : Y2=1167 : view X1,Y1,X2,Y2
  Y2=600 : Y3=70 : Y4=screen_y+100
  SPRITE_POSITION 50,(screen_x/2)-350,Y3
  repeat
      Y1=Y1+1 : Y2=Y2+1 : view X1,Y1,X2,Y2
      Y4=Y4-2 : SPRITE_POSITION 51,(screen_x/2)-350,Y4
  scene2d_off : pause 50
  until y2>1000 or scancode<>0
  pause 2000
  X1=0 : Y1=0 : X2=screen_x : Y2=screen_y : view X1,Y1,X2,Y2
  SPRITE_HIDE 50 : SPRITE_HIDE 51
END_SUB

rem ========================== Réglage des Niveaux =============================
SUB niveau()
    if niveau%=1 then vit_vai%=8 : vit_mis%=20
    if niveau%=2 then vit_vai%=9 : vit_mis%=22
    if niveau%=3 then vit_vai%=10 : vit_mis%=24  : vit_E_max%=8 : vit_E_min%=3
    if niveau%=4 then vit_vai%=11 : vit_mis%=26  : vit_E_max%=9 : vit_E_min%=4
    if niveau%=5 then vit_vai%=12 : vit_mis%=28  : vit_E_max%=10 : vit_E_min%=5
    if niveau%=6 then vit_vai%=13 : vit_mis%=30  : vit_E_max%=11 : vit_E_min%=6
    if niveau%=7 then vit_vai%=14 : vit_mis%=32  : vit_E_max%=12 : vit_E_min%=7
    if niveau%=8 then vit_vai%=15 : vit_mis%=34  : vit_E_max%=13 : vit_E_min%=8
    if niveau%=9 then vit_vai%=16 : vit_mis%=36  : vit_E_max%=14 : vit_E_min%=9
    if niveau%=10 then vit_vai%=17 : vit_mis%=38 : vit_E_max%=15 : vit_E_min%=10

' réglages
' vit_vai% = 8 :' + => plus rapide
' vit_mis%=20  :' + => plus rapide
' vit_E_min%=2 : ' vitesse ennemi: minimum 2
' vit_E_max%=12 :' vitesse ennemi: + => plus rapide (mais aléatoire >vit_E_min%)

END_SUB

rem ============== Score et réglage des paliers pour les viveaux ===============
SUB affiscore()
    ' affichage du score et progression du niveau par paliers
    if score%=1 then niveau%=niveau%+1  :' 2
    if score%=2 then niveau%=niveau%  :' 2
    if score%=3 then niveau%=niveau%+1  :' 3
    if score%=4 then niveau%=niveau%  :' 3
    if score%>4 and score%<10 then niveau%=niveau%+1  :' 4
    if score%>9 and score%<15 then niveau%=niveau%+1 :' 5
    if score%>14 and score%<20 then niveau%=niveau%+1 :' 6
    if score%>19 and score%<25 then niveau%=niveau%+1 :' 7
    if score%>24 and score%<30 then niveau%=niveau%+1 :' 8
    if score%>29 and score%<35 then niveau%=niveau%+1 :' 9
    if score%>34 then niveau%=10
    caption "CHASSEUR D'ASTEROIDES  -  Score: "+str$(score%)+"  -  Niveau: "+str$(niveau%)
    niveau()
END_SUB

rem ================== Attribution des touches du clavier ======================
touche:
' Touches du pavé numérique
  if KEY_DOWN_CODE = 97 then move(1)                        : ' 1 End
  if KEY_DOWN_CODE = 40 or KEY_DOWN_CODE = 98 then move(2)  : ' 2 Bas
  if KEY_DOWN_CODE = 99 then move(3)                        : ' 3 PgDn
  if KEY_DOWN_CODE = 37 or KEY_DOWN_CODE = 100 then move(4) : ' 4 gauche
  if KEY_DOWN_CODE = 39 or KEY_DOWN_CODE = 102 then move(5) : ' 5 droite
  if KEY_DOWN_CODE = 103 then move(6)                      : ' 6 Home
  if KEY_DOWN_CODE = 38 or KEY_DOWN_CODE = 104 then move(7) : ' 7 haut
  if KEY_DOWN_CODE = 105 then move(8)                      : ' 8 PgUp
  if KEY_DOWN_CODE = 27 then gosub fin                      : ' Echap
  if KEY_DOWN_CODE = 80 then gosub Attente : return
  if KEY_DOWN_CODE = 83 then timer_off 3
  if KEY_DOWN_CODE = 77 then timer_on 3 : play 197
  if KEY_DOWN_CODE = 32 AND Cpt_tirs% < Nb_tirs%
      Cpt_tirs% = Cpt_tirs% + 1
      tir%(Cpt_tirs%) = 1 :  tir_d(Cpt_tirs%) = d  : ' On mémorise qu'un tir est actif et la direction de ce tir
      ' On ajuste la position initale du tir en fonction de la direction du vaisseau
      if d = 5*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 33
      if d = 3*pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y% + 44
      if d = 7*pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 33
      if d = pi then tir_x(Cpt_tirs%) = x%      : tir_y(Cpt_tirs%) = y% + 22
      if d = 0 then tir_x(Cpt_tirs%) = x% + 44 : tir_y(Cpt_tirs%) = y% + 22
      if d = 3*pi/4 then tir_x(Cpt_tirs%) = x% + 11 : tir_y(Cpt_tirs%) = y% + 11
      if d = pi/2 then tir_x(Cpt_tirs%) = x% + 22 : tir_y(Cpt_tirs%) = y%
      if d = pi/4 then tir_x(Cpt_tirs%) = x% + 33 : tir_y(Cpt_tirs%) = y% + 11
      sprite_position 39+Cpt_tirs%,tir_x(Cpt_tirs%), tir_y(Cpt_tirs%) : SPRITE_SHOW 39+Cpt_tirs%
  end_if    : ' Fin du traitement d'un appuie sur espace
on_key_down touche
return

rem ==================== Boucle_principale (tour) ==============================
boucle_principale:
timer_off 2: off_key_down
  if niveau%>2
    ' on gére le vaisseau ennemi pour ce tour
    if SpriteVE%=0 then new_ennemi()
    ennemi()
  end_if
  cpt_t_asteroide = cpt_t_asteroide + 1
  if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
  if cpt_t_asteroide = 2 then asteroide(3): ' On gère notre asteroid pour ce tour
  if cpt_t_asteroide = 2 then asteroide(2)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
  FOR i% = 1 TO Nb_Asteroides%
      Test_collision_vaisseau(i%)
  next i%
  if Cpt_tirs% > 0
    for i% = 1 to Cpt_tirs%
      if tir%(i%) = 1 then tir(i%) :  ' Si un tir est actif, on gère son tour
        cpt_t_asteroide = cpt_t_asteroide + 1
        if cpt_t_asteroide = 1 then asteroide(1)  : ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(3): ' On gère notre asteroid pour ce tour
        if cpt_t_asteroide = 2 then asteroide(2)  :  cpt_t_asteroide = 0 : ' On gère notre asteroid pour ce tour
    next i%
  end_if
timer_on 2 : on_key_down touche
return

rem ============================================================================
SUB vaisseau_detruit(Aster%)
    ' animation de la destruction de la cible
    off_key_down
    sprite_position 29 + Aster%,xA%(Aster%)+20,yA%(Aster%)+20 : SPRITE_HIDE SpriteV%
    scene2d_interval 250 : scene2d_on
    sprite_position 12,(xA%(Aster%) - 60),(yA%(Aster%) - 60) : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
    scene2d_off
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau(Aster%)
  Collision_AABB(xA%(Aster%),yA%(Aster%),22,24,x%,y%,32,32) :' vérifier si le vaisseau ami n'est pas en collision avec l'astéroide
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit(Aster%)
    message "Votre vaisseau est détruit!"+chr$(13)+chr$(13)+"Votre score: "+str$(score%) :' fin de partie
    gosub fin
  end_if
' test collision VE avec Aster
  if SpriteVE%<>0
    Collision_AABB(xA%(Aster%),yA%(Aster%),16,16,xE%,yE%,28,28) :' vérifier si le vaisseau ennemi n'est pas en collision avec l'astéroide
    if tir$="OK"
      play 198 : ' explosion vaisseau
    ' animation de la destruction du vaisseau ennemi par aster
    off_key_down
    SPRITE_HIDE SpriteVE%
    scene2d_interval 250 : scene2d_on
    sprite_position 12,xE%-60,yE%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 400 : SPRITE_HIDE 12 : scene2d_off
    SpriteVE%=0 : tirE%=0
    end_if
  end_if
END_SUB

rem ============================================================================
' New_astéroide
SUB new_asteroide(Aster%)
scene2d_interval 500 : scene2d_on
  vit_ast_x%(Aster%)= 0 : vit_ast_y%(Aster%)= 0  : ' On initialise le compteur pour un lancé aléatoire
  while (abs(vit_ast_x%(Aster%)) + abs(vit_ast_y%(Aster%))) < 5      : ' On fixe une vitesse minimale en dessous
    vit_ast_x%(Aster%)=rnd(20) - 10 : vit_ast_y%(Aster%)=rnd(20) - 10 : ' de laquelle on n'accepte pas le tirage
  end_while                                                  : ' la vitesse peut être positive ou négative
  xA%(Aster%) = screen_x + 10 : yA%(Aster%) = screen_y + 10  : ' on fixe la position de départ de l'astéroid en bas à droite
  if vit_ast_x%(Aster%) > 0 then xA%(Aster%)=-10              : ' si la vitesse en x est positive, on change le point de départ à gauche
  if vit_ast_y%(Aster%) > 0 then yA%(Aster%)=-10              : ' si la vitesse en y est positive, on change le point de départ en haut
  sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)        : ' on positionne notre asteroide
END_SUB

rem ============================================================================
' astéroide
SUB asteroide(Aster%)
      if ((xA%(Aster%) < (0-10)) and (vit_ast_x%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((xA%(Aster%) > (screen_x + 10)) and (vit_ast_x%(Aster%) > 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) < (0-10))  and (vit_ast_y%(Aster%) < 0)) then new_asteroide(Aster%)
      if ((yA%(Aster%) > (screen_y + 10)) and (vit_ast_y%(Aster%) > 0)) then new_asteroide(Aster%)
      xA%(Aster%)=xA%(Aster%)+vit_ast_x%(Aster%) : yA%(Aster%)=yA%(Aster%)+vit_ast_y%(Aster%)
      sprite_position 29 + Aster%,xA%(Aster%),yA%(Aster%)
      Test_collision_vaisseau(Aster%)
scene2d_off
END_SUB

rem ============================================================================
' libère un tir
SUB Annule_tir(N_t%)
 tir_d(N_t%) = tir_d(Cpt_tirs%) :  tir_x(N_t%) = tir_x(Cpt_tirs%) : tir_y(N_t%) = tir_y(Cpt_tirs%)
 SPRITE_POSITION 39 + N_t%,tir_x(N_t%), tir_y(N_t%) : SPRITE_HIDE 39 + Cpt_tirs%
 tir%(Cpt_tirs%) = 0 : Cpt_tirs% = Cpt_tirs% - 1
END_SUB

rem ============================================================================
' Tirer une balle dans l'une des 8 directions possibles du sprite
SUB tir(N_t%)
dim_local pxbe%,pybe%,pxve%,pyve%
  tir_x(N_t%) = tir_x(N_t%) + cos(tir_d(N_t%))* vit_mis%  : tir_y(N_t%) = tir_y(N_t%) - sin(tir_d(N_t%)) * vit_mis%
  if (cos(tir_d(N_t%)) > 0 and tir_x(N_t%) > screen_x) or (cos(tir_d(N_t%)) < 0 and tir_x(N_t%) < 0 ) or (sin(tir_d(N_t%)) < 0 and tir_y(N_t%) > screen_y) or (sin(tir_d(N_t%)) > 0 and tir_y(N_t%) < 0 )
    Annule_tir(N_t%)
  end_if
  sprite_position 39+N_t%,tir_x(N_t%), tir_y(N_t%) : ' Mouvement de la balle du tir
  FOR n% = 1 TO Nb_Asteroides%
      Collision_AABB(tir_x(N_t%),tir_y(N_t%),16,16,xA%(n%),yA%(n%), 22,24)
      if tir$="OK" then tir_ok(N_t%,n%)
  NEXT n%
  ' verif si collision avec vaisseau ennemi
if SpriteVE%<>0
    pxbe%=sprite_x_position(39+N_t%) : pybe%=sprite_y_position(39+N_t%)
    pxve%=sprite_x_position(SpriteVE%) : pyve%=sprite_y_position(SpriteVE%)
    Collision_AABB(pxbe%,pybe%,10,10,pxve%,pyve%,40,40)
    if tir$="OK"
      Annule_tir(N_t%)
      off_key_down
      play 198 : ' explosion vaisseau
    '  animation de la destruction du vaisseau ami par un ennemi
      SPRITE_HIDE SpriteVE% : tirE%=0  : SPRITE_HIDE 69
      scene2d_interval 250 : scene2d_on
      sprite_position 12,pxbe%-60,pybe%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
      pause 400 : SPRITE_HIDE 12 : SpriteVE%=0
      on_key_down touche
      scene2d_off :score%=score%+1 : affiscore()
    end_if
end_if
END_SUB

rem ============================================================================
SUB tir_ok(N_t%,N_a%)
    ' animation de la destruction de la cible
play 199 :' explosion_aster
    Annule_tir(N_t%)
    off_key_down
    sprite_position 11,(xA%(N_a%) - 40),(yA%(N_a%) - 40) : SPRITE_SHOW 11 : sprite_animated_frames 11,8,14
    pause 200 : SPRITE_HIDE 29 + N_a% : SPRITE_HIDE 11
    on_key_down touche
    score%=score%+2 : affiscore()
    new_asteroide(N_a%):  SPRITE_SHOW 29 + N_a%
END_SUB

rem ============================================================================
SUB Collision_AABB(r1_x%,r1_y%,r1_width,r1_height,r2_x%,r2_y%, r2_width,r2_height)
  Tir$="OK"
  IF ((r2_x% >= (r1_x% + r1_width)) OR ((r2_x% + r2_width) <= r1_x%) OR (r2_y% >= (r1_y% + r1_height)) OR ((r2_y% + r2_height) <= r1_y%)) THEN Tir$=""
END_SUB

rem ============================================================================
' d est la direction (le cap) que prendra le sprite
SUB move(nsp%)
    select nsp%
        case 1 : x% = x% - vit_vai% : y% = y% + vit_vai%  : d = 5*pi/4
        case 2 : y% = y% + vit_vai%                  : d = 3*pi/2
        case 3 : x% = x% + vit_vai% : y% = y% + vit_vai%  : d = 7*pi/4
        case 4 : x% = x% - vit_vai%                  : d = pi
        case 5 : x% = x% + vit_vai%                  : d = 0
        case 6 : x% = x% - vit_vai% : y% = y% - vit_vai%  : d = 3*pi/4
        case 7 : y% = y% - vit_vai%                  : d = pi/2
        case 8 : x% = x% + vit_vai% : y% = y% - vit_vai%  : d = pi/4
    end_select
'    caption str$(nsp%) + ":" + str$(SpriteV%)
    if nsp% <> SpriteV%
        sprite_hide SpriteV% : SpriteV% = nsp%  : sprite_position nsp%,x%,y% :sprite_show nsp%
    else
        sprite_position nsp%,x%,y%
    end_if
' Le mode ENROULE : si le sprite sort de la zone , il réapparait de l'autre côté
    if x% < 0  then x% = screen_x
    if x% > screen_x then x% = 0
    if y% < 0 then y% = screen_y
    if y% > screen_y then y% = 0

END_SUB
rem ============================================================================
SUB ennemi()
    SPRITE_SHOW SpriteVE%
    ' bouger le vaisseau
    if SpriteVE%=63 then xE%=xE%+vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=62 then yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=61 then xE%=xE%-vit_E% : yE%=yE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=64 then xE%=xE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=66 then xE%=xE%-vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=67 then yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=68 then xE%=xE%+vit_E% : yE%=yE%-vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    if SpriteVE%=65 then xE%=xE%+vit_E% : Test_collision_vaisseau_E(SpriteVE%)
    sprite_position SpriteVE%,xE%,yE%
'  Pas de collision donc
'  si en dehors du cadre SpriteVE%=0
    if xE%<(0-64) or xE%>(screen_x+64) or yE%<(0-64) or yE%>(screen_y+64)
      SpriteVE%=0 : tirE%=0 : SPRITE_HIDE 69
    else
    ' faire un tir ou pas
      if xE%>128 and xE%<(screen_x-128) and yE%>128 and yE%<(screen_y-128)
        if tirE%=0
            init_tir_ennemi() : tir_ennemi()
        else
            tir_ennemi()
        end_if
      end_if
    end_if
END_SUB

rem ============================================================================
SUB tir_ennemi()
dim_local pxbe%,pybe%
    pxbe%=sprite_x_position(69) : pybe%=sprite_y_position(69)
    ' vérifier si la balle est sortie
    if SpriteVE%=63 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBD)
    if SpriteVE%=62 then pybe%=pybe%+(vit_E%*2)                          :' (VEB)
    if SpriteVE%=61 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%+(vit_E%*2) :' (VEBG)
    if SpriteVE%=64 then pxbe%=pxbe%-(vit_E%*2)                          :' (VEG)
    if SpriteVE%=66 then pxbe%=pxbe%-(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHG)
    if SpriteVE%=67 then pybe%=pybe%-(vit_E%*2)                          :' (VEH)
    if SpriteVE%=68 then pxbe%=pxbe%+(vit_E%*2) : pybe%=pybe%-(vit_E%*2) :' (VEHD)
    if SpriteVE%=65 then pxbe%=pxbe%+(vit_E%*2)                          :' (VED)
    sprite_position 69,pxbe%,pybe%
    Collision_AABB(pxbe%,pybe%,32,32,x%,y%,32,32)
    if tir$="OK"
      tirE%=0 : vaisseau_detruit_par_E(69)
      message "Vos ennemis sont d'excellent tireur ! c'est terminé pour vous"+chr$(13)+chr$(13)+"Votre score: "+str$(score%)
      gosub fin
    end_if
END_SUB

rem ============================================================================
SUB init_tir_ennemi()
dim_local pxbe%,pybe%
    tirE%=tirE%+1
    ' position de départ
    if SpriteVE%=63 then pxbe%=xE%+45 : pybe%=yE%+45
    if SpriteVE%=62 then pxbe%=xE%+25 : pybe%=yE%+55
    if SpriteVE%=61 then pxbe%=xE%+2  : pybe%=yE%+48
    if SpriteVE%=64 then pxbe%=xE%-7  : pybe%=yE%+24
    if SpriteVE%=66 then pxbe%=xE%    : pybe%=yE%
    if SpriteVE%=67 then pxbe%=xE%+24 : pybe%=yE%-12
    if SpriteVE%=68 then pxbe%=xE%+47 : pybe%=yE%
    if SpriteVE%=65 then pxbe%=xE%+56 : pybe%=yE%+24
    SPRITE_SHOW 69 : sprite_position 69,pxbe%,pybe%
END_SUB

rem ============================================================================
SUB Test_collision_vaisseau_E(nspE%)
    ' test collision entre vaisseaux
  Collision_AABB(x%,y%,28,28,xE%,yE%,28,28)
  if tir$="OK"
    play 198 : ' explosion vaisseau
    vaisseau_detruit_par_E(nspE%)
    message "HA ! HA ! Il y a des kamikazes, chez vos ennemis !"+chr$(13)+chr$(13)+"Votre score: "+str$(score%): ' fin de partie
    gosub fin
  end_if
END_SUB
rem ============================================================================
SUB vaisseau_detruit_par_E(NE%)
dim_local px%,py%
    px%=sprite_x_position(SpriteV%) : py%=sprite_y_position(SpriteV%)
    ' animation de la destruction du vaisseau ami par un ennemi
      play 198 : ' explosion vaisseau
    off_key_down : tirE%=0 : SPRITE_HIDE 69
    SPRITE_HIDE SpriteV% : SPRITE_HIDE NE% :' les deux sont détruit
    scene2d_interval 250 : scene2d_on
    sprite_position 12,px%-60,py%-60 : SPRITE_SHOW 12 : sprite_animated_frames 12,8,14
    pause 2400 : SPRITE_HIDE 12
    scene2d_off
END_SUB

rem ============================================================================
' nouveau vaisseau ennemi
SUB new_ennemi()
dim_local pde%
    ' choix aléatoire du vaisseau
    repeat : pde%=rnd(9): until pde%>0 and pde%<9
    if pde%<1 or pde%>8 then message "Echec choix aléatoire pde%="+str$(pde%) : terminate
    ' positionner (aléatoirement) le vaisseau en dehors de l'écran suivant le choix
    if pde%=1 then SpriteVE%=63 : xE%=-64 : yE%=-64                      :' Coin HG (VEBD)
    if pde%=2 then SpriteVE%=62 : xE%=rnd(screen_x) : yE%=-64            :' Haut    (VEB)
    if pde%=3 then SpriteVE%=61 : xE%=screen_x+64 : yE%=-64              :' Coin HD (VEBG)
    if pde%=4 then SpriteVE%=64 : xE%=screen_x+64 : yE%=rnd(screen_y)    :' Droite  (VEG)
    if pde%=5 then SpriteVE%=66 : xE%=screen_x+64 : yE%=screen_y+64      :' Coin BD (VEHG)
    if pde%=6 then SpriteVE%=67 : xE%=rnd(screen_x) : yE%=screen_y+64    :' Bas (VEH)
    if pde%=7 then SpriteVE%=68 : xE%=-64 : yE%=screen_y+64              :' Coin BG (VEHD)
    if pde%=8 then SpriteVE%=65 : xE%=-64 : yE%=rnd(screen_y)            :' Gauche (VED)
    sprite_position SpriteVE%,xE%,yE%
    ' déterminer une vitesse aléatoire
    repeat : vit_E%=rnd(vit_E_max%) : until vit_E%>vit_E_min%
END_SUB

rem ============================================================================

fin:
  terminate
return
Revenir en haut Aller en bas
Contenu sponsorisé





chasseur d’astéroïdes V3 Empty
MessageSujet: Re: chasseur d’astéroïdes V3   chasseur d’astéroïdes V3 Empty

Revenir en haut Aller en bas
 
chasseur d’astéroïdes V3
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» Chasseur d'astéroïdes (PANGINE2D)
» chasseur d’astéroïdes V4 sonorisé par Bignono
» Asteroides

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC :: PANORAMIC :: Les jeux faits avec Panoramic-
Sauter vers: