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
» trop de fichiers en cours
Ca tourne mais ça n'avance pas bien Emptypar Marc Aujourd'hui à 11:42

» Bataille navale SM
Ca tourne mais ça n'avance pas bien Emptypar jjn4 Hier à 17:39

» Une calculatrice en une ligne de programme
Ca tourne mais ça n'avance pas bien Emptypar jean_debord Hier à 8:01

» Gestion d'un système client-serveur.
Ca tourne mais ça n'avance pas bien Emptypar Pedro Jeu 25 Avr 2024 - 19:31

» Les maths du crocodile
Ca tourne mais ça n'avance pas bien Emptypar jean_debord Jeu 25 Avr 2024 - 10:37

» Naissance de Crocodile Basic
Ca tourne mais ça n'avance pas bien Emptypar jean_debord Jeu 25 Avr 2024 - 8:45

» Editeur EliP 6 : Le Tiny éditeur avec 25 onglets de travail
Ca tourne mais ça n'avance pas bien Emptypar Froggy One Mer 24 Avr 2024 - 18:38

» Dessine-moi une galaxie
Ca tourne mais ça n'avance pas bien Emptypar jjn4 Lun 22 Avr 2024 - 13:47

» Erreur END_SUB
Ca tourne mais ça n'avance pas bien Emptypar jjn4 Lun 22 Avr 2024 - 13:43

» Bug sur DIM_LOCAL ?
Ca tourne mais ça n'avance pas bien Emptypar papydall Dim 21 Avr 2024 - 23:30

» Form
Ca tourne mais ça n'avance pas bien Emptypar leclode Dim 21 Avr 2024 - 18:09

» 2D_fill_color(résolu)
Ca tourne mais ça n'avance pas bien Emptypar leclode Sam 20 Avr 2024 - 8:32

» Consommation gaz électricité
Ca tourne mais ça n'avance pas bien Emptypar leclode Mer 17 Avr 2024 - 11:07

» on_key_down (résolu)
Ca tourne mais ça n'avance pas bien Emptypar leclode Mar 16 Avr 2024 - 11:01

» Sous-programme(résolu)
Ca tourne mais ça n'avance pas bien Emptypar jjn4 Jeu 4 Avr 2024 - 14:42

Navigation
 Portail
 Index
 Membres
 Profil
 FAQ
 Rechercher
Rechercher
 
 

Résultats par :
 
Rechercher Recherche avancée
Avril 2024
LunMarMerJeuVenSamDim
1234567
891011121314
15161718192021
22232425262728
2930     
CalendrierCalendrier
Le Deal du moment : -28%
Brandt LVE127J – Lave-vaisselle encastrable 12 ...
Voir le deal
279.99 €

 

 Ca tourne mais ça n'avance pas bien

Aller en bas 
4 participants
AuteurMessage
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptySam 16 Mar 2013 - 14:51

Bonjour à tous !

Je cherche toujours à comprendre ce qui ne va pas dans mon code. Au départ, on a un rectangle qui tourne :

Code:

if scancode=37 then Ang=Ang-5:Tourne%=1
if scancode=39 then Ang=Ang+5:Tourne%=1
Ang=mod(Ang,360)
print_locate 10,10:print str$(Ang)
if Tourne%=1 then GOSUB Rota : GOSUB Tracer

Puis j'ai voulu que ce rectangle avance dans la direction de l'angle. Au niveau du programme principal, cela donne :

Code:

    REPEAT
'
if scancode=37 then Ang=Ang-5:Tourne%=1
if scancode=39 then Ang=Ang+5:Tourne%=1
if scancode=38 then Pas=Pas+5:Avance%=1
if scancode=40 then Pas=Pas-5:Avance%=1
'
Ang=mod(Ang,360)
Angrad=Ang * pi/180
print_locate 10,10:print str$(Ang)
'
if Tourne%=1 then GOSUB ROTA : GOSUB TRACER
if Avance%=1 then GOSUB TRANS: GOSUB TRACER
'
    UNTIL scancode=27


Les sous-programmes de rotation et de translation fonctionnent bien et reprennent la même valeur Angrad. Seulement voila : le second programme change la valeur de l'angle. Si je tourne assez longtemps à gauche, puis à droite, la figure freine avant de ralentir et finit par tourner à droite... avec des valeurs de l'angle fantaisistes par rapport à ce que je vois à l'écran !!!

En conséquence mon rectangle semble se déporter au lieu d'avancer dans la bonne direction...

J'ai vérifié et revérifié, je ne trouve pas. Quelqu'un aurait-il une idée ?

PS bravo pour le nouveau site perso. Je ne sais plus à qui je dois dire bravo (désolé), je commence à peine à reconnaître les figures de ce forum.
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptySam 16 Mar 2013 - 14:57

Bonjour, je pourrais jeter un oeil, mais peux-tu poster ton code complet entre les borne [ code ] et [ /code ]
Revenir en haut Aller en bas
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Voici le code complet   Ca tourne mais ça n'avance pas bien EmptySam 16 Mar 2013 - 15:03

Avec joie !!!

Code:


caption 0, "TANK move ESC pour arrêter !!!"
rem 320 240
'
rem ===============
rem LABELs de Cadix
rem ===============
'
    LABEL ROTA, TRACER,TRANS
'
' Affichage des éléments
'
top  0,(screen_y-height(0))/2
left 0,(screen_x-width(0))/2
'
picture 1:full_space 1:2d_target_is 1
color 1,50,130,13
'
' Dimensions du rectangle
'
dim LargRect%,HautRect%
    LargRect%=64:HautRect%=32
'
' Calcul du centre de la fenêtre
'
dim xc,yc
    xc=int(width(1)/2)
    yc=int(height(1)/2)
'
' On place les 4 coins du rectangle
'
dim xhd,xhg,xbg,xbd
dim yhd,yhg,ybg,ybd
'
xhd=xc+int(LargRect%/2)
yhd=yc-int(HautRect%/2)
xhg=xc-int(LargRect%/2)
yhg=yc-int(HautRect%/2)
xbg=xhg
ybg=yc+int(HautRect%/2)
xbd=xhd
ybd=ybg
'
' On trace le rectangle initial
'
2d_line xhd,yhd,xhg,yhg
2d_line xhg,yhg,xbg,ybg
2d_line xbg,ybg,xbd,ybd
2d_line xbd,ybd,xhd,yhd
'
' DIMs pour les calculs liés à la ROTAtion
'
dim x1,y1,x2,y2,x3,y3,x4,y4
rem ce sont les xhd, yhd etc. transformés par ROTAtion
dim xx1,yy1,xx2,yy2,xx3,yy3,xx4,yy4
rem ce sont les coordonnées transitoires
dim mathg,mathd,matbg,matbd
rem ce sont les coordonnées de la matrice, Néo !
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4
rem ce sont les coordonnées pour effacement
'
' DIMs translation
'
dim Pas
    Pas=0
'
' On prépare l'effacement du rectangle
'
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd
oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
'
' Angle en degrés converti en radians
'
dim Ang,pi:pi= 4* ATN(1)
Ang=0
dim Angrad
rem c'est l'angle converti en radians
rem Angrad=Ang * pi/180
'
' DIMs pour saisie des commandes
'
dim Tourne%,Avance%
rem c'est un flag !
'
rem ====================
rem SAISIE des COMMANDES
rem ====================
'
    REPEAT
'
if scancode=37 then Ang=Ang-5:Tourne%=1
if scancode=39 then Ang=Ang+5:Tourne%=1
if scancode=38 then Pas=Pas+5:Avance%=1
if scancode=40 then Pas=Pas-5:Avance%=1
'
Ang=mod(Ang,360)
Angrad=Ang * pi/180
print_locate 10,10:print str$(Ang)
'
if Tourne%=1 then GOSUB ROTA : GOSUB TRACER
if Avance%=1 then GOSUB TRANS: GOSUB TRACER
'
    UNTIL scancode=27

'
' FIN des préliminaires
'
  END
'
' Tout droit
'
  TRANS:
'
xc= xc +Pas*cos(Angrad):yc= yc +Pas*sin(Angrad)
xhd=xhd+Pas*cos(Angrad):yhd=yhd+Pas*sin(Angrad)
xhg=xhg+Pas*cos(Angrad):yhg=yhg+Pas*sin(Angrad)
xbg=xbg+Pas*cos(Angrad):ybg=ybg+Pas*sin(Angrad)
xbd=xbd+Pas*cos(Angrad):ybd=ybd+Pas*sin(Angrad)
'
' Remise du flag à FAUX
'
  Avance%=0
'
  RETURN
'
' Silence on tourne
'
  ROTA:
'
mathg=cos(Angrad)
mathd=sin(Angrad)
matbg=0-sin(Angrad)
matbd=cos(Angrad)
'
xx1=xhd-xc :xx2=xhg-xc :xx3=xbg-xc :xx4=xbd-xc
yy1=yhd-yc :yy2=yhg-yc :yy3=ybg-yc :yy4=ybd-yc
'
' Calcul matriciel
'
xhd=(mathg*xx1)+(matbg*yy1):yhd=(mathd*xx1)+(matbd*yy1)
xhg=(mathg*xx2)+(matbg*yy2):yhg=(mathd*xx2)+(matbd*yy2)
xbg=(mathg*xx3)+(matbg*yy3):ybg=(mathd*xx3)+(matbd*yy3)
xbd=(mathg*xx4)+(matbg*yy4):ybd=(mathd*xx4)+(matbd*yy4)

xhd=xhd+xc :xhg=xhg+xc :xbg=xbg+xc :xbd=xbd+xc
yhd=yhd+yc :yhg=yhg+yc :ybg=ybg+yc :ybd=ybd+yc
'
' Remise du flag à FAUX
  Tourne%=0
'
  RETURN

'
  TRACER:
'
' Tracé du nouveau tank
'
' Tempo
'
wait 100
rem Changer cette valeur pour une ROTAtion +- fluide
'
2d_line xhd,yhd,xhg,yhg
2d_line xhg,yhg,xbg,ybg
2d_line xbg,ybg,xbd,ybd
2d_line xbd,ybd,xhd,yhd
'
' Effacement de l'ancien tank
'
rem wait 1000
2d_pen_color 50,130,13
2d_line oldx1,oldy1,oldx2,oldy2
2d_line oldx2,oldy2,oldx3,oldy3
2d_line oldx3,oldy3,oldx4,oldy4
2d_line oldx4,oldy4,oldx1,oldy1
2d_pen_color 0,0,0
'
' Affecter ces coordonnées aux coord d'effacement
'
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd
oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
'
rem xp = A * x(1) + C * y(1) : yp = B * x(1) + D * y(1)
'
  RETURN
'
  END



Wink Voilà voila...
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyLun 25 Mar 2013 - 13:34

Je suis au boulot, je ne peut pas tester, mais je le ferais ce soir.
J'ai remarqué plusieurs problèmes:
1: tu ne mets pas à jour xc,yc quand tu déplaces ton tank. Tu as donc forcément un problème puisque tu déplace ton tank mais que tu gardes le centre au centre de l'écran.

Après j'ai d'autres idées, mais je les mettrais quand je pourrais tester ce soir.
Revenir en haut Aller en bas
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyLun 25 Mar 2013 - 23:36

Bon, je ne suis pas fort en math, donc 2 constats:
La formule utilisée pour avancer n'est pas bonne (je compte sur les matheux pour donner la bonne formule) (Formule de trans() )
A cause des arrondis, la taille du char diminue en tournant, j'ai mis une petite bidouille pour redimensionner le char pour éviter qu'il ne rétressisse trop. Tu peux faire la même chose pour quand le char est tourné à 90° de sorte que la remise à la bonne taille se voye moins
Code:
' ********************************************************************************
'                Tanks v1.1 by Froggy One & Jicehel
' ********************************************************************************
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC" ==> MET FIN AU PROGRAMME:.... CASE 27  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE ==> PIVOTER À GAUCHE:....... CASE 37  *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE ==> AVANCER:................. CASE 38  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE ==> PIVOTER À DROITE:....... CASE 39  *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE ==> RECULER:................. CASE 40  *
' ********************************************************************************

' déclaration des étiquettes pour gérer les événements
label t1,t2

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd

xhd=xc+(LargRect%/2): yhd=yc-(HautRect%/2)
xhg=xc-(LargRect%/2): yhg=yc-(HautRect%/2)
xbg=xhg : ybg=yc+(HautRect%/2)
xbd=xhd : ybd=ybg


' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien triangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 1

' Angle en radians
dim Angrad

Trace_rectangle()
on_key_down 0,t1
on_key_up 0,t2

end

sub Trace_rectangle()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhd-xc))+((0-sin(Angrad))*(yhd-yc))+xc
  yhd=(sin(Angrad)*(xhd-xc))+(cos(Angrad)*(yhd-yc))+yc
  xhg=(cos(Angrad)*(xhg-xc))+((0-sin(Angrad))*(yhg-yc))+xc
  yhg=(sin(Angrad)*(xhg-xc))+(cos(Angrad)*(yhg-yc))+yc
  xbg=(cos(Angrad)*(xbg-xc))+((0-sin(Angrad))*(ybg-yc))+xc
  ybg=(sin(Angrad)*(xbg-xc))+(cos(Angrad)*(ybg-yc))+yc
  xbd=(cos(Angrad)*(xbd-xc))+((0-sin(Angrad))*(ybd-yc))+xc
  ybd=(sin(Angrad)*(xbd-xc))+(cos(Angrad)*(ybd-yc))+yc
  if (int(xhd) = int(xbd+0.4)) or (int(xhd+0.4) = int(xbd))
    if xhd > xhg
      xhd=xc+(LargRect%/2): yhd=yc-(HautRect%/2)
      xhg=xc-(LargRect%/2): yhg=yhd
      xbg=xhg : ybg=yc+(HautRect%/2)
      xbd=xhd : ybd=ybg
    else
      xbg=xc+(LargRect%/2): ybg=yc-(HautRect%/2)
      xhd=xc-(LargRect%/2): yhd=yc+(HautRect%/2)
      xhg=xbg : yhg=yhd
      xbd=xhd : ybd=ybg
    end_if
  end_if
  xc=(xhd+xbg)/2 : yc=(yhd+ybg)/2
  Angrad = 0
End_Sub

sub trans()
  xhd=xhd+Pas*cos(Angrad):yhd=yhd+Pas*sin(Angrad)
  xhg=xhg+Pas*cos(Angrad):yhg=yhg+Pas*sin(Angrad)
  xbg=xbg+Pas*cos(Angrad):ybg=ybg+Pas*sin(Angrad)
  xbd=xbd+Pas*cos(Angrad):ybd=ybd+Pas*sin(Angrad)
  xc=(xhd+xbg)/2 : yc=(yhd+ybg)/2
  pas = 0
end_sub


t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
return

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20 : Tourne()
  if tfd=1 then Angrad=Angrad + pi/20 : Tourne()
  if tfh=1 then Pas=Pas+3 : trans()
  if tfb=1 then Pas=Pas-3 : trans()
  Trace_rectangle()
end_sub
Revenir en haut Aller en bas
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 11:13

J'ai réfléchi dans le métro, je poste le code pour moi comme pense bête pour ce soir (pas testé, je ne peux pas au boulot ...)
Code:
' ********************************************************************************
'                Tanks v1.1 by Froggy One & Jicehel
' ********************************************************************************
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC" ==> MET FIN AU PROGRAMME:.... CASE 27  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE ==> PIVOTER À GAUCHE:....... CASE 37  *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE ==> AVANCER:................. CASE 38  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE ==> PIVOTER À DROITE:....... CASE 39  *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE ==> RECULER:................. CASE 40  *
' ********************************************************************************

' déclaration des étiquettes pour gérer les événements
label t1,t2

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd
dim xhdi,xhgi,xbgi,xbdi,yhdi,yhgi,ybgi,iybd


xhdi=LargRect%/2: yhdi=0-(HautRect%/2)
xhgi=0-(LargRect%/2): yhgi=yhdi
xbgi=xhgi : ybgi=HautRect%/2
xbdi=xhdi : ybdi=ybgi

xhd=xc+xhdi : yhd=yc+yhdi
xhg=xc+xhgi : yhg=yc+yhgi
xbg=xc+xbgi : ybg=yc+ybgi
xbd=xc+xbdi : ybd=yc+ybdi

' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien triangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 1

' Angle en radians
dim Angrad

Trace_rectangle()
on_key_down 0,t1
on_key_up 0,t2

end

sub Trace_rectangle()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhdi))+((0-sin(Angrad))*yhdi)+xc
  yhd=(sin(Angrad)*(xhdi))+(cos(Angrad)*yhdi)+yc
  xhg=(cos(Angrad)*(xhgi))+((0-sin(Angrad))*(yhgi))+xc
  yhg=(sin(Angrad)*(xhgi))+(cos(Angrad)*yhgi)+yc
  xbg=(cos(Angrad)*(xbgi))+((0-sin(Angrad))*ybg))+xc
  ybg=(sin(Angrad)*(xbgi))+(cos(Angrad)*ybgi)+yc
  xbd=(cos(Angrad)*(xbdi))+((0-sin(Angrad))*(ybdi)+xc
  ybd=(sin(Angrad)*(xbdi))+(cos(Angrad)*(ybdi)+yc
End_Sub

sub trans()
  DIM_LOCAL delta_x,delta_y
  delta_x=Pas*cos(Angrad):delta_y=Pas*sin(Angrad)
  xhd=xhd+delta_x:yhd=yhd+delta_y
  xhg=xhg+delta_x:yhg=yhg+delta_y
  xbg=xbg+delta_x:ybg=ybg+delta_y
  xbd=xbd+delta_x:ybd=ybd+delta_y
  xc=xc+delta_x:yc=yc+delta_y
end_sub


t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
return

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20 : Tourne()
  if tfd=1 then Angrad=Angrad + pi/20 : Tourne()
  if tfh=1 then Pas=Pas+3 : trans()
  if tfb=1 then Pas=Pas-3 : trans()
  Trace_rectangle()
end_sub
Revenir en haut Aller en bas
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 13:54

Waow ! T(h)ank you JCL !

Je me suis permis de corriger un "i" manquant ligne 30 et quelques parenthèses qui trainaient en 82-84 mais en tous cas ça avance beaucoup mieux ! de plus les parenthèses, je trouve ça très élégant. Il reste un effet de freinage auquel je m'attaquerai bientôt (boulot boulot !)
Je te recopie le code. A + et merci encore !
Code:

********************************************************************************
'                Tanks v1.1 by Froggy One & Jicehel
' ********************************************************************************
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC" ==> MET FIN AU PROGRAMME:.... CASE 27  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE ==> PIVOTER À GAUCHE:....... CASE 37  *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE ==> AVANCER:................. CASE 38  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE ==> PIVOTER À DROITE:....... CASE 39  *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE ==> RECULER:................. CASE 40  *
' ********************************************************************************

' déclaration des étiquettes pour gérer les événements
label t1,t2

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd
dim xhdi,xhgi,xbgi,xbdi,yhdi,yhgi,ybgi,ybdi


xhdi=LargRect%/2: yhdi=0-(HautRect%/2)
xhgi=0-(LargRect%/2): yhgi=yhdi
xbgi=xhgi : ybgi=HautRect%/2
xbdi=xhdi : ybdi=ybgi

xhd=xc+xhdi : yhd=yc+yhdi
xhg=xc+xhgi : yhg=yc+yhgi
xbg=xc+xbgi : ybg=yc+ybgi
xbd=xc+xbdi : ybd=yc+ybdi

' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien rectangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 1

' Angle en radians
dim Angrad

Trace_rectangle()
on_key_down 0,t1
on_key_up 0,t2

end

sub Trace_rectangle()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhdi))+((0-sin(Angrad))*yhdi)+xc
  yhd=(sin(Angrad)*(xhdi))+(cos(Angrad)*yhdi)+yc
  xhg=(cos(Angrad)*(xhgi))+((0-sin(Angrad))*(yhgi))+xc
  yhg=(sin(Angrad)*(xhgi))+(cos(Angrad)*yhgi)+yc
  xbg=(cos(Angrad)*(xbgi))+((0-sin(Angrad))*ybgi)+xc
  ybg=(sin(Angrad)*(xbgi))+(cos(Angrad)*ybgi)+yc
  xbd=(cos(Angrad)*(xbdi))+((0-sin(Angrad))*ybdi)+xc
  ybd=(sin(Angrad)*(xbdi))+(cos(Angrad)*ybdi)+yc
End_Sub

sub trans()
  DIM_LOCAL delta_x,delta_y
  delta_x=Pas*cos(Angrad):delta_y=Pas*sin(Angrad)
  xhd=xhd+delta_x:yhd=yhd+delta_y
  xhg=xhg+delta_x:yhg=yhg+delta_y
  xbg=xbg+delta_x:ybg=ybg+delta_y
  xbd=xbd+delta_x:ybd=ybd+delta_y
  xc=xc+delta_x:yc=yc+delta_y
end_sub


t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
return

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20 : Tourne()
  if tfd=1 then Angrad=Angrad + pi/20 : Tourne()
  if tfh=1 then Pas=Pas+3 : trans()
  if tfb=1 then Pas=Pas-3 : trans()
  Trace_rectangle()
end_sub
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 14:13

Voilà, j'ai trouvé :

en 120-121, il faut limiter le pas avec Arrow

Code:


if tfh=1 then Pas=min(3,Pas+3) : trans()
if tfb=1 then Pas=max(3,Pas-3) : trans()


Youpi !!!

Et re-re-merci Exclamation
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 15:04

Pas de quoi. Bon maintenant tu fait la tourelle mobile du tank (même principe avec un angle en plus à gérer) ^^
Tu désinnes un cercle au centre du tank et tu fait tourner un trait épais pour le canon autour du cercle ...

J'ai hâte de voir ce que ton jeu va donner Wink
Revenir en haut Aller en bas
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ça tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 17:43

On progresse... maintenant on a une tourelle fixe, un tank qui démarre et qui s'arrête sur un coup de barre... comme moi !
Code:

' ************************************************* '
'                Tanks v1.1 by Froggy One & Jicehel '
' ************************************************* '
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC"  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE  *
dim ztp,ztop : ztop=32 : ' *    BARRE    *
' ****************************************

' Déclaration des étiquettes pour gérer les événements
label t1,t2,boucle

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd
dim xhdi,xhgi,xbgi,xbdi,yhdi,yhgi,ybgi,ybdi


xhdi=LargRect%/2: yhdi=0-(HautRect%/2)
xhgi=0-(LargRect%/2): yhgi=yhdi
xbgi=xhgi : ybgi=HautRect%/2
xbdi=xhdi : ybdi=ybgi

xhd=xc+xhdi : yhd=yc+yhdi
xhg=xc+xhgi : yhg=yc+yhgi
xbg=xc+xbgi : ybg=yc+ybgi
xbd=xc+xbdi : ybd=yc+ybdi

' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien rectangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 1

' Angle en radians
dim Angrad

' Tourelle
dim oldxc,oldyc,cibx,ciby

' Compteur

  TIMER 9 : timer_interval 9,250

' The PROGRAMME

  Trace_rectangle()
  Trace_tourelle()
  on_key_down 0,t1
  on_key_up  0,t2
  on_timer 9,boucle
 
end

sub Trace_rectangle()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd
end_sub

sub Trace_tourelle()
  2d_fill_color 50,130,13
 
  ' On efface l'ancienne tourelle
  2d_pen_color 50,130,13
  2d_circle oldxc,oldyc,(HautRect%/2)-2
  2d_line oldxc,oldyc,oldxc+4*cos(Angrad),oldyc+4*sin(Angrad)
 
  ' On affiche la nouvelle
  2d_pen_color 0,0,0
  2d_circle xc,yc,(HautRect%/2)-2
  2d_line xc,yc,xc+((HautRect%/2)-2)*cos(Angrad),yc+((HautRect%/2)-2)*sin(Angrad)
  oldxc=xc:oldyc=yc
 
end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhdi))+((0-sin(Angrad))*yhdi)+xc
  yhd=(sin(Angrad)*(xhdi))+(cos(Angrad)*yhdi)+yc
  xhg=(cos(Angrad)*(xhgi))+((0-sin(Angrad))*(yhgi))+xc
  yhg=(sin(Angrad)*(xhgi))+(cos(Angrad)*yhgi)+yc
  xbg=(cos(Angrad)*(xbgi))+((0-sin(Angrad))*ybgi)+xc
  ybg=(sin(Angrad)*(xbgi))+(cos(Angrad)*ybgi)+yc
  xbd=(cos(Angrad)*(xbdi))+((0-sin(Angrad))*ybdi)+xc
  ybd=(sin(Angrad)*(xbdi))+(cos(Angrad)*ybdi)+yc
End_Sub

sub trans()
  DIM_LOCAL delta_x,delta_y
  delta_x=Pas*cos(Angrad):delta_y=Pas*sin(Angrad)
  xhd=xhd+delta_x:yhd=yhd+delta_y
  xhg=xhg+delta_x:yhg=yhg+delta_y
  xbg=xbg+delta_x:ybg=ybg+delta_y
  xbd=xbd+delta_x:ybd=ybd+delta_y
  xc=xc+delta_x:yc=yc+delta_y
end_sub

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20 : Tourne()
  if tfd=1 then Angrad=Angrad + pi/20 : Tourne()
  if tfh=1 then Pas= 3  : trans()
  if tfb=1 then Pas=-3  : trans()
  if ztp=1 then Pas=0    : trans()
  Trace_rectangle()
  Trace_tourelle()
end_sub

t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  if key_down_code=ztop then ztp=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
  if key_down_code=ztop then ztp=0
return

boucle:
      bouge()
      tourne()
      trans()
        if mouse_right_down(1)=1
        cibx=mouse_x_position(1)
        ciby=mouse_y_position(1)
        end_if
return

Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Jicehel

Jicehel


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

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMar 26 Mar 2013 - 20:42

Je t'ai modifié un peu le source
Code:
' ************************************************* '
'                Tanks v1.2 by Froggy One & Jicehel '
' ************************************************* '
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC"  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE  *
dim ztp,ztop : ztop=32 : ' *    BARRE    *
' ****************************************

' Déclaration des étiquettes pour gérer les événements
label t1,t2,boucle

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd
dim xhdi,xhgi,xbgi,xbdi,yhdi,yhgi,ybgi,ybdi


xhdi=LargRect%/2: yhdi=0-(HautRect%/2)
xhgi=0-(LargRect%/2): yhgi=yhdi
xbgi=xhgi : ybgi=HautRect%/2
xbdi=xhdi : ybdi=ybgi

xhd=xc+xhdi : yhd=yc+yhdi
xhg=xc+xhgi : yhg=yc+yhgi
xbg=xc+xbgi : ybg=yc+ybgi
xbd=xc+xbdi : ybd=yc+ybdi

' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien rectangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 0

' Angle en radians
dim Angrad

' Tourelle
dim oldxc,oldyc,cibx,ciby,OldAngrad

' Compteur

  TIMER 9 : timer_interval 9,150

' The PROGRAMME

  on_key_down 0,t1
  on_key_up  0,t2
  on_timer 9,boucle

end

sub Trace_Tank()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13 : 2D_fill_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On efface l'ancienne tourelle
  2d_circle oldxc,oldyc,(HautRect%/2)-2 : 2d_pen_width 3
  2d_line oldxc+((HautRect%/2)-2)*cos(OldAngrad),oldyc+((HautRect%/2)-2)*sin(OldAngrad),oldxc+1.5*HautRect%*cos(OldAngrad),oldyc+1.5*HautRect%*sin(OldAngrad)
  2d_pen_width 1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0  : 2D_fill_color 200,200,200
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On affiche la nouvelle tourelle
  2d_circle xc,yc,(HautRect%/2)-2 : 2d_pen_width 3
  2d_line xc+((HautRect%/2)-2)*cos(Angrad),yc+((HautRect%/2)-2)*sin(Angrad),xc+1.5*HautRect%*cos(Angrad),yc+1.5*HautRect%*sin(Angrad)
  oldxc=xc:oldyc=yc:oldAngrad=Angrad : 2d_pen_width 1

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhdi))+((0-sin(Angrad))*yhdi)+xc
  yhd=(sin(Angrad)*(xhdi))+(cos(Angrad)*yhdi)+yc
  xhg=(cos(Angrad)*(xhgi))+((0-sin(Angrad))*(yhgi))+xc
  yhg=(sin(Angrad)*(xhgi))+(cos(Angrad)*yhgi)+yc
  xbg=(cos(Angrad)*(xbgi))+((0-sin(Angrad))*ybgi)+xc
  ybg=(sin(Angrad)*(xbgi))+(cos(Angrad)*ybgi)+yc
  xbd=(cos(Angrad)*(xbdi))+((0-sin(Angrad))*ybdi)+xc
  ybd=(sin(Angrad)*(xbdi))+(cos(Angrad)*ybdi)+yc
End_Sub

sub trans()
  DIM_LOCAL delta_x,delta_y
  delta_x=Pas*cos(Angrad):delta_y=Pas*sin(Angrad)
  xhd=xhd+delta_x:yhd=yhd+delta_y
  xhg=xhg+delta_x:yhg=yhg+delta_y
  xbg=xbg+delta_x:ybg=ybg+delta_y
  xbd=xbd+delta_x:ybd=ybd+delta_y
  xc=xc+delta_x:yc=yc+delta_y
end_sub

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20
  if tfd=1 then Angrad=Angrad + pi/20
  if tfh=1 then Pas= 5
  if tfb=1 then Pas=-5
  if ztp=1 then Pas=0
end_sub

t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  if key_down_code=ztop then ztp=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
  if key_down_code=ztop then ztp=0
return

boucle:
      bouge()
      tourne()
      trans()
      Trace_tank()
      if mouse_right_down(1)=1
        cibx=mouse_x_position(1)
        ciby=mouse_y_position(1)
        caption 0,"TANK move ESC pour arrêter !!!  - Cible ("+str$(cibx)+";"+str$(ciby)+")"
      end_if
return
Revenir en haut Aller en bas
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien    Ca tourne mais ça n'avance pas bien EmptyMer 27 Mar 2013 - 7:12

Sleep JE VOUDRAIS y regarder... mais PANORAMIC ne veut plus tourner !!!! à suivre...
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyMer 27 Mar 2013 - 7:46

Il suffisait de redémarrer ! Ne t'étonne pas si je fais une pause, j'ai des rhododendrons à replanter !!! Razz très jolie, la tourelle. A +
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyJeu 28 Mar 2013 - 16:56

bounce Vite fait, la tourelle sait maintenant viser :

Code:


' ************************************************* '
'                Tanks v1.2 by Froggy One & Jicehel '
' ************************************************* '
dim esc,cesc : cesc=27 : ' * TOUCHE "ESC"  *
dim tfg,ctfg : ctfg=37 : ' * FLÈCHE GAUCHE *
dim tfh,ctfh : ctfh=38 : ' * FLÈCHE HAUTE  *
dim tfd,ctfd : ctfd=39 : ' * FLÈCHE DROITE *
dim tfb,ctfb : ctfb=40 : ' * FLÈCHE BASSE  *
dim ztp,ztop : ztop=32 : ' *    BARRE    *
' ****************************************

' Déclaration des étiquettes pour gérer les événements
label t1,t2,boucle

' Initialisation de la fenêtre principale
caption 0, "TANK move ESC pour arrêter !!!"
top  0,(screen_y-height(0))/2 : left 0,(screen_x-width(0))/2
' Initialisation de la surface de jeu
picture 1:full_space 1:2d_target_is 1: color 1,50,130,13

' Déclaration des constantes
dim pi:pi= 4* ATN(1)

' Dimensions du rectangle
dim LargRect%,HautRect% :  LargRect%=64:HautRect%=32
' Centre du rectangle et initialisation au centre de l'écran
dim xc,yc :  xc=int(width(1)/2):  yc=int(height(1)/2)

' Déclaration et initialisation des quatres coins du rectangle
dim xhd,xhg,xbg,xbd,yhd,yhg,ybg,ybd
dim xhdi,xhgi,xbgi,xbdi,yhdi,yhgi,ybgi,ybdi


xhdi=LargRect%/2: yhdi=0-(HautRect%/2)
xhgi=0-(LargRect%/2): yhgi=yhdi
xbgi=xhgi : ybgi=HautRect%/2
xbdi=xhdi : ybdi=ybgi

xhd=xc+xhdi : yhd=yc+yhdi
xhg=xc+xhgi : yhg=yc+yhgi
xbg=xc+xbgi : ybg=yc+ybgi
xbd=xc+xbdi : ybd=yc+ybdi

' Déclaration des variables permettant de stocker les coordonnées pour effacement
dim oldx1,oldx2,oldx3,oldx4,oldy1,oldy2,oldy3,oldy4

' On initialise les valeurs de l'ancien rectangle fictif
oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

' Déclaration de la vitesse de déplacement
dim pas : pas = 0

' Angle en radians
dim Angrad

' Tourelle
dim oldxc,oldyc,cibx,ciby,OldAngrad,AngTir,grandx,grandy,hypo
dim CosAngTir,SinAngTir
    CosAngTir=1:SinAngTir=0
dim OldCosAngTir,OldSinAngTir

' Compteur

  TIMER 9 : timer_interval 9,150

' The PROGRAMME

  on_key_down 0,t1
  on_key_up  0,t2
  on_timer 9,boucle

end

sub Trace_Tank()

  ' On efface les 4 côtés de l'ancien rectangle
  2d_pen_color 50,130,13 : 2D_fill_color 50,130,13
  2d_line oldx1,oldy1,oldx2,oldy2 : 2d_line oldx2,oldy2,oldx3,oldy3
  2d_line oldx3,oldy3,oldx4,oldy4 : 2d_line oldx4,oldy4,oldx1,oldy1

  ' On efface l'ancienne tourelle
  2d_circle oldxc,oldyc,(HautRect%/2)-2 : 2d_pen_width 2 : rem 3
  rem 2d_line oldxc+((HautRect%/2)-2)*cos(OldAngrad),oldyc+((HautRect%/2)-2)*sin(OldAngrad),oldxc+1.5*HautRect%*cos(OldAngrad),oldyc+1.5*HautRect%*sin(OldAngrad)
  2d_line oldxc+((HautRect%/2)-2)*OldCosAngTir,  oldyc+((HautRect%/2)-2)*OldSinAngTir,  oldxc+1.5*HautRect%*OldCosAngTir,  oldyc+1.5*HautRect%*OldSinAngTir
  2d_pen_width 1

  ' On trace les 4 côtés du nouveau rectangle
  2d_pen_color 0,0,0  : 2D_fill_color 50,130,13: rem 200,200,200
  2d_line xhd,yhd,xhg,yhg: 2d_line xhg,yhg,xbg,ybg
  2d_line xbg,ybg,xbd,ybd: 2d_line xbd,ybd,xhd,yhd

  ' On affiche la nouvelle tourelle
  2d_circle xc,yc,(HautRect%/2)-2 : 2d_pen_width 2 : rem 3
  rem 2d_line xc+((HautRect%/2)-2)*cos(Angrad),yc+((HautRect%/2)-2)*sin(Angrad),xc+1.5*HautRect%*cos(Angrad),yc+1.5*HautRect%*sin(Angrad)
  2d_line xc+((HautRect%/2)-2)*CosAngTir,  yc+((HautRect%/2)-2)*SinAngTir,  xc+1.5*HautRect%*CosAngTir,  yc+1.5*HautRect%*SinAngTir

  ' on mémorise les coordonnées pour effacer la tourelle next time

  OldCosAngTir=CosAngTir:OldSinAngTir=SinAngTir
  oldxc=xc:oldyc=yc:oldAngrad=Angrad : 2d_pen_width 1

  ' On mémorise les coordonnées pour effacer le rectangle la prochaine fois
  oldx1=xhd:oldx2=xhg:oldx3=xbg:oldx4=xbd: oldy1=yhd:oldy2=yhg:oldy3=ybg:oldy4=ybd

end_sub

Sub Tourne()
  xhd=(cos(Angrad)*(xhdi))+((0-sin(Angrad))*yhdi)+xc
  yhd=(sin(Angrad)*(xhdi))+(cos(Angrad)*yhdi)+yc
  xhg=(cos(Angrad)*(xhgi))+((0-sin(Angrad))*(yhgi))+xc
  yhg=(sin(Angrad)*(xhgi))+(cos(Angrad)*yhgi)+yc
  xbg=(cos(Angrad)*(xbgi))+((0-sin(Angrad))*ybgi)+xc
  ybg=(sin(Angrad)*(xbgi))+(cos(Angrad)*ybgi)+yc
  xbd=(cos(Angrad)*(xbdi))+((0-sin(Angrad))*ybdi)+xc
  ybd=(sin(Angrad)*(xbdi))+(cos(Angrad)*ybdi)+yc
End_Sub

sub trans()
  DIM_LOCAL delta_x,delta_y
  delta_x=Pas*cos(Angrad):delta_y=Pas*sin(Angrad)
  xhd=xhd+delta_x:yhd=yhd+delta_y
  xhg=xhg+delta_x:yhg=yhg+delta_y
  xbg=xbg+delta_x:ybg=ybg+delta_y
  xbd=xbd+delta_x:ybd=ybd+delta_y
  xc=xc+delta_x:yc=yc+delta_y
end_sub

sub bouge()
  if esc=1 then terminate
  if tfg=1 then Angrad=Angrad - pi/20
  if tfd=1 then Angrad=Angrad + pi/20
  if tfh=1 then Pas= 5
  if tfb=1 then Pas=-5
  if ztp=1 then Pas=0
end_sub

sub vise()
  if mouse_right_down(1)=1
        cibx=mouse_x_position(1)
        ciby=mouse_y_position(1)
        grandx=(cibx-xc)
        grandy=(ciby-yc)
        hypo=sqr((grandx*grandx)+(grandy*grandy))
        CosAngTir=grandx/hypo
        SinAngTir=grandy/hypo
        caption 0,"TANK move ESC pour arrêter !!!  - Cible ("+str$(cibx)+";"+str$(ciby)+")"
  end_if
end_sub

t1:
  if key_down_code=cesc then esc=1
  if key_down_code=ctfg then tfg=1
  if key_down_code=ctfh then tfh=1
  if key_down_code=ctfd then tfd=1
  if key_down_code=ctfb then tfb=1
  if key_down_code=ztop then ztp=1
  bouge()
return

t2:
  if key_down_code=cesc then esc=0
  if key_down_code=ctfg then tfg=0
  if key_down_code=ctfh then tfh=0
  if key_down_code=ctfd then tfd=0
  if key_down_code=ctfb then tfb=0
  if key_down_code=ztop then ztp=0
return

boucle:
      bouge()
      vise()
      tourne()
      trans()
      Trace_tank()

return

Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Yannick




Nombre de messages : 8610
Age : 52
Localisation : Bretagne
Date d'inscription : 15/02/2010

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: re   Ca tourne mais ça n'avance pas bien EmptyJeu 28 Mar 2013 - 16:57

Tient, cela peut être pratique çà...
...pour un char . Laughing
Revenir en haut Aller en bas
JL35




Nombre de messages : 7095
Localisation : 77
Date d'inscription : 29/11/2007

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien EmptyJeu 28 Mar 2013 - 17:25

Parles-en à Ben Hur Very Happy
Revenir en haut Aller en bas
Froggy One

Froggy One


Nombre de messages : 584
Date d'inscription : 06/01/2012

Ca tourne mais ça n'avance pas bien Empty
MessageSujet: arrête ton char   Ca tourne mais ça n'avance pas bien EmptyVen 29 Mar 2013 - 9:09

@ygeronimi
@JL35

Wink Vous char-riez !!!
Revenir en haut Aller en bas
http://gaeldwest.wordpress.com
Contenu sponsorisé





Ca tourne mais ça n'avance pas bien Empty
MessageSujet: Re: Ca tourne mais ça n'avance pas bien   Ca tourne mais ça n'avance pas bien Empty

Revenir en haut Aller en bas
 
Ca tourne mais ça n'avance pas bien
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» Rien d’intéressant mais ça tourne !
» On_Sprite_Click N,L
» Comment terminer une saisie dans un objet par entrée
» silence,on tourne
» Les commandes

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC :: PANORAMIC :: A l'aide!-
Sauter vers: