j'essai de faire un cylce jour,nuit 2d et testé les lists,mais j'ai des ralentissements sur les déplacements des personnages.
je passe par un openwindowscreen,mais je suis pas sur du résultat par rapport à l'affichage des data(placement des sprites par rapport à l'ecran).
touche echap pour quitter le programme
merci pour votre aide.
Code : Tout sélectionner
;-- cycle jour,nuit avec data --
EnableExplicit
;- Initialisations
If InitSprite()=0 Or InitKeyboard()=0 ;Or InitSound() = 0
MessageRequester("Probleme","Initialisations impossibles",0)
End
EndIf
Enumeration
#etoile
#etoile2
#etoile3
#base
#terrain
#raster
#Soleil
#cercle
#pierre
#porte
#soldat
#soldat_gauche
#soldat_droite
EndEnumeration
Enumeration fenetre
#fenetre = 0
EndEnumeration
Enumeration
#font
EndEnumeration
;-- Structure --
Structure Star
Xpos.i
Ypos.i
vit.i
couleur_star.b
EndStructure
Structure base
x.i
y.i
base.i
EndStructure
Structure renfort
x.i
y.i
renfort.i
EndStructure
Structure base_droite
x.i
y.i
base_droite.i
EndStructure
Structure Soleilp
Posx.f
Posy.f
Vitesse.f
Couleur.i
EndStructure
Structure Soldat
Posx.f
Posy.f
Vitesse_soldat.f
EndStructure
Structure Soldat_gauche
soldats_gauche_Posx.i
soldats_gauche_Posy.i
Vitesse_soldats_gauche.i
EndStructure
Structure Soldat_droite
soldats_droite_Posx.i
soldats_droite_Posy.i
Vitesse_soldats_droite.i
EndStructure
;-- constantes --
#Fps = 60
#NBstar=200
#Nbbox = 28
#Nbcercle =35
#Nbround =20
#Nbporte = 9
#Cycle = 255
#sol =650
#Nb_colonne = 6
#nbs = 1
#Nbsoldat_gauche = 20
#Nbsoldat_droite = 20
#intensite =255
#variation_soldats=250
Global largeur_ecran,hauteur_ecran,event,i,font,intensite.f,variation_intensite.f
Global Colonne_Hauteur,colonne_Largeur,col_Hg,col_Hd,col_Lg,col_Ld
Global Lcercle,Radius,Radius2,x,y,Largeur,Hauteur,Couleur,couleur2,couleur3
Global xc,yc,spritex,spritey,round_x,round_y,round_ax,round_ay,Largeur_Rx,Hauteur_Ry
Global Portex,Portey,Lportex,Hportey,Aportex,Aportey,couleur_porte
Global R1.f,V1.f,B1.f,R2.f,V2.f,B2.f,Dr.f,Dv.f,Db.f,init,Ctime,Move_soldats
Global Dim stars.star(#NBstar)
Global Lstar,Hstar,Lstarv,Hstarv
Global rasterx, rastery,Csoleil,Csoleil,radius_soleil,soleil_posy.f,variation_soleil.f
Global soldat_gauchex,soldat_gauchey,soldat_gauche_largeur,soldat_gauche_hauteur,soldat_gauche_couleur
Global soldat_droitex,soldat_droitey,soldat_droite_largeur,soldat_droite_hauteur,soldat_droite_couleur
Global NewList bases.Base()
Global NewList renforts.renfort()
Global NewList bases_droite.base_droite()
Global NewList soleil_A.soleilP()
Global NewList soldats.soldat()
Global NewList soldats_gauche.soldat_gauche()
Global NewList soldats_droite.soldat_droite()
ExamineDesktops()
largeur_ecran = DesktopWidth(0)
hauteur_ecran =DesktopHeight(0)
rasterx = 0
rastery = 450
variation_intensite.f=0.05;
variation_soleil.f = 0.09
Csoleil=90
radius_soleil=90
soleil_posy.f = 650
Lstar = largeur_ecran
Hstar = hauteur_ecran/2
Procedure newfont()
Protected font
font=LoadFont(#font, "arial",12)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#font))
DrawText(10,20,"Fps : "+Str(#Fps),RGB(255,185,96))
DrawText(10,50,"Soleil_posx : "+Str(soleil_A()\Posx),RGB(255,185,96))
DrawText(10,80,"Soleil Posy : "+Str(soleil_Posy),RGB(255,185,96))
DrawText(10,110,"Intensite : "+Str(intensite.f),RGB(255,185,96))
DrawText(10,140,"Soldats Posx : "+Str(soldats()\posx.f),RGB(255,185,96))
DrawText(10,170,"Soldat Gauche Posx : "+Str(soldats_gauche()\soldats_gauche_posx),RGB(255,185,96))
DrawText(10,200,"Soldat Droite Posx : "+Str(soldats_droite()\soldats_droite_posx),RGB(255,185,96))
StopDrawing()
EndProcedure
;degrade ciel
Procedure degrade()
;couleur de depart
R1.f = 60 ;coucher soleil
V1.f = 0
B1.f = 140 ; coucher soleil
;couleur d'arrive
R2.f = 160
V2.f = 136
B2.f = 200
;delta
Dr.f = ((R2-R1)/255)
Dv.f = ((V2-V1)/255)
Db.f = ((B1-B2)/255)
EndProcedure
;-lire Data
Procedure Lire_data()
;-box
Restore boxdata
StartDrawing(SpriteOutput(#soldat))
For i=1 To #Nbbox
Read.i x
Read.i y
Read.i largeur
Read.i hauteur
Read.i couleur
Box(x,y,largeur,hauteur,couleur)
Next
StopDrawing()
;-cercle
Restore cercledata
StartDrawing(SpriteOutput(#Cercle))
For i = 1 To #Nbcercle
Read.i xc
Read.i yc
Read.i radius
Read.i couleur2
Circle(xc,yc,radius,couleur2)
Next
StopDrawing()
;-roundbox
Restore rounddata
StartDrawing(SpriteOutput(#pierre))
For i = 1 To #Nbround
Read.i round_x
Read.i round_y
Read.i Largeur_Rx
Read.i Hauteur_Ry
Read.i round_ax
Read.i round_ay
Read.i couleur3
RoundBox(Round_x,Round_y,Largeur_Rx,Hauteur_Ry,round_ax,round_ay,couleur3)
Next
StopDrawing()
Restore porte
StartDrawing(SpriteOutput(#porte))
For i = 1 To #Nbporte
Read.i Portex
Read.i portey
Read.i Lportex
Read.i Hportey
Read.i Aportex
Read.i Aportey
Read.i couleur_porte
RoundBox(Portex,Portey,Lportex,Hportey,Aportex,Aportey,couleur_porte)
Next
StopDrawing()
Restore soldat_gauche_box
StartDrawing(SpriteOutput(#soldat_gauche))
For i=1 To #Nbsoldat_gauche
Read.i soldat_gauchex
Read.i soldat_gauchey
Read.i soldat_gauche_largeur
Read.i soldat_gauche_hauteur
Read.i soldat_gauche_couleur
Box(soldat_gauchex,soldat_gauchey,soldat_gauche_largeur,soldat_gauche_hauteur,soldat_gauche_couleur)
Next
StopDrawing()
Restore soldat_droite_box
StartDrawing(SpriteOutput(#soldat_droite))
For i=1 To #Nbsoldat_droite
Read.i soldat_droitex
Read.i soldat_droitey
Read.i soldat_droite_largeur
Read.i soldat_droite_hauteur
Read.i soldat_droite_couleur
Box(soldat_droitex,soldat_droitey,soldat_droite_largeur,soldat_droite_hauteur,soldat_droite_couleur)
Next
StopDrawing()
EndProcedure
Procedure dessine_star()
StartDrawing(SpriteOutput(#etoile))
Box(0,0,2,6,$FF9A70)
StopDrawing()
StartDrawing(SpriteOutput(#etoile2))
Box(0,0,1,1,$0033FF)
StopDrawing()
StartDrawing(SpriteOutput(#etoile3))
Box(0,0,1,1,$FFCC00)
StopDrawing()
EndProcedure
;----- init starfield horizontale ---------
Procedure init_star()
Protected i
With stars(i)
For i = 0 To #Nbstar
\Xpos = i*Largeur_ecran/ #Nbstar
\Ypos = i*Hauteur_ecran/2 / #Nbstar
\vit=Random(4,2)
\couleur_star=Random(2,1)
Next
For i = 0 To #Nbstar*5
Swap stars(Random(#Nbstar))\Xpos, stars(Random(#Nbstar))\Xpos
Swap stars(Random(#Nbstar))\Ypos, stars(Random(#Nbstar))\Ypos
Next i
EndWith
EndProcedure
;----------- affiche starfield horizontale ---------
Procedure affiche_star()
Protected i
For i= 0 To #nbstar
TransparentSpriteColor(#etoile,RGB(0,0,0))
TransparentSpriteColor(#etoile2,RGB(0,0,0))
TransparentSpriteColor(#etoile3,RGB(0,0,0))
DisplayTransparentSprite(stars(i)\couleur_star,stars(i)\Xpos,stars(i)\Ypos-5,intensite)
;If soleil_posy<350:stars(i)\Xpos - stars(i)\vit:EndIf
If stars(i)\Xpos < = 0
stars(i)\Xpos + Lstar
EndIf
Next
EndProcedure
Procedure initialisation_degrade()
;couleur de depart
R1.f = 60 ;coucher soleil
V1.f = 0
B1.f = 140 ; coucher soleil
;couleur d'arrive
R2.f = 160
V2.f = 136
B2.f = 200
;delta
Dr.f = ((R2-R1)/255)
Dv.f = ((V2-V1)/255)
Db.f = ((B1-B2)/255)
EndProcedure
Procedure soleil()
StartDrawing(SpriteOutput(#soleil))
Circle(Csoleil,Csoleil,radius_soleil,RGB(253,255,14))
StopDrawing()
EndProcedure
;mouvement soleil
Procedure mov_soleil()
soleil_posy.f=soleil_posy.f+variation_soleil.f
If soleil_posy.f>#sol Or soleil_posy.f=<200
variation_soleil.f=-variation_soleil.f
EndIf
EndProcedure
;initalisation soleil
Procedure Initialisation_soleil()
For i = 1 To #nbs
AddElement(Soleil_A())
With Soleil_A()
\Posx = Largeur_ecran/2-90
\Posy = 150
\vitesse=0.08
\Couleur.i = 255
Next
EndWith
EndProcedure
;fond
Procedure initialisation_base()
For colonne_largeur = 1 To 7
For colonne_hauteur = 1 To 5
AddElement(bases())
With Bases()
\x=colonne_largeur*96
\y=colonne_hauteur*70
\base = CopySprite(#pierre,#PB_Any)
Next
Next
EndWith
EndProcedure
;renfort
Procedure initialisation_renforts()
For col_Lg= 1 To 4
For col_Hg = 1 To 6
AddElement(renforts())
With renforts()
\x=col_Lg*200
\y=col_Hg*70
\renfort = CopySprite(#Pierre,#PB_Any)
Next
Next
EndWith
EndProcedure
;-deplacement soldats
Procedure deplacement_soldats()
AddElement(soldats())
With soldats()
\posx = 450
\posy = Hauteur_ecran/2 - 58
\vitesse_soldat =0
EndWith
EndProcedure
Procedure deplacement_soldat_gauche()
AddElement(soldats_gauche())
With soldats_gauche()
\soldats_gauche_posx =largeur_ecran
\soldats_gauche_posy = Hauteur_ecran/2 +300
\vitesse_soldats_gauche = 1
EndWith
EndProcedure
Procedure deplacement_soldat_droite()
AddElement(soldats_droite())
With soldats_droite()
\soldats_droite_posx =-150
\soldats_droite_posy = Hauteur_ecran/2 +350
\Vitesse_soldats_droite = 1
EndWith
EndProcedure
Procedure intensite()
intensite.f=intensite.f+variation_intensite.f
If intensite.f>#cycle Or intensite.f=<0
variation_intensite.f=-variation_intensite.f
EndIf
EndProcedure
;---- Degrade ---------
Procedure affiche_degrade()
For rasterY = 1 To hauteur_ecran
StartDrawing(SpriteOutput(#raster))
LineXY(rasterx+hauteur_ecran, rastery, rasterx, rastery, RGB(R1, V1, B1))
R1 + Dr
V1 + Dv
B1 + Db
StopDrawing()
Next rasterY
EndProcedure
;---- Affiche decor ---------
Procedure affiche_base()
ForEach Bases()
TransparentSpriteColor(#pierre,RGB(0,0,0))
;base droite
DisplayTransparentSprite(#pierre,Bases()\x+hauteur_ecran/2-550,Bases()\y+hauteur_ecran/2-30)
;base gauche
DisplayTransparentSprite(#pierre,Bases()\x+hauteur_ecran/2+450,Bases()\y+hauteur_ecran/2-30)
Next
EndProcedure
Procedure affiche_renforts()
ForEach renforts()
TransparentSpriteColor(#pierre,RGB(0,0,0))
; renfort droit
DisplayTransparentSprite(#pierre,renforts()\x+largeur_ecran/2-1050,renforts()\y+hauteur_ecran/2-95)
; renfort gauche
DisplayTransparentSprite(#pierre,renforts()\x+largeur_ecran/2-120,renforts()\y+hauteur_ecran/2-95)
Next
EndProcedure
;-terrain
Procedure terrain()
StartDrawing(SpriteOutput(#terrain))
Box(0,0,650,350,$4856)
StopDrawing()
EndProcedure
;--- ouverture ecran ---
If OpenWindow(#fenetre,0,0,largeur_ecran,hauteur_ecran,"test list",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(#fenetre),0,0,largeur_ecran,hauteur_ecran)
CreateSprite(#etoile,1,1,#PB_Sprite_PixelCollision)
CreateSprite(#etoile2,1,1,#PB_Sprite_AlphaBlending)
CreateSprite(#etoile3,1,1,#PB_Sprite_AlphaBlending)
CreateSprite(#soldat,120,150,#PB_Sprite_AlphaBlending)
CreateSprite(#soldat_gauche,120,150,#PB_Sprite_AlphaBlending)
CreateSprite(#soldat_droite,120,150,#PB_Sprite_AlphaBlending)
CreateSprite(#raster,250,500,#PB_Sprite_AlphaBlending)
CreateSprite(#Soleil,185,185,#PB_Sprite_AlphaBlending)
CreateSprite(#cercle,250,350,#PB_Sprite_AlphaBlending)
CreateSprite(#porte,250,350,#PB_Sprite_AlphaBlending)
CreateSprite(#pierre,300,300,#PB_Sprite_AlphaBlending)
CreateSprite(#terrain,650,350,#PB_Sprite_AlphaBlending)
;appelle procedure
init_star()
dessine_star()
initialisation_degrade()
affiche_degrade()
initialisation_soleil()
soleil()
initialisation_base()
initialisation_renforts()
lire_data()
terrain()
deplacement_soldats()
deplacement_soldat_gauche()
deplacement_soldat_droite()
;-boucle
Repeat
If ElapsedMilliseconds() > Ctime + 1000/#Fps
Ctime = ElapsedMilliseconds()
FlipBuffers()
ClearScreen(RGB(0,0,0))
;--- debut intro ----
init+1
Select Init
Case init
intensite()
affiche_star()
mov_soleil()
soleil_A()\Posx+soleil_A()\vitesse
If soleil_A()\posx>largeur_ecran:soleil_A()\posx=-185:EndIf
;--- raster ciel -------
TransparentSpriteColor(#raster,RGB(0,0,0))
ZoomSprite(#raster,largeur_ecran,hauteur_ecran/2+250)
DisplayTransparentSprite(#raster,rasterX,rasterY-hauteur_ecran-5,intensite)
TransparentSpriteColor(#soleil,RGB(0,0,0))
DisplayTransparentSprite(#soleil,soleil_A()\Posx,soleil_posy)
TransparentSpriteColor(#soldat,RGB(0,0,0))
DisplayTransparentSprite(#soldat,soldats()\posx-190,soldats()\posy)
DisplayTransparentSprite(#soldat,soldats()\posx+250,soldats()\posy)
DisplayTransparentSprite(#soldat,soldats()\posx+largeur_ecran/2-50,soldats()\posy)
DisplayTransparentSprite(#soldat,soldats()\posx+largeur_ecran/2+250,soldats()\posy)
ZoomSprite(#terrain,largeur_ecran,280)
DisplayTransparentSprite(#terrain,0,750)
affiche_base()
affiche_renforts()
TransparentSpriteColor(#porte,RGB(0,0,0))
TransparentSpriteColor(#cercle,RGB(0,0,0))
DisplayTransparentSprite(#porte,largeur_ecran/2-160,hauteur_ecran/2+175-soleil_posy/2+10)
DisplayTransparentSprite(#cercle,largeur_ecran/2-120,hauteur_ecran/2+205-soleil_posy/2+10)
soldats_gauche()\soldats_gauche_Posx-soldats_gauche()\Vitesse_soldats_gauche
TransparentSpriteColor(#soldat_gauche,RGB(0,0,0))
DisplayTransparentSprite(#soldat_gauche,soldats_gauche()\soldats_gauche_posx,soldats_gauche()\soldats_gauche_posy)
DisplayTransparentSprite(#soldat_gauche,soldats_gauche()\soldats_gauche_posx+100,soldats_gauche()\soldats_gauche_posy)
DisplayTransparentSprite(#soldat_gauche,soldats_gauche()\soldats_gauche_posx+180,soldats_gauche()\soldats_gauche_posy)
If soldats_gauche()\soldats_gauche_posx<-250:soldats_gauche()\soldats_gauche_posx=largeur_ecran:EndIf
TransparentSpriteColor(#soldat_droite,RGB(0,0,0))
soldats_droite()\soldats_droite_posx+soldats_droite()\Vitesse_soldats_droite
DisplayTransparentSprite(#soldat_droite,soldats_droite()\soldats_droite_posx,soldats_droite()\soldats_droite_posy)
DisplayTransparentSprite(#soldat_droite,soldats_droite()\soldats_droite_posx-100,soldats_droite()\soldats_droite_posy)
DisplayTransparentSprite(#soldat_droite,soldats_droite()\soldats_droite_posx-180,soldats_droite()\soldats_droite_posy)
If soldats_droite()\soldats_droite_posx>largeur_ecran+150:soldats_droite()\soldats_droite_posx=-150:EndIf
EndSelect
newfont()
Else
Delay(1)
EndIf
Repeat
ExamineKeyboard()
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event=0
Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
End
EndIf
;-- Data ---
DataSection
boxdata:
;personnage
Data.i 41,20,5,3,$999999,37,23,13,8,$999999,33,25,4,18,$999999,50,25,4,18,$999999,36,30,15,15,$99A8FF,41,30,4,8,$999999,37,35,3,2,$686E00,46,35,3,2,$686E00
Data.i 40,42,5,1,$686E00,38,45,10,5,$99A8FF,36,48,15,30,$999999,30,50,5,25,$999999,52,50,5,25,$999999,20,70,15,5,$999999,20,70,5,5,$99A8FF,21,18,3,100,$4144
Data.i 21,10,4,25,$FFE4B3,10,23,20,8,$FFE4B3,40,70,15,5,$999999,40,70,5,5,$99A8FF,36,80,5,35,$999999,45,80,5,35,$999999,34,75,18,12,$3446,36,78,15,3,$999999
Data.i 36,110,5,5,$3446,45,110,5,5,$3446,31,115,10,5,$999999,43,115,10,5,$999999
cercledata:
Data.i 12,9,2,$4C3F00,46,9,2,$4C3F00,80,9,2,$4C3F00,120,9,2,$4C3F00,160,9,2,$4C3F00,12,48,2,$4C3F00,46,48,2,$4C3F00,80,48,2,$4C3F00,120,48,2,$4C3F00,160,48,2,$4C3F00
Data.i 12,88,2,$4C3F00,46,88,2,$4C3F00,80,88,2,$4C3F00,120,88,2,$4C3F00,160,88,2,$4C3F00,12,128,2,$4C3F00,46,128,2,$4C3F00,80,128,2,$4C3F00,120,128,2,$4C3F00,160,128,2,$4C3F00
Data.i 30,158,2,$4C3F00,30,188,2,$4C3F00,30,218,2,$4C3F00,30,248,2,$4C3F00,30,278,2,$4C3F00,85,158,2,$4C3F00,85,188,2,$4C3F00,85,218,2,$4C3F00,85,248,2,$4C3F00,85,288,2,$4C3F00
Data.i 138,158,2,$4C3F00,138,188,2,$4C3F00,138,218,2,$4C3F00,138,248,2,$4C3F00,138,278,2,$4C3F00
rounddata:
;-pierre
Data.i 0,23,52,20,5,5,$666666,3,25,45,15,2,2,$777777,50,23,51,20,5,5,$666666,52,25,47,15,2,2,$777777,0,40,35,20,5,5,$666666,3,43,30,14,2,2,$777777,35,40,35,20,5,5,$666666,37,43,30,14,2,2,$777777
Data.i 70,40,30,20,5,5,$666666,70,43,28,14,2,2,$777777,0,57,54,20,5,5,$666666,3,60,45,15,2,2,$777777,48,57,52,20,5,5,$666666,52,60,46,15,2,2,$777777,0,75,38,20,5,5,$666666,3,77,30,14,2,2,$777777
Data.i 35,75,35,20,5,5,$666666,37,77,30,14,2,2,$777777,68,75,32,20,5,5,$666666,70,77,28,14,2,2,$777777
;-portail&
porte:
Data.i 0,0,255,360,180,20,$2B42,25,15,200,320,160,20,$3648,18,28,215,20,10,20,$2B42,18,68,215,20,10,20,$2B42,18,108,215,20,10,20,$2B42,18,148,215,20,10,20,$2B42,62,148,20,220,10,20,$2B42
Data.i 115,148,20,220,10,20,$2B42,168,148,20,220,10,20,$2B42
;-- soldat gauche ---
soldat_gauche_box:
Data.i 58,0,10,5,$FFE4B5,54,5,20,5,$FFE4B5,50,10,25,5,$FFE4B5,53,15,16,15,$99A8FF,54,20,5,3,$686E00,53,32,20,10,$99A8FF,60,15,15,22,$FFE4B5,35,65,20,8,$999999
Data.i 30,65,8,8,$99A8FF,32,5,3,125,$4144,31,5,5,35,$FFE4B3,15,25,25,10,$FFE4B3,65,92,10,40,$4144,65,95,8,25,$999999,50,125,20,8,$999999,60,42,15,20,$999999
Data.i 55,47,35,45,$2B42,60,52,25,35,$4144,62,55,20,30,$2B42,67,65,10,10,$FFE4B5
;-- soldat droite --
soldat_droite_box:
Data.i 58,0,10,5,$FFE4B5,54,5,20,5,$FFE4B5,50,10,25,5,$FFE4B5,57,15,16,15,$99A8FF,67,20,5,3,$686E00,53,32,20,10,$99A8FF,50,15,15,22,$FFE4B5,78,65,20,8,$999999
Data.i 98,65,8,8,$99A8FF,101,5,3,125,$4144,100,5,5,35,$FFE4B3,95,25,20,10,$FFE4B3,60,92,10,40,$4144,60,95,8,25,$999999,62,125,20,8,$999999,55,42,15,5,$999999
Data.i 50,47,35,45,$2B42,55,52,25,35,$FFE4B5,58,55,20,30,$2B42,62,65,10,10,$FFE4B5
;soldats attaque
EndDataSection