Page 1 sur 1

Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 16:37
de critor
Dans plusieurs articles précédents, nous avons exploré les possibilités et la compatibilité des solutions Python sur calculatrices, autour d'une animation de radar à balayage.

Une animation initialement codée par Dark Storm pour Casio Graph 90+E dans le contexte du concours de démo graphiques Python sur Planète Casio.

12549Une animation qui a beaucoup inspiré marcel_p82.

C'est tout un jeu que ce dernier a construit autour de l'animation pour TI-Nspire CX II.

Dans ce jeu baptisé Sonar, tu es donc officier radar sur un sous-marin, et te dois de couler la flotte ennemie. Il te suffira de taper
t
pour tirer une torpille après avoir saisi l'angle de tir. Mais attention, il s'agit donc ici d'un radar à balayage, qui ne te reporte la position exacte de l'ennemi qu'une fois par rotation. Et bien évidemment, dans l'intervalle, ta cible continue à bouger la coquine... :bat:

Le jeu utilise les nouvelles possibilités graphiques introduites dans le langage interprété historique TI-Basic à compter de la version 5.0, et donc exclusivement sur les TI-Nspire CX II puisque les anciens modèles ne sont plus mis à jour.

Des performances a priori représentatives de ce que tu pourras bientôt obtenir avec le module graphique Python ti_draw dans la prochaine mise à jour TI-Nspire CX II.

Qu'en penses-tu ? ;)

Téléchargement : archives_voir.php?id=2621104

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 16:43
de grosged
C'est vraiment pas mal pour du TI-Basic !

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 17:12
de Shadow15510
Je n'ai pas de TI, mais j'aimerais tenter un portage du programme vers le Python (Graph 90+E / Numworks). :P Existe-t-il un moyen de lire le programme ?

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 17:18
de Hamza.S
Il faut un logiciel Nspire CX student/teacher (idéal version 5.x) sinon quelqu'un peut coller le code

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 17:18
de critor
Avec le logiciel TI-Nspire, tu peux éditer le programme : archives_voir.php?id=2618237

Sinon voici le code source ci-dessous.

Mais sans instruction getkey() dans le Python de Casio, tu risques d'avoir du mal... :'(

Code: Tout sélectionner
Define LibPub sonar()=
Prgm
:©Ordre de détruire le sous-marin ennemi.
:Define ini_window()=Prgm
:  SetColor 0,0,0
:  Clear
:  FillRect 0,0,318,212
:  SetWindow 0,318,0,212
:EndPrgm
:Define ini_sonar()=Prgm
:  xcentre:=154:ycentre:=106:rayon:=100
:  SetColor 0,255,0
:  DrawCircle xcentre,ycentre,rayon
:  DrawText 225,177,"45°"
:  DrawText 60,177,"135°"
:  DrawText 55,25,"225°"
:  DrawText 230,25,"315°"
:  DrawText 256,91,"4 km"
:  DrawText 1,1,"θ:"
:  DrawText 235,1,"Dist.:"
:  DrawText 241,198,"esc: Quitter"
:  DrawText 258,187,"t: Torpille"
:EndPrgm
:Define dessine_sonar()=Prgm
:  SetColor 0,255,0
:  DrawCircle xcentre,ycentre,rayon
:  DrawCircle xcentre,ycentre,rayon*((3)/(4))
:  DrawCircle xcentre,ycentre,rayon*((1)/(2))
:  DrawCircle xcentre,ycentre,rayon*((1)/(4))
:  DrawLine xcentre-rayon,ycentre,xcentre+rayon,ycentre
:  DrawLine xcentre,ycentre+rayon,xcentre,ycentre-rayon
:  SetPen 1,3
:  SetColor 0,180,0
:  DrawLine xcentre,ycentre,xcentre+71,ycentre+71
:  DrawLine xcentre,ycentre,xcentre-71,ycentre+71
:  DrawLine xcentre,ycentre,xcentre-71,ycentre-71
:  DrawLine xcentre,ycentre,xcentre+71,ycentre-71
:  SetPen 1,1
:  EndPrgm
:Define dessine_axe()=Prgm
:  SetColor 0,255,0
:  SetPen 1,1
:  DrawText 181,91,"1"
:  DrawText 206,91,"2"
:  DrawText 231,91,"3"
:EndPrgm
:Define ini_rayons()=Prgm
:  pas:=6°:balayage:=0:matrice:=newMat(6,2)
:matrice:=[[xcentre+rayon*cos(5*pas+balayage),ycentre+rayon*sin(5*pas+balayage)][xcentre+rayon*cos(4*pas+balayage),ycentre+rayon*sin(4*pas+balayage)][xcentre+rayon*cos(3*pas+balayage),ycentre+rayon*sin(3*pas+balayage)][xcentre+rayon*cos(2*pas+balayage),ycentre+rayon*sin(2*pas+balayage)][xcentre+rayon*cos(1*pas+balayage),ycentre+rayon*sin(1*pas+balayage)][xcentre+rayon*cos(1*pas+balayage),ycentre+rayon*sin(1*pas+balayage)]]
:EndPrgm
:Define calculs()=Prgm
:  matrice:=(augment([[0][0]],(subMat(matrice,1,1,5,2))))
:  matrice[1]:=[xcentre+rayon*cos(5*pas+balayage),ycentre+rayon*sin(5*pas+balayage)]
:EndPrgm
:Define dessine_rayons()=Prgm
:  SetColor 0,255,0
:  FillPoly xcentre,ycentre,matrice[1,1],matrice[1,2],matrice[2,1],matrice[2,2],xcentre,ycentre
:  SetColor 0,205,0
:  FillPoly xcentre,ycentre,matrice[2,1],matrice[2,2],matrice[3,1],matrice[3,2],xcentre,ycentre
:  SetColor 0,155,0
:  FillPoly xcentre,ycentre,matrice[3,1],matrice[3,2],matrice[4,1],matrice[4,2],xcentre,ycentre
:  SetColor 0,100,0
:  FillPoly xcentre,ycentre,matrice[4,1],matrice[4,2],matrice[5,1],matrice[5,2],xcentre,ycentre
:  SetColor 0,0,0
:  FillPoly xcentre,ycentre,matrice[5,1],matrice[5,2],matrice[6,1],matrice[6,2],xcentre,ycentre
:EndPrgm
:Define ini_contact()=Prgm
:  signe:={−1,1}
:  contactrayon:=randInt(45,95)
:  contactx:=randInt(xcentre-contactrayon,xcentre+contactrayon)
:  contacty:=iPart(ycentre+signe[randInt(1,2)]*√(contactrayon^(2)-(contactx-xcentre)^(2)))
:EndPrgm
:Define θ(v1,v2)=Func
:  Local v1,v2
:  Return cos(((dotP(v1,v2))/(norm(v1)*norm(v2))))*((180)/(π))
:EndFunc
:Define dessine_contact()=Prgm
:  ang_contact:=approx(θ([contactx-xcentre,contacty-ycentre],[rayon,0]))
:  If contacty<ycentre Then
:    ang_contact:=360-ang_contact
:  EndIf
:   tempo:=(balayage+5*pas)*((180)/(π))-ang_contact
:  If tempo<0 or tempo>270 Then
:    SetColor 1,0,0
:  EndIf
:  If tempo>0 and tempo<90 Then
:    SetColor 1,255,0
:  EndIf
: If tempo>90 and tempo<180 Then
:    SetColor 1,155,0
:  EndIf
: If tempo>180 and tempo<270 Then
:    SetColor 1,100,0
: EndIf
:  FillCircle contactx,contacty,3
:  SetColor 0,255,0
:EndPrgm
:Define ini_mvt()=Prgm
:  mvtcontactm:=((randInt(−100,100))/(100.))
:  mvtcontactx:=signe[randInt(1,2)]*randInt(4,8)
:EndPrgm
:Define mvtcontact()=Prgm
:  contactx:=contactx+mvtcontactx
:  contacty:=round(contacty+mvtcontactm*mvtcontactx,0)
:EndPrgm
:Define afficheθd()=Prgm
:  SetColor 0,0,0
:  FillRect 12,1,35,15
:  FillRect 269,1,295,15
:  SetColor 0,255,0
:  DrawText 15,1,left(string(round(ang_contact,0)),dim(string(round(ang_contact,0)))-1)&"°"
:  tempo:=string(round(40*√((contactx-xcentre)^(2)+(contacty-ycentre)^(2)),0))
:  tempo:=left(tempo,dim(tempo)-1)&"m"
:  DrawText 270,1,tempo
:EndPrgm
:Define efface_msg()=Prgm
:  SetColor 0,0,0
:  FillRect 0,198,111,13
:  FillRect 0,187,59,12
:  FillRect 0,176,51,12
:  SetColor 0,255,0
:EndPrgm
:Define tir_torpille()=Prgm
:  status:=1
:  proxi:=0
:  efface_msg()
:  DrawText 1,198,"Angle de tir?"
:  DrawText 1,187,"Tir: Enter"
:  DrawText 9,176,"θ:"
:  angle_tir:=" "
:  key:=" "
:  keyok:=0
:  While key≠"enter"
:    key:=getKey(1)
:    If key="1" or key="2" or key="3" or key="4" or key="5" or key="6" or key="7" or key="8" or key="9" or key="0" Then
:      angle_tir:=expr(angle_tir&key)
:      If angle_tir>360 Then
:        angle_tir:=0
:      EndIf
:      angle_tir:=string(angle_tir)
:      SetColor 0,0,0
:      FillRect 22,176,30,13
:      SetColor 0,255,0
:      DrawText 26,176,angle_tir&"°"
:      keyok:=1
:    EndIf
:    EndWhile
:    If keyok=1 Then
:      angle_tir:=expr(angle_tir)°
:      efface_msg()
:      DrawText 1,198,"Mode acquisition.."
:      torpille:=[xcentre,ycentre]
:      torpillex:=xcentre
:      torpilley:=ycentre
:    EndIf
:EndPrgm
:Define mvttorpille()=Prgm
:  If proxi=1 Then
:    torpille:=torpille+7*unitV([contactx-torpillex,contacty-torpilley])
:  Else
:    torpille:=torpille+[7,∠angle_tir]
:  EndIf
:  torpillex:=round(mat▶list(torpille)[1],0)
:  torpilley:=round(mat▶list(torpille)[2],0)
:EndPrgm

:©Début du programme principal.

:setMode(2,1)
:proxi:=0
:status:=0
:ini_window():ini_sonar():dessine_sonar()
:dessine_axe():ini_rayons():ini_contact():ini_mvt()
:key:=""
:While key≠"esc"
:  key:=getKey(0)
:  For i,1,60
:    calculs()
:    balayage:=mod(balayage+pas,360°)
:    dessine_rayons()
:    dessine_sonar()
:    dessine_contact()
:    afficheθd()
:    If status=1 Then
:      SetColor 0,255,0
:      PlotXY torpillex,torpilley,5
:    EndIf
:    key:=getKey(0)
:    If key="esc" Then
:      Exit
:    EndIf
:    If key="t" Then
:      tir_torpille()
:    EndIf
:  EndFor
:  If status=1 Then
:    mvttorpille()
:    If (torpillex-xcentre)^(2)+(torpilley-ycentre)^(2)>(rayon-10)^(2) Then
:      status:=0
:      efface_msg()
:    ElseIf (torpillex-contactx)^(2)+(torpilley-contacty)^(2)≤15^(2) Then
:      proxi:=1
:      efface_msg()
:      DrawText 1,198,"Mode poursuite.."
:    EndIf
:    If abs(torpillex-contactx)≤3 and abs(torpilley-contacty)≤3 Then
:      efface_msg()
:      proxi:=−1
:      DrawText 1,198,"Contact atteint."
:      Exit
:    EndIf
:  EndIf
:dessine_axe()
:mvtcontact()
:If (contactx-xcentre)^(2)+(contacty-ycentre)^(2)>(rayon-2)^(2) Then
:  proxi:=0
:  efface_msg()
:  ini_contact()
:  ini_mvt()
:EndIf
:EndWhile
:DelVar xcentre,ycentre,rayon,pas,signe
:DelVar key,i,matrice,calculs,balayage
:DelVar ini_window,ini_sonar,ini_rayons
:DelVar dessine_axe,dessine_rayons,dessine_sonar
:DelVar contactx,contacty,contactrayon,ini_contact
:DelVar tempo,θ,ang_contact,dessine_contact
:DelVar ini_mvt,mvtcontact,mvtcontactm,mvtcontactx
:DelVar afficheθd,tir_torpille,keyok,angle_tir,mvttorpille
:DelVar efface_msg,status,torpille,torpillex,torpilley,proxi
:EndPrgm

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 17:23
de Shadow15510
J'avais oublié getkeys… x) Sur Numworks je m'étais bricolé une keylib avec ion et time. Ça doit pouvoir passer… ^^ Merci pour le code ! :)

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 17:56
de Shadow15510
Je viens de découvrir que la fonction
Code: Tout sélectionner
draw_string
du module Kandinsky accepte deux arguments optionnels : la couleur du texte et la couleur de fond ça donne :
Code: Tout sélectionner
draw_string(<texte>, <x>, <y> [, <couleur>] [, <fond>])
:P

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 14 Juin 2020, 18:01
de critor
Oui.

Malheureusement, on ne contrôle pas le fond chez Casio.

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 15 Juin 2020, 08:40
de Shadow15510
Ouaip, c'est dommage… De toute façon, l'absence de gestion des touches rend les jeux impossible à jouer… Par contre j'ai de bons espoirs sur la Numworks ! :P

Re: Sonar un jeu TI-Basic graphique pour TI-Nspire CX II

Message non luPosté: 15 Juin 2020, 09:34
de Shadow15510
J'ai commencé à regarder un peu : j'arrive à faire faire un tour complet au radar en 8 secondes avec deux triangles… Et l'image clignote un peu… x)