cycle jour,nuit avec data

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
raven
Messages : 222
Inscription : jeu. 06/janv./2005 15:45

cycle jour,nuit avec data

Message par raven »

Bonjour,
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

Pb5.24 Lts/5.31 Windows 7 64 nvidia 560 ti E8500 8g ram
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: cycle jour,nuit avec data

Message par TazNormand »

Salut Raven,

sympa le tapis roulant pour les gardes devant le château :lol:

plaisanterie mise à part, je vois que tu fais du lineXY() pour le dégradé du ciel, je n'ai pas fait de code mais une idée me viens, pourquoi ne pas jouer sur le niveau d'opacité d'une image via DrawAlphaImage() ?

Edit : Je viens de voir que tu utilisais un gros sprite de fond et que tu jouais sur l'opacité, donc oublies ma remarque.
Image
Image
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: cycle jour,nuit avec data

Message par Ar-S »

Chez moi ton code ne rame pas et reste à 60fps mais j'ai une GTX 1080 donc j'ai plus rien qui rame pour tout dire.
Juste une remarque. Dans ta proce newfont() tu as

Code : Tout sélectionner

font=LoadFont(#font, "arial",12)
Vire le et mets le en début de code avec tes globales

Code : Tout sélectionner

Global font=LoadFont(#font, "arial",12)
Parce que là ta font ce charge à chaque repeat, je te dis pas le gâchis :)

Je trouve aussi étrange ce

Code : Tout sélectionner

 Select Init
           Case init
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
raven
Messages : 222
Inscription : jeu. 06/janv./2005 15:45

Re: cycle jour,nuit avec data

Message par raven »

oui j'ai crée un gros sprite,puis dessiner le degradé dedans avec un zoom.
je sais pas si c'est la meilleur façon de faire.

les datas sont pas terrible c'etait un test :)

les valeurs des fps ne bouge pas,ça renvoie juste la valeur de la constante dans le drawtext.
mais dès que je rajoute des sprites par dessus y'a des sacades.

Code : Tout sélectionner

;-test dégradé-
EnableExplicit
InitSprite()
InitKeyboard()

Enumeration
  #raster
  #raster02
EndEnumeration

Enumeration fenetre
  #fenetre
EndEnumeration 

Enumeration
  #font
EndEnumeration

#fps = 60
#start = 1
#cycle = 255

Global Largeur_ecran,Hauteur_ecran,init,intensite.f,variation_intensite.f,ctime,debut
Global Bposx,Bposy,event,Rouge1.f,Vert1.f,Bleu1.f,Rouge2.f,Vert2.f,Bleu2.f,Drouge.f,Dvert.f,Dbleu.f,i
Global R1.f,R2.f,V1.f,V2.f,B1.f,B2.f,Dr.f,Dr2.f,Dv.f,Dv2.f,Db.f,Db2.f,rasterX,rasterY
Global Rd.f,Vd.f,Bd.f,Ra.f,Va.f,Ba.f,Dra.f,Dva.F,Dba.f,Raster02_x,Raster02_y
Global font=LoadFont(#font, "arial",12)

ExamineDesktops()
largeur_ecran = DesktopWidth(0)
hauteur_ecran = DesktopHeight(0)

rasterX = 0
raster02_x =0
intensite.f = 15
variation_intensite.f= 0.8
Procedure degrade()
  ;couleur de depart
 ;-- degradé 1 --
  R1.f = 60 ;coucher soleil
  V1.f = 0
  B1.f = 140 
  ;couleur d'arrive
  R2.f =  160
  V2.f = 135
  B2.f = 180
  ;delta
  Dr.f = ((R2-R1)/255)
  Dv.f =  ((V2-V1)/255)
  Db.f = ((B1-B2)/255)
  ;-- degradé 2 ----
  Rd.f = 0                        
  Vd.f = 0
  Bd.f = 0
  ;couleur d'arrive
  Ra.f =  255
  Va.f = 255
  Ba.f = 130
  ;delta
  Dra.f = ((Ra-Rd)/255)
  Dva.f =  ((Va-Vd)/255)
  Dba.f = ((Bd-Ba)/255)
  EndProcedure
  ;--------------------

Procedure intensite()
  intensite.f=intensite.f+variation_intensite.f
  If intensite.f>#cycle Or intensite.f=<15
    variation_intensite.f=-variation_intensite.f
  EndIf
EndProcedure

;--------------------------
Procedure newfont()
  StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(#font))
  DrawText(10,50,"Test Dégradé ",RGB(255,185,96))
  DrawText(10,90," Intensite : "+Str(intensite),RGB(255,185,96))
  StopDrawing()
EndProcedure

degrade()
;---- ouverture fenetre ----
If OpenWindow(#fenetre,0,0,largeur_ecran,hauteur_ecran,"test degrade",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(#fenetre),0,0,largeur_ecran,hauteur_ecran)
CreateSprite(#raster,800,600)
CreateSprite(#raster02,800,600)

;---- Degrade n 1 ------
  For rasterY = 0 To hauteur_ecran/2
    StartDrawing(SpriteOutput(#raster))
    LineXY(rasterx+Largeur_ecran, rastery, rasterx, rastery, RGB(R1, V1, B1))
    R1 + Dr 
    V1 + Dv 
    B1 +  Db
    StopDrawing()
  Next rasterY
  
    For raster02_Y = 0 To hauteur_ecran/2-250
    StartDrawing(SpriteOutput(#raster02))
    LineXY(raster02_x+Largeur_ecran, raster02_y, raster02_x, raster02_y, RGB(Rd, Vd, Bd))
    Rd + Dra
    Vd + Dva
    Bd + Dba
    StopDrawing()
  Next raster02_Y
;-------------------------

;boucle
Repeat ;2d
  If ElapsedMilliseconds() > Ctime + 1000/#Fps
    Ctime = ElapsedMilliseconds()

  FlipBuffers()
  ClearScreen(RGB(0,0,0))
  
  If debut = #start
    intensite()
    ZoomSprite(#raster,largeur_ecran,hauteur_ecran)
    DisplayTransparentSprite(#raster,rasterX,rasterY-hauteur_ecran/2,intensite)
    ZoomSprite(#raster02,largeur_ecran,Hauteur_ecran/2)
    DisplayTransparentSprite(#raster02,Raster02_x,Raster02_y+hauteur_ecran/2+20)
    newfont()
  EndIf

init = 1
    Select init 
      
    Case 1 
      debut=#start
        
  EndSelect
      Else
  Delay(1)
EndIf
  Repeat ;fenetre
    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
Pb5.24 Lts/5.31 Windows 7 64 nvidia 560 ti E8500 8g ram
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: cycle jour,nuit avec data

Message par Ar-S »

Et si tu vires tout le code de G-Rom concernant les Fps et qu'avant ta boucle tu mettes
SetFrameRate(60)

ça rame chez toi ça ?

Code : Tout sélectionner

;-test dégradé-
EnableExplicit
InitSprite()
InitKeyboard()


Enumeration sp
  #raster
  #raster02
  #SPRITE_ARS  
EndEnumeration

Enumeration fenetre
  #fenetre
EndEnumeration

Enumeration
  #font
EndEnumeration


#start = 1
#cycle = 255

Global AX

Global Largeur_ecran,Hauteur_ecran,init,intensite.f,variation_intensite.f,ctime,debut
Global Bposx,Bposy,event,Rouge1.f,Vert1.f,Bleu1.f,Rouge2.f,Vert2.f,Bleu2.f,Drouge.f,Dvert.f,Dbleu.f,i
Global R1.f,R2.f,V1.f,V2.f,B1.f,B2.f,Dr.f,Dr2.f,Dv.f,Dv2.f,Db.f,Db2.f,rasterX,rasterY
Global Rd.f,Vd.f,Bd.f,Ra.f,Va.f,Ba.f,Dra.f,Dva.F,Dba.f,Raster02_x,Raster02_y
Global font=LoadFont(#font, "arial",12)

ExamineDesktops()
largeur_ecran = DesktopWidth(0)
hauteur_ecran = DesktopHeight(0)

rasterX = 0
raster02_x =0
intensite.f = 15
variation_intensite.f= 0.8
Procedure degrade()
  ;couleur de depart
;-- degradé 1 --
  R1.f = 60 ;coucher soleil
  V1.f = 0
  B1.f = 140
  ;couleur d'arrive
  R2.f =  160
  V2.f = 135
  B2.f = 180
  ;delta
  Dr.f = ((R2-R1)/255)
  Dv.f =  ((V2-V1)/255)
  Db.f = ((B1-B2)/255)
  ;-- degradé 2 ----
  Rd.f = 0                       
  Vd.f = 0
  Bd.f = 0
  ;couleur d'arrive
  Ra.f =  255
  Va.f = 255
  Ba.f = 130
  ;delta
  Dra.f = ((Ra-Rd)/255)
  Dva.f =  ((Va-Vd)/255)
  Dba.f = ((Bd-Ba)/255)
  EndProcedure
  ;--------------------

Procedure intensite()
  intensite.f = intensite.f + variation_intensite.f
  If intensite.f > #cycle Or intensite.f <= 15
    variation_intensite.f = -variation_intensite.f
  EndIf
EndProcedure

;--------------------------
Procedure newfont()
  StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(#font))
  DrawText(10,50,"Test Dégradé ",RGB(255,185,96))
  DrawText(10,90," Intensite : "+Str(intensite),RGB(255,185,96))
  StopDrawing()
EndProcedure

degrade()
;---- ouverture fenetre ----
If OpenWindow(#fenetre,0,0,largeur_ecran,hauteur_ecran,"test degrade",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(#fenetre),0,0,largeur_ecran,hauteur_ecran)


CreateSprite (#SPRITE_ARS,45,45)
StartDrawing(SpriteOutput(#SPRITE_ARS))
Box(0,0,45,45,#Red)
StopDrawing()


CreateSprite(#raster,800,600)
CreateSprite(#raster02,800,600)




;---- Degrade n 1 ------
  For rasterY = 0 To hauteur_ecran/2
    StartDrawing(SpriteOutput(#raster))
    LineXY(rasterx+Largeur_ecran, rastery, rasterx, rastery, RGB(R1, V1, B1))
    R1 + Dr
    V1 + Dv
    B1 +  Db
    StopDrawing()
  Next rasterY
 
    For raster02_Y = 0 To hauteur_ecran/2-250
    StartDrawing(SpriteOutput(#raster02))
    LineXY(raster02_x+Largeur_ecran, raster02_y, raster02_x, raster02_y, RGB(Rd, Vd, Bd))
    Rd + Dra
    Vd + Dva
    Bd + Dba
    StopDrawing()
  Next raster02_Y
;-------------------------
  
  SetFrameRate(60)
  DisableDebugger

;boucle
  Repeat ;2d

  ClearScreen(RGB(0,0,0))
  
    debut = #start
    intensite()
    ZoomSprite(#raster,largeur_ecran,hauteur_ecran)
    DisplayTransparentSprite(#raster,rasterX,rasterY-hauteur_ecran/2,intensite)
    ZoomSprite(#raster02,largeur_ecran,Hauteur_ecran/2)
    DisplayTransparentSprite(#raster02,Raster02_x,Raster02_y+hauteur_ecran/2+20)
    newfont()
    
    AX + 5
    DisplayTransparentSprite(#SPRITE_ARS,AX, 20, 254, #Red)
    DisplayTransparentSprite(#SPRITE_ARS,AX, 90, 254, #Red)
    DisplayTransparentSprite(#SPRITE_ARS,AX, 150, 254, #Red)
    DisplayTransparentSprite(#SPRITE_ARS,AX, 260, 254, #Red)
    
    If AX >= Largeur_ecran 
    AX = 0
  EndIf
  
FlipBuffers()

  Repeat ;fenetre
    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
EnableDebugger
EndIf

~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
raven
Messages : 222
Inscription : jeu. 06/janv./2005 15:45

Re: cycle jour,nuit avec data

Message par raven »

non c'a rame pas c'est fluide,vais faire des tests, merci :wink:

edit: après test sur le code complet,c'est fluide aussi 8)
Pb5.24 Lts/5.31 Windows 7 64 nvidia 560 ti E8500 8g ram
Répondre