Mais je vois pas du tout comment corrigé cela .
Code : Tout sélectionner
;--- Initilisation
EnableExplicit
If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("Erreur", "Impossible d'initialiser le programme ")
End
EndIf
;---Constantes
Enumeration Windows
#Main_Windows
EndEnumeration
Enumeration Sprites
#Player
#Ennemy
#Tir
EndEnumeration
;--- Structure d'info pour le sprite du joueur , le tir du joueur et l'ennemi
Structure NewSprite
Posx.i
Posy.i
Sprite.i
Life.i
EndStructure
;---Gestion du tir
Global NewList Tir.NewSprite(),gShootReady=#True,gShootTime
;--- Gestion du joueur
Global Player.NewSprite
;--- Gestion de l'ennemi
Global Ennemy.NewSprite
;---Gestion de la barre de vie
Global gValue.i,gMaximum.i,gLife.i,gLifeMaxi.i,gLifeBar.i
;---Variables globale
Global gEvent, gWidth=800, gHeight=600
;--- Declaration de la procedure pour la barre de vie
Declare DisplayProgressBar(Sprite,x,y,gValue, gMaximun)
;--- Création de la surface du jeux
OpenWindow(#Main_Windows,0,0,gWidth,gHeight,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Main_Windows),0,0,gWidth,gHeight)
SetWindowTitle(#Main_Windows,"Test de Barre de Vie "+ " touche Spacebar pour le tir")
;--- Dessin du sprite du joueur
CreateSprite(#Player,40,40)
StartDrawing(SpriteOutput(#Player))
Box(0, 0, 40, 40, RGB(255, 0, 0))
StopDrawing()
;--- Dessin du sprite de l'ennemi
CreateSprite(#Ennemy,110,110)
StartDrawing(SpriteOutput(#Ennemy))
Circle(50,50,50,RGB(30, 144, 255))
StopDrawing()
;--- Dessin du sprite du tir du joueur
CreateSprite(#Tir,20,30)
StartDrawing(SpriteOutput(#Tir))
Box(0, 0, 5, 10, RGB(255, 255, 255))
StopDrawing()
;--- Création de la barre de vie
gLifeMaxi = 250
gLife.i = gLifeMaxi
gLifeBar = CreateSprite(#PB_Any, 200, 24)
;--- Création du joueur
Player\Posx=370
Player\Posy=530
;--- Création de l'ennemi
Ennemy\Posx=350
Ennemy\Posy=80
Ennemy\Life=250
;--- Boucle du programme
Repeat
Repeat
;--- Pour la fenetre
gEvent = WindowEvent()
Select gEvent
Case #PB_Event_CloseWindow
End
EndSelect
Until gEvent=0
;--- Pour la partie 2D
ClearScreen(RGB(0, 0, 0))
;-- Affichage de la barre de vie( On appelle notre procédure)
DisplayProgressBar(gLifeBar, 300, 10, gLife, gLifeMaxi)
;--- Affichage du sprite du joueur
DisplaySprite(#Player,Player\Posx,Player\Posy)
;---Affichage du sprite de l'ennemi
If gLife>0
DisplaySprite(#Ennemy,Ennemy\Posx,Ennemy\Posy)
EndIf
;---Affichage des tirs du joueur
ForEach Tir()
Tir()\Posy-2
If Tir()\Posy<0
FreeSprite(Tir()\Sprite)
DeleteElement(Tir(),#True)
Else
DisplayTransparentSprite(Tir()\Sprite,Tir()\Posx,Tir()\Posy)
;--- Collision avec le tir et l'ennemi
If Ennemy\Life>0 And SpriteCollision(#Ennemy,Ennemy\Posx,Ennemy\Posy,Tir()\Sprite,Tir()\Posx,Tir()\Posy)
FreeSprite(Tir()\Sprite)
DeleteElement(Tir(),#True)
;--- barre de vie
If gLife>0
gLife-10
Ennemy\Life-10
ElseIf Ennemy\Life=0 And gLife=0
FreeSprite(#Ennemy)
EndIf
EndIf
EndIf
Next
ExamineKeyboard()
;--- Si on appuie sur la barre d'espacement on tir sur l'ennemi
If KeyboardPushed(#PB_Key_Space) And gShootReady=#True
AddElement(Tir())
Tir()\Sprite=CopySprite(#Tir,#PB_Any)
Tir()\Posx=Player\Posx+SpriteWidth(#Player)/2-SpriteWidth(Tir()\Sprite)/2
Tir()\Posx=390
Tir()\Posy= 510
gShootTime=ElapsedMilliseconds()
EndIf
If ElapsedMilliseconds()-gShootTime>300
gShootReady=#True
Else
gShootReady=#False
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
;---Procédure pour la barre de vie
Procedure DisplayProgressBar(Sprite, x, y, gValue, gMaximum)
;--- Variables de cette procédure :
Protected Width.i = SpriteWidth(Sprite)
Protected Height.i = SpriteHeight(Sprite)
Protected Coef.f = Width/gMaximum
Protected Index.i = gValue * Coef
Protected Text.s, TextWidth.i, TextHeight.i
StartDrawing(SpriteOutput(Sprite))
DrawingMode(#PB_2DDrawing_Transparent)
;---Dessin du fond
Box(0, 0, Width, Height, RGB(128, 128, 128))
;---Dessin de l'index
Box(0, 0, Index, Height, RGB(255, 0,0))
;--Dessin du pourcentage
Text = Str(100 * Index / gMaximum / Coef) + "%"
TextWidth = TextWidth(Text)
TextHeight= TextHeight(Text)
DrawText((Width - TextWidth)/2, (Height - TextHeight)/2, Text, RGB(255, 255, 255))
;--Dessin du contour
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, Width, Height, RGB(0, 0, 0))
StopDrawing()
;--Affichage du sprite
DisplaySprite(Sprite, x, y)
EndProcedure