embryon de jeu de plateforme 2D

Programmation avancée de jeux en PureBasic
hackotedelaplaque
Messages : 121
Inscription : mer. 21/janv./2004 22:18

embryon de jeu de plateforme 2D

Message par hackotedelaplaque »

je vous soumets un petit code.
Il y a encore beaucoup à faire, et le saut est complètement bogué je le sais mais je compte m'y mettre sérieusement dès qu'il fera trop froid pour aller à la plage ! :-)

y'a deux fichiers source.

Voici le 1er :

Code : Tout sélectionner

;- init libs

InitSprite() : InitKeyboard()

IncludeFile"data.pb"


;- constantes

Enumeration
  
  #spr_mario_droite
  #spr_mario_marche_droite
  #spr_mario_marche_droite2
  #spr_mario_saute_droite
  
  #spr_mario_gauche
  #spr_mario_marche_gauche
  #spr_mario_marche_gauche2
  #spr_mario_saute_gauche
  
  #spr_bloc
  
EndEnumeration

;-  structures

Structure tile
  x.w
  y.w
EndStructure

Structure objet Extends tile
  frame.w
  vitesse.b
  dir_droite.b
  anim.w
  saut.w
  
  
EndStructure


;- variables

Global mario.objet

mario\frame = #spr_mario_droite
mario\x = 64
mario\y = 64
mario\vitesse = 1
mario\dir_droite = 1
mario\anim = 0
mario\saut = 0

;- tableaux

Dim bloc.tile(65)



;- Affichage


OpenScreen(1024, 768, 16, "Mario_PureCode")



TransparentSpriteColor(-1, 255, 0, 255)

;- Sprites

CreateSprite(#spr_mario_droite, 64, 64)

For ligne = 0 To 15
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_droite))
      Box(colonne * 4, ligne * 4, 4, 4, couleur) ; 4= facteur de zoom
    StopDrawing()
    
  Next colonne
Next ligne

CreateSprite(#spr_mario_marche_droite, 64, 64)

For ligne = 0 To 15
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_marche_droite))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne

CreateSprite(#spr_mario_marche_droite2, 64, 64)

For ligne = 0 To 15
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_marche_droite2))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne


CreateSprite(#spr_mario_saute_droite, 64, 64)

For ligne = 0 To 15
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_saute_droite))
      Box(colonne * 4, ligne * 4, 4, 4, couleur) ; 4= facteur de zoom
    StopDrawing()
    
  Next colonne
Next ligne


CreateSprite(#spr_mario_gauche, 64, 64)
Restore pixel :
For ligne = 0 To 15
  For colonne = 15 To 0 Step - 1
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_gauche))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne


CreateSprite(#spr_mario_marche_gauche, 64, 64)
For ligne = 0 To 15
  For colonne = 15 To 0 Step - 1
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_marche_gauche))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne

CreateSprite(#spr_mario_marche_gauche2, 64, 64)
For ligne = 0 To 15
  For colonne = 15 To 0 Step - 1
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_marche_gauche2))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne


CreateSprite(#spr_mario_saute_gauche, 64, 64)
For ligne = 0 To 15
  For colonne = 15 To 0 Step - 1
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge
    
    StartDrawing(SpriteOutput(#spr_mario_saute_gauche))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne


CreateSprite(#spr_bloc, 64, 64)

For ligne = 0 To 14
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence
    If pixel = 1 : couleur = RGB(240, 120, 10) : EndIf ; 1 = brique
    If pixel = 2 : couleur = RGB(250, 210, 190) : EndIf ; 2 = pastel
    If pixel = 3 : couleur = RGB(0, 0, 0) : EndIf ; 3 = noir
    
    StartDrawing(SpriteOutput(#spr_bloc))
      Box(colonne * 4, ligne * 4, 4, 4, couleur)
    StopDrawing()
    
  Next colonne
Next ligne





;- Boucle principale

Repeat
  
  ClearScreen(0, 150, 255)
  
  ExamineKeyboard()
  
  Gosub level :
  
  Gosub move :
  
  DisplayTransparentSprite(mario\frame, mario\x, mario\y)
  
  FlipBuffers(0)
  
  
  
Until KeyboardPushed(#PB_Key_Escape)

End


;- Subroutines

level :

Restore map :
n = 0
For ligne = 0 To 11
  For colonne = 0 To 15
    Read map
    If map
      DisplaySprite(#spr_bloc, 64 * colonne, 64 * ligne) ; 64 = taille bloc
      bloc(n)\x = colonne * 64
      bloc(n)\y = ligne * 64
      n + 1
    EndIf
  Next colonne
Next ligne

Return

move :

If KeyboardPushed(#PB_Key_Right)
  
  
  If mario\anim > 0 And mario\anim < 40
    mario\frame = #spr_mario_marche_droite
  EndIf
  
  If mario\anim > 40 And mario\anim < 80
    mario\frame = #spr_mario_marche_droite2
  EndIf
  
  
  If mario\anim = 80
    mario\anim = 0
  EndIf
  
  mario\anim + 1
  mario\x + mario\vitesse
  mario\dir_droite = 1
  
  ; detection de collisions latérales
  For n = 0 To 64
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y)
      mario\x = bloc(n)\x - 64
      mario\frame = #spr_mario_droite
    EndIf
  Next
  
EndIf

If KeyboardReleased(#PB_Key_Right)
  mario\anim = 0
  mario\frame = #spr_mario_droite
EndIf

If KeyboardPushed(#PB_Key_Left)
  
  
  
  If mario\anim > 0 And mario\anim < 40
    mario\frame = #spr_mario_marche_gauche
  EndIf
  
  If mario\anim > 40 And mario\anim < 80
    mario\frame = #spr_mario_marche_gauche2
  EndIf
  
  
  If mario\anim = 80
    mario\anim = 0
  EndIf
  
  mario\anim + 1
  
  
  
  mario\x - mario\vitesse
  mario\dir_droite = 0
  
  
  ; detection de collisions latérales
  For n = 0 To 64
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y)
      mario\x = bloc(n)\x + 64
      mario\frame = #spr_mario_gauche
      
    EndIf
  Next
  
EndIf

If KeyboardReleased(#PB_Key_Left)
  mario\anim = 0
  mario\frame = #spr_mario_gauche
EndIf

If KeyboardPushed(#PB_Key_Left) And KeyboardPushed(#PB_Key_right)
  mario\frame = #spr_mario_droite
EndIf



;- gravite


mario\y + 1


For n = 0 To 64
  If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y)
    mario\y = bloc(n)\y - 64
    mario\saut = 0
    
    
    If mario\frame = #spr_mario_saute_droite
      mario\frame = #spr_mario_droite
    EndIf
    
    If mario\frame = #spr_mario_saute_gauche
      mario\frame = #spr_mario_gauche
    EndIf
    
  EndIf
Next


If KeyboardPushed(#PB_Key_Up)
  
  
  
  
  If mario\dir_droite = 1
    mario\frame = #spr_mario_saute_droite
  Else
    mario\frame = #spr_mario_saute_gauche
  EndIf
  
  If mario\saut < 100
    mario\y - 2
  EndIf
  
  
  mario\saut + 1
  
  For n = 0 To 64
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y)
      mario\y = bloc(n)\y + 64
    EndIf
  Next
  
EndIf


Return

Et voilà le fichier data.pb nécessaire (ce sont les sprites et la map)

Code : Tout sélectionner

;- Datasections
DataSection
  
  pixel :
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_droite et gauche
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 4, 4, 2, 4, 4, 4, 0, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 0, 0, 0
    Data.l 0, 0, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0
    Data.l 0, 0, 3, 3, 4, 2, 1, 2, 2, 1, 2, 4, 3, 3, 0, 0
    Data.l 0, 0, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 0, 0
    Data.l 0, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 0
    Data.l 0, 0, 0, 0, 2, 2, 2, 0, 0, 2, 2, 2, 0, 0, 0, 0
    Data.l 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0
    Data.l 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0
  
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_marche_droite et gauche
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0
    Data.l 0, 0, 4, 4, 4, 4, 2, 2, 4, 4, 0, 0, 0, 0, 0, 0
    Data.l 3, 3, 4, 4, 4, 4, 2, 2, 2, 4, 4, 4, 3, 3, 3, 0
    Data.l 3, 3, 3, 0, 4, 4, 2, 1, 2, 2, 2, 4, 4, 3, 3, 0
    Data.l 3, 3, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0
    Data.l 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0
    Data.l 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0
    Data.l 0, 1, 1, 2, 2, 2, 0, 0, 0, 2, 2, 2, 1, 1, 0, 0
    Data.l 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    Data.l 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_marche_droite2 et gauche2
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 4, 4, 2, 4, 4, 4, 0, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 4, 4, 4, 4, 2, 2, 4, 4, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 4, 4, 4, 2, 2, 1, 2, 2, 1, 0, 0, 0, 0
    Data.l 0, 0, 0, 4, 4, 4, 4, 2, 2, 2, 2, 2, 0, 0, 0, 0
    Data.l 0, 0, 0, 2, 4, 4, 3, 3, 3, 2, 2, 2, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 2, 4, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
  
  
    Data.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3 ; mario_saute_droite et gauche
    Data.l 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 3, 3, 3
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 4, 4, 4
    Data.l 0, 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 4, 4, 4
    Data.l 0, 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 4
    Data.l 0, 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 1, 0
    Data.l 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 1, 0, 0
    Data.l 0, 0, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 0, 0, 0
    Data.l 0, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 0, 0, 1
    Data.l 3, 3, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 0, 0, 1
    Data.l 3, 3, 3, 0, 2, 2, 4, 2, 2, 1, 2, 2, 1, 2, 1, 1
    Data.l 0, 3, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1
    Data.l 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1
    Data.l 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0
    Data.l 0, 1, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0
  
  
    Data.l 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 1, 2, 2, 2, 2, 1 ; bloc
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 3, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, 1
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2, 2, 2, 2, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3
    Data.l 3, 3, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3
    Data.l 2, 2, 3, 3, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3
    Data.l 2, 1, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, 1, 3
    Data.l 2, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3, 3
    Data.l 1, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 3, 3, 1
  
  
  map :
  
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ; carte du niveau
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.l 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1
    Data.l 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.l 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1
    Data.l 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1
    Data.l 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1
    Data.l 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.l 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  
EndDataSection
voilà ! :D
10 CLS
20 PRINT "Vive PureBasic"
30 GOTO 20
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

amusant ;)
un peu lent sur mon 500mhz tout de même

et en appuyant plusieurs fois de suite sur la touche haut, on peut ralentir la chute de mario

la partie à modifier : (à la fin du prog)
j'ai ajouté dans le test mario\saut = 0 pour continuer le saut jusqu'à sa fin :wink:

Code : Tout sélectionner

If KeyboardPushed(#PB_Key_Up) or [b]mario\saut = 0[/b]
  
  If mario\dir_droite = 1 
    mario\frame = #spr_mario_saute_droite 
  Else 
    mario\frame = #spr_mario_saute_gauche 
  EndIf 
  
  If mario\saut < 100
    mario\y - 2 
  EndIf 
   
  mario\saut + 1
  
  For n = 0 To 64 
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y) 
      mario\y = bloc(n)\y + 64 
    EndIf 
  Next 
  
EndIf 
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

Pas mal ta démo , effectivement ça fonctione comme tu le disais :)

Voici une première version de la mienne ( 77 ko ) sans les sources ,je vais encore arranger deux trois trucs avant de les joindre.

Ceci dit ce n'est pas un secret d"état , si ça intéresse quelqu'un , je peux les mettre à disposition tel quel , je les corrigerai après.

http://perso.wanadoo.fr/comtois/sources ... eBeta1.zip
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

super comtois !!! j'adore le perso qui fait mine de tomber au bord des cubes !!

si vous poursuivez dans ce genre faite en sorte que le saut soit commandé par la touche "espace" par exemple !!

car il est plus simple de sauter avec la main gauche pendant que l'on maitrise le perso avec la main droite (fleche droite et gauche)
generalement c'est ce qu'on fait dans ce type de jeux !!
ou tu du moin prevoyez une redefinition possible des touches de commandes !!
dans le genre y en a un que j'aime beaucoup il s'appelle "Charlie the Duck" :D
hackotedelaplaque
Messages : 121
Inscription : mer. 21/janv./2004 22:18

Message par hackotedelaplaque »

Soldat inconnu > effectivement si mon mario tombe sans que j'ai pressé la touche saut je peux ralentir la chutte en pressant celle-ci, ce qui n'est pas du tout réaliste en effet. Mais ce n'est qu'en embryon, je n'ai pas réfléchi encore à l'implémentation de la gravité.
par contre si je modifie le code comme tu le dis, j'ai un bogue, le sprite "mario_saut" étant systématiquement affiché. Ca doit s'arranger facilement.
2/ tu dis que c'est lent sur un 500 mais j'ai la même config pratiquement. N'aurais-tu pas enlevé le paramètre "0" dans flipbufers par hasard ?
3/ Hors sujet, mais si je devais te donner 1 € à chaque utilisation de ton PureSyntax tu serais milliardaire ! je serais curieux de savoir comment ça marche cette petite bête là !

Comtois> Bien sûr que ça m'intéresse ton code source !!!! Elle est terrible ta démo, j'ai apprécié en particulier la précision dans la gestion des collisions lorsque le sprite est en équilibre sur le rebord de la plateforme.
Ta technique me semble meilleure en effet :cry:

La gravité semble nickel.
Juste une fois le sprite a traversé une plateforme mais je n'ai pas réussi à reproduire cette erreur, j'ai peut-être mal vu.

Ca blaze un peu quand on voit ce qu'on fait et ce que savent faire les autres !!! :oops:

Au sujet des jeux de plateforme, est-ce que quelqu'un sait comment faire un "scroling" ?
Ma map et la tienne Comtois sont statiques sur un écran unique.
Faut-il faire pareil mais avec une map beaucoup plus large que l'écran et dont les coordonnées en x diminuent au fur et à mesure que le sprite du joueur avance en X ?
Si oui n'est-ce pas un gaspillage mémoire de dessiner des choses hors de l'écran plutôt qu'au fur et à mesure ?
Bref je sais pas trop comment faire.

Mais j'en suis pas là, je veux une bonne gestion de la gravité d'abord ! J'ai quelques idées (à savoir :
- que plus la chutte est longue plus elle accélère
- prise en charge des frictions dans les airs
- notion d'élan en fonction de la vitesse avant le saut
10 CLS
20 PRINT "Vive PureBasic"
30 GOTO 20
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Va faire un tour sur le site de Pollux, il a justement fait un tuto sur les scrollings.

http://perso.wanadoo.fr/darkprograms/pb ... /tuts.html

Au sujet de la gravité, j'ai trouvé ça. C'est en anglais, mais j'ai pas autre chose. (A croire que les Français ne savent pas faire de tutoriels, ou qu'ils préfèrent se regarder le nombril :x )
Gravity Faq

The information contained in document will allow you to realistically
simulate jumping and interstellar maneuvers.

The purpose of this document is to understand the physics of the
world we live in, and apply realistic physics to your game. It
will not give you optimized routines for your program, that is your
job! But if you understand how things work, it will be a heck of
a lot easier.

=====================================================================
= Basics
=====================================================================

There are some key terms I will define to make sure we are talking
about the same things:

Distance : Total path of travel.
Displacement: Difference between original position, and final position

Speed : Change in displacement divided by the change in time
Velocity : Direction of travel, and speed of travel.

Acceleration: Change in velocity divided by the change in time.

Force :

Note: That displacement, velocity, and acceleration are actually
vector quantities. (That is, they have a direction and magnitude).

Abbreviations:

a : acceleration
M : mass
s : displacement
s0 : initial displacement
t : time
v : velocity
v0 : initial velocity

units
m : meter (unit of length)
m/s : meter per second (unit of speed)
m/s^2 : meter per second squared (unit of acceleration)
N : Newtons (unit of force)
s : second (unit of time)

=====================================================================
= The concepts
=====================================================================

Imagine a spaceship flying through space at 1000 m/s. It is deep in
interstellar space with nothing around it. What forces are acting
on it? The answer: none!
It will continue to fly through space at 1000 m/s forever if no
force acts on it.

: The ONLY reason why objects will change velocity (direction and/or
: speed) is if a force is applied to it.

What is a force you ask? A force is an external push or pull. A
force is also a vector. It has a magnitude and a direction
associated with it. Right now gravity is exerting a force on you:
it is pulling you toward the center of the earth.

Also, the only reason an object will change displacement is if
it has some velocity.

Suppose now that the hand of god reaches down and starts pushing the
spaceship forward. There is now a force applied to the ship. With
any force applied, an acceleration is induced. With our new
acceleration, the velocity starts to increase. If god doesn't stop
pushing the ship, then soon the ship will go very fast!


=====================================================================
= Look, I just want to make my guy jump.
=====================================================================

Ok, I'm getting to this. We have our jumping dude Joe. Joe's
initial position is on the floor or platform that is not moving.
The user presses a key and Joe should leap into the air. You need
to keep track of three things about Joe: His position, velocity,
and acceleration.

Initially, his position will be at the floor. Once the key is hit,
we simply give Joe a very fast velocity in the upward direction.
Then every frame/sec/update/whatever decrease his upward velocity
by a constant amount. That's it!

The constant decrease is actually an acceleration in the downward
direction. The horizontal motion of Joe is unaffected. So while
Joe is flying through the air, you can change his forward/backward
movement as normal.

Side note: In real life, it is impossible to move forward/backward
when jumping straight up. But I find games that allow forward/
backward movement while jumping more playable and fun than just jumping
straight up. And who said games are realistic anyway?

What should be the acceleration that we are applying? On earth, the
acceleration of Joe will be 9.81 m/s^2 in the downward direction.
Unfortunately, meters per second squared means nothing to the computer.
The acceleration must be determined based on your game's update rate.
Usually guessing and tweaking is the best way to achieve this.

So our pseudo-code is as such:

Joe.pos.y = 0; (Or wherever floor is)
Joe.vel.y = 0;
Joe.accel = 10;
Joe.jumping = NO;

Loop
If (jump key is pressed)
{
Joe.vel.y = 100;
Joe.jumping = YES;
}

if (Joe.jumping == YES) /* Move Joe if we are jumping */
{
Joe.vel.y = Joe.vel.y - Joe.accel
Joe.pos.y = Joe.pos.y + Joe.vel.y
}

if (Joe.pos.y <= 0) /* Check to see if Joe has hit floor */
{
Joe.vel.y = 0;
Joe.jumping = NO;
}
End Loop

For the first time the jump key is pressed, the position of Joe will
suddenly jump off the floor.

As he goes higher, Joe begins to slow down because the velocity
is constantly decremented. Joe will eventually stop moving up, and
begin to move down. He will move faster and faster until
he reaches the floor again.

Joe's velocity and position in the y direction at the end of each loop
will appear as such:

Loop0 : Joe.vel.y = 0 Joe.pos.y = 0
Loop1 : Joe.vel.y = 100 Joe.pos.y = 100
Loop2 : Joe.vel.y = 90 Joe.pos.y = 190
Loop3 : Joe.vel.y = 80 Joe.pos.y = 270
Loop4 : Joe.vel.y = 70 Joe.pos.y = 340
Loop5 : Joe.vel.y = 60 Joe.pos.y = 400
Loop6 : Joe.vel.y = 50 Joe.pos.y = 450
Loop7 : Joe.vel.y = 40 Joe.pos.y = 490
Loop8 : Joe.vel.y = 30 Joe.pos.y = 520
Loop9 : Joe.vel.y = 20 Joe.pos.y = 540

Loop10: Joe.vel.y = 10 Joe.pos.y = 550
Loop11: Joe.vel.y = 0 Joe.pos.y = 550
Loop12: Joe.vel.y = -10 Joe.pos.y = 540
Loop13: Joe.vel.y = -20 Joe.pos.y = 520
Loop14: Joe.vel.y = -30 Joe.pos.y = 490
Loop15: Joe.vel.y = -40 Joe.pos.y = 450
Loop16: Joe.vel.y = -50 Joe.pos.y = 400
Loop17: Joe.vel.y = -60 Joe.pos.y = 340
Loop18: Joe.vel.y = -70 Joe.pos.y = 270
Loop19: Joe.vel.y = -80 Joe.pos.y = 190
Loop20: Joe.vel.y = -90 Joe.pos.y = 100
Loop21: Joe.vel.y =-100 Joe.pos.y = 0

Notice that Joe is going very fast when he hits the floor.
If Joe does not hit the floor, or the floor disappears (i.e. he jumps
off a platform) then eventually Joe will be going very fast.

We need to give him a limiting velocity. This is the fastest velocity
Joe can go by falling. In real life this is caused by air resistance.
This is easy enough to do.

The modified pseudo-code is such:

Joe.pos.y = 0; (Or wherever floor is)
Joe.vel.y = 0;
Joe.accel = 10;
Joe.jumping = NO;

Loop
if (jump key is pressed)
{
Joe.vel.y = 100;
Joe.jumping = YES;
}

if (Joe.jumping == YES) /* Move Joe if we are jumping */
{
if (Joe.vel.y > -100) /* Limit Joe's velocity to -100 */
{
Joe.vel.y = Joe.vel.y - Joe.accel
Joe.pos.y = Joe.pos.y + Joe.vel.y
}
}

if (Joe.pos.y <= 0) /* Check to see if Joe has hit floor */
{
Joe.vel.y = 0;
Joe.jumping = NO;
}
End Loop

The added loop will not decrease Joe's velocity if he is already moving
downward at a speed of -100. Thus we have added his limiting velocity.

=====================================================================
= Other dimensions
=====================================================================

Ok, the above example is all well and good, but some game sprites
do not just go up and down. Some go side to side while they are
jumping.

Easy! It just so happens that the x and y values of velocity and
acceleration are independent! So while you resolve the y position
and velocity of Joe, you can move Joe in the x direction normally.

It will appear that Joe follows a parabolic path, which is what he
would follow in the real world.

The same goes for 3 dimensions. x,y,z velocities and accelerations are
all independent of one another.

=====================================================================
= Spaceman Spiff
=====================================================================

Another example where kinematics applies is an asteroids type game.
You fly around in a zero-g environment, but can thrust forward in
any direction.

In this case gravity is not a factor. What do we use instead? We
use the thrust of the spaceship as our acceleration. We simply break
up our acceleration vector into x and y directions, and apply the same
techniques as above.

To implement this we get the pseudo-code:

pos.x = 0; pos.y = 0;
vel.x = 0; vel.y = 0;
acc.x = 0; acc.y = 0;

Loop
if (thrust key pressed)
{
resolve_direction_vector;
acc.x = scale_x * 10;
acc.y = scale_y * 10;
}

vel.x = vel.x + acc.x;
vel.y = vel.y + acc.y;

pos.x = pos.x + vel.x;
pos.y = pos.y + vel.y;
End Loop

Now we have a step we have not seen before: resolve_direction_vector.
We need this because the ship can move in any direction.
What this step does is get the appropriate directions vector and
break it down into an x vector and y vector. Once broken down, the
resolve_direction_vector step will set scale_x and scale_y.

/^
Original / |
acceleration / |
vector / |
/ |
/ | Y vector
/ |
Start / * |
position -> X------->|

X vector

* = Angle of ship measured from x axis

Given an angle for our direction from 0 to 365, we can determine
the scale_x and scale_y variables. There are various ways to
do this, but an easy way (not optimized) is to use trig:

scale_x = cos(angle);
scale_y = sin(angle);

The trig functions will take care of negative values. That is, if
the ship is facing West (angle = 180 degrees), the values for
scale_x and scale_y: scale_x = -1; scale_y = 0;
And our ship will accelerate in the negative x direction.

How about if the ship is pointed in a Northeast direction (angle = 45)?
We get:
scale_x = .707
scale_y = .707

Which means the ship is accelerating by 7.07 in the y direction, and
by 7.07 in the x direction. The illusion you see the ship
accelerate by 10 in a 45 degree direction.

You will want to limit the maximum velocity of the ship, or else
it will soon be going faster than the user can see.

If you want, some people like a damping field. That means eventually,
the ship slows down by itself. To do this, simply decrement the
velocity towards zero every loop. (e.g. if velocity is positive,
subtract; if velocity is negative, add)

=====================================================================
= The REAL equations
=====================================================================

This section explains the real equations. If you wish to do some
more complex kinematics, this section will give you everything you
need to resolve the equations. If not, then the above text is
plenty for a lot of applications. For more explanations, consult
a basic physics book.

We define three key variables with respect to an object:
displacement, velocity, and acceleration.

Force is related to acceleration in the following way:
(Incidentally, Newton's second law of motion)

;Eqn 1
;
; F = M * a
;
In English: Force equals mass times acceleration.

So in our spaceship example, the hand of god can cause a small
interceptor with little mass to accelerate faster than a huge
dreadnought with much mass.

The relationship between displacement, velocity, and acceleration
are:

;Eqn 2
;
; s = s0 + v0*t + 0.5*a*t^2
;
The current displacement is equal to the initial displacement, plus
the velocity times time, plus one-half times acceleration times
time squared.

;Eqn 3
;
; v = v0 + a*t
;
The current velocity equals the initial velocity plus acceleration
times time.

;Eqn 4
;
; v^2 - v0^2 = 2*a*s
;
The current velocity squared minus the initial velocity equals two
times acceleration time displacement.

With these 4 magic equations, almost all physics motion problems
can be resolved.
These equations are all based on constant acceleration (which fits
in fine with most computer applications)

=====================================================================
= How do these equations work?
=====================================================================

Let us take a ball thrown directly up into the air. This is a
one-dimensional situation, because the ball is only going up or
down. Let's take s0 to be the position where we release the ball
up into the air. Since we have an initial position, I'm going to
be referring to the current displacement of the ball as position.
The term position will be reference from s0.

Ok, so we throw the ball up into the air. The instant we release
the ball (t = 0) we know:
s0 = 0;
v0 = 10 m/s in the up direction (about 22 miles per hour)
a = ?

Hmm. What is the acceleration? For any object near the earth's
surface, the force due to gravity can be found with:
;Eqn 5
;
; Fg = M*g
;
Where M is the mass and g is the gravitational constant.
For earth, g = 9.81 m/s^2.

A bit of math now. Combine Eqns 1 & 5
;
; Fg = M*a -> M*g = M*a -> g = a
;
Whoa! The masses seem to have canceled! That's interesting. For
any falling object, the acceleration is not affected by the mass.
Does this mean that a hippo will fall as fast as a Ping-Pong ball?
Yes they will: in a vacuum. But I digress...

So the acceleration of the ball equals g, or 9.81 m/s^2.
But the acceleration is in the DOWNWARD direction, so we say a = -g

Using Eqn 3, we get:
v = v0 + a*t = 10 m/s + (-9.81 m/s^2) * 0 s = 10 m/s.
If we use Eqn 2, we also get s = 0. Big deal, huh?

Let's take a look at 0.5 sec later:
v = 10 + (-9.81) * 0.5 s = 5.1 m/s

The ball has slowed down, which is what we expect. Eventually it
will stop. To find this, we simply set v = 0 and solve for t.
v = 0 = 10 + (-9.81) * t
Solving for t, we find t = 1.019 seconds. Thus 1.019 seconds after
we throw the ball up, it stops in mid-air.

Ok, we know it stops, but where is it? To find this, we use Eqn 2:
s = 0 + 10 * 1.019 + 0.5 * (-9.81) * 1.019^2 = 5.1 meters
That is 5.1 meters above the spot where we released it.

What goes up must come down, but how fast? How fast is our ball
going when we catch it? When we catch the ball, we know that
s = 0. So use Eqn 4. After some calculations, we find
v = sqrt( v0^2 ). That's easy, right? v = v0. Well...sort of.

There is actually two solutions to this equation. +v0 and -v0.
What does this mean? It means whenever the ball is at position
s = 0, then it is either going up at v0 or down at v0. Since
we know it was going up when we threw it, it must be coming down
at the same velocity.

The last thing we find is what time it comes down:
Use Eqn 3:
v = -v0 = v0 + (-9.81) * t
Result: t = 2.038 seconds. If we throw a ball up at 10 m/s, then
2.038 seconds later, we will find the same ball in our hand.

This section was just to show how the equations work. In an
actual program, you wouldn't simply stick these equations in because
you would have to keep track of t for every single object. Every time
something jumped, you'd reset that object's personal t.


=====================================================================
= Hasta La Vista, dudes
=====================================================================

Well, that's it. Hope this gives you enough information to start out.

If you have questions, suggestions, clarifications, and any other
modifications, please drop me a line.

Edgar Roman

eroman@nmsu.edu
or (aroman@nmsu.edu)

First Release: 12/29/94
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

hackotedelaplaque je suis comme toi , avant de songer à faire du scrolling , je voudrais d'abord avoir une bonne gestion du personnage .
il manque pas mal d'animations ( tir , accrochage aux rebords des plateformes , etc .. ) , et il faudrait déjà que je finisse de mettre au propre celles qui existent .

Mais tu as raison , il faudrait peut-être aussi penser au scrolling dès le départ pour ne pas avoir à tout casser plus tard :)

enfin , c'est pas grave , pour moi l'objectif c'était de bouger le perso sur une vue statique :)

le scrolling ,si je le fais , ça sera un bonus .

bon , je te prépare le source , tel qu'il est ,c'est à dire en désordre et pas trop commenté :?
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

Chris a écrit :Au sujet de la gravité, j'ai trouvé ça. C'est en anglais, mais j'ai pas autre chose. (A croire que les Français ne savent pas faire de tutoriels, ou qu'ils préfèrent se regarder le nombril
Tu pourrais nous le traduire hein dit ? :)


La loi Toubon est encore en rigueur ou pas ? il n'est pas interdit d'importer un document en France sans qu'il soit traduit ? :)
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Tu pourrais nous le traduire hein dit ?
Et puis quoi encore!!! :lol:
La loi Toubon est encore en rigueur ou pas ? il n'est pas interdit d'importer un document en France sans qu'il soit traduit ?
Je n'importe pas, je redirige. Si tu veux une traduction, demande à Toubon :lol:
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

> hackotedelaplaque : pour le scrolling, vu comment est réalisé ton code, je ferai comme ça :
une carte plus grande que l'écran, 2 variable qui permettent de gérer la position de la carte, et on affiche seulement les cube qui sont l'écran
v essayer de modifier ton code vite fait
c'est relativement simple à faire je pense (surtout avec pure ;) ) turbo pascal, c'était autrement plus compliqué

au fait, j'ai écrit une annerie dans ma correction, j'ai mis = 0 au lieu de <> 0 :oops:

ça donne ça :

Code : Tout sélectionner

If KeyboardPushed(#PB_Key_Up) or [b]mario\saut = 0[/b] 
  
  If mario\dir_droite = 1 
    mario\frame = #spr_mario_saute_droite 
  Else 
    mario\frame = #spr_mario_saute_gauche 
  EndIf 
  
  If mario\saut < 100 
    mario\y - 2 
  EndIf 
    
  mario\saut + 1 
  
  For n = 0 To 64 
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, bloc(n)\x, bloc(n)\y) 
      mario\y = bloc(n)\y + 64 
    EndIf 
  Next 
  
EndIf
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

un scrolling vite fait et très simple

Code : Tout sélectionner

;- init libs 

InitSprite() : InitKeyboard() 

;- Datasections 
DataSection 
  
  pixel : 
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_droite et gauche 
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0 
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0 
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 4, 4, 2, 4, 4, 4, 0, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 0, 0, 0 
    Data.l 0, 0, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0 
    Data.l 0, 0, 3, 3, 4, 2, 1, 2, 2, 1, 2, 4, 3, 3, 0, 0 
    Data.l 0, 0, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 0, 0 
    Data.l 0, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 0 
    Data.l 0, 0, 0, 0, 2, 2, 2, 0, 0, 2, 2, 2, 0, 0, 0, 0 
    Data.l 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 
    Data.l 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 
  
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_marche_droite et gauche 
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0 
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0 
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 
    Data.l 0, 0, 4, 4, 4, 4, 2, 2, 4, 4, 0, 0, 0, 0, 0, 0 
    Data.l 3, 3, 4, 4, 4, 4, 2, 2, 2, 4, 4, 4, 3, 3, 3, 0 
    Data.l 3, 3, 3, 0, 4, 4, 2, 1, 2, 2, 2, 4, 4, 3, 3, 0 
    Data.l 3, 3, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0 
    Data.l 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0 
    Data.l 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0 
    Data.l 0, 1, 1, 2, 2, 2, 0, 0, 0, 2, 2, 2, 1, 1, 0, 0 
    Data.l 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
    Data.l 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
  
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0 ; mario_marche_droite2 et gauche2 
    Data.l 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0 
    Data.l 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0, 0 
    Data.l 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 0, 0 
    Data.l 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 4, 4, 2, 4, 4, 4, 0, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 4, 4, 4, 4, 2, 2, 4, 4, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 4, 4, 4, 2, 2, 1, 2, 2, 1, 0, 0, 0, 0 
    Data.l 0, 0, 0, 4, 4, 4, 4, 2, 2, 2, 2, 2, 0, 0, 0, 0 
    Data.l 0, 0, 0, 2, 4, 4, 3, 3, 3, 2, 2, 2, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 2, 4, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 
  
  
    Data.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3 ; mario_saute_droite et gauche 
    Data.l 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 3, 3, 3 
    Data.l 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3 
    Data.l 0, 0, 0, 0, 0, 1, 1, 1, 3, 3, 1, 3, 0, 4, 4, 4 
    Data.l 0, 0, 0, 0, 1, 3, 1, 3, 3, 3, 1, 3, 3, 4, 4, 4 
    Data.l 0, 0, 0, 0, 1, 3, 1, 1, 3, 3, 3, 1, 3, 3, 3, 4 
    Data.l 0, 0, 0, 0, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 1, 0 
    Data.l 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 1, 0, 0 
    Data.l 0, 0, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 0, 0, 0 
    Data.l 0, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 0, 0, 1 
    Data.l 3, 3, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 0, 0, 1 
    Data.l 3, 3, 3, 0, 2, 2, 4, 2, 2, 1, 2, 2, 1, 2, 1, 1 
    Data.l 0, 3, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1 
    Data.l 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1 
    Data.l 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0 
    Data.l 0, 1, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0 
  
  
    Data.l 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 1, 2, 2, 2, 2, 1 ; bloc 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 3, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, 1 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2, 2, 2, 2, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 3 
    Data.l 3, 3, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3 
    Data.l 2, 2, 3, 3, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3 
    Data.l 2, 1, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, 1, 3 
    Data.l 2, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3, 3 
    Data.l 1, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 3, 3, 1 
  
  
  map : 
  
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ; carte du niveau 
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 
    Data.l 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1 
    Data.l 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 
    Data.l 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1 
    Data.l 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1 
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 
    Data.l 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1 
    Data.l 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1 
    Data.l 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 
    Data.l 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 
  
EndDataSection


;- constantes 

Enumeration 
  
  #spr_mario_droite 
  #spr_mario_marche_droite 
  #spr_mario_marche_droite2 
  #spr_mario_saute_droite 
  
  #spr_mario_gauche 
  #spr_mario_marche_gauche 
  #spr_mario_marche_gauche2 
  #spr_mario_saute_gauche 
  
  #spr_bloc 
  
EndEnumeration 

;-  structures 

Structure tile 
  x.w 
  y.w 
EndStructure 

Structure objet Extends tile 
  frame.w 
  vitesse.b 
  dir_droite.b 
  anim.w 
  saut.w 
EndStructure 

;- variables 

Global mario.objet 

mario\frame = #spr_mario_droite 
mario\x = 64 
mario\y = 64 
mario\vitesse = 1 
mario\dir_droite = 1 
mario\anim = 0 
mario\saut = 0 

;- tableaux et variables globales

Dim Bloc.tile(200) 

Global NbBloc.l, PositionMap.POINT, DimensionMap.POINT

;- Affichage 
#EcranX = 800
#EcranY = 600

OpenScreen(#EcranX, #EcranY, 16, "Mario_PureCode") 

;- On charge la map
Restore map
NbBloc = 0 
For ligne = 0 To 11 
  For colonne = 0 To 15 
    Read map
    If map
      Bloc(NbBloc)\x = colonne * 64
      Bloc(NbBloc)\y = ligne * 64
      NbBloc + 1
    EndIf 
  Next colonne 
Next ligne 

; Taille de la map en pixel
DimensionMap\x = 64 * 16
DimensionMap\y = 64 * 12
; Donc la position de la map est comprise ente les points suivants
DimensionMap\x - #EcranX - 1 ; et 0 sur les x
DimensionMap\y - #EcranY - 1 ; et 0 sur les y


;- Création des sprites
Restore pixel

TransparentSpriteColor(-1, 255, 0, 255) 

CreateSprite(#spr_mario_droite, 64, 64) 

For ligne = 0 To 15
  For colonne = 0 To 15 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_droite)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) ; 4= facteur de zoom 
    StopDrawing() 
    
  Next colonne 
Next ligne 

CreateSprite(#spr_mario_marche_droite, 64, 64)

For ligne = 0 To 15 
  For colonne = 0 To 15 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_marche_droite)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 

CreateSprite(#spr_mario_marche_droite2, 64, 64) 

For ligne = 0 To 15 
  For colonne = 0 To 15 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_marche_droite2)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 


CreateSprite(#spr_mario_saute_droite, 64, 64) 

For ligne = 0 To 15 
  For colonne = 0 To 15 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_saute_droite)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) ; 4= facteur de zoom 
    StopDrawing() 
    
  Next colonne 
Next ligne 


CreateSprite(#spr_mario_gauche, 64, 64) 
Restore pixel : 
For ligne = 0 To 15 
  For colonne = 15 To 0 Step - 1 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_gauche)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 


CreateSprite(#spr_mario_marche_gauche, 64, 64) 
For ligne = 0 To 15 
  For colonne = 15 To 0 Step - 1 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_marche_gauche)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 

CreateSprite(#spr_mario_marche_gauche2, 64, 64) 
For ligne = 0 To 15 
  For colonne = 15 To 0 Step - 1 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_marche_gauche2)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 


CreateSprite(#spr_mario_saute_gauche, 64, 64) 
For ligne = 0 To 15 
  For colonne = 15 To 0 Step - 1 
    Read pixel 
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(0, 0, 0) : EndIf ; 1 = noir 
    If pixel = 2 : couleur = RGB(0, 0, 255) : EndIf ; 2 = bleu 
    If pixel = 3 : couleur = RGB(255, 180, 150) : EndIf ; 3 = peau 
    If pixel = 4 : couleur = RGB(255, 0, 0) : EndIf ; 4 = rouge 
    
    StartDrawing(SpriteOutput(#spr_mario_saute_gauche)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 


CreateSprite(#spr_bloc, 64, 64) 

For ligne = 0 To 15
  For colonne = 0 To 15
    Read pixel
    If pixel = 0 : couleur = RGB(255, 0, 255) : EndIf ; 0 = transparence 
    If pixel = 1 : couleur = RGB(240, 120, 10) : EndIf ; 1 = brique 
    If pixel = 2 : couleur = RGB(250, 210, 190) : EndIf ; 2 = pastel 
    If pixel = 3 : couleur = RGB(0, 0, 0) : EndIf ; 3 = noir 
    
    StartDrawing(SpriteOutput(#spr_bloc)) 
      Box(colonne * 4, ligne * 4, 4, 4, couleur) 
    StopDrawing() 
    
  Next colonne 
Next ligne 





;- Boucle principale 

Repeat 
  
  ClearScreen(0, 150, 255) 
  
  ExamineKeyboard() 
  
  Gosub move : 
  
  Gosub level :
  
  ; on affiche tous les objets en les décalant de la position de la map
  DisplayTransparentSprite(mario\frame, mario\x - PositionMap\x, mario\y - PositionMap\y) 
  
  ; déboguage
  StartDrawing(ScreenOutput())
    Locate(10, 10)
    DrawText("Map : " + Str(PositionMap\x) + ", " + Str(PositionMap\y))
    Locate(10, 30)
    DrawText("Mario : " + Str(mario\x) + ", " + Str(mario\y))
  StopDrawing()
  
  FlipBuffers() 

Until KeyboardPushed(#PB_Key_Escape) 

End 


;- Subroutines 

level : 

; on positione la map pour avoir mario au centre de l'écran, donc on décale la position de la map de la taille de l'écran / 2
PositionMap\x = mario\x - #EcranX / 2
PositionMap\y = mario\y - #EcranY / 2
If PositionMap\x < 0 ; Si la position de la map est incorrect, on corrige
  PositionMap\x = 0
ElseIf PositionMap\x > DimensionMap\x
  PositionMap\x = DimensionMap\x
EndIf
If PositionMap\y < 0 ; Si la position de la map est incorrect, on corrige
  PositionMap\y = 0
ElseIf PositionMap\y > DimensionMap\y
  PositionMap\y = DimensionMap\y
EndIf

For n = 0 To NbBloc ; pour chaque bloc
  If Bloc(n)\x - PositionMap\x >= -64 And  Bloc(n)\x  - PositionMap\x < #EcranX And Bloc(n)\y  - PositionMap\y >= -64 And  Bloc(n)\y  - PositionMap\y < #EcranY
    ; si le bloc va apparaitre sur l'écran
    DisplaySprite(#spr_bloc, Bloc(n)\x - PositionMap\x, Bloc(n)\y - PositionMap\y)
  EndIf
Next

Return 

move : 

If KeyboardPushed(#PB_Key_Right) 
  
  
  If mario\anim > 0 And mario\anim < 40 
    mario\frame = #spr_mario_marche_droite 
  EndIf 
  
  If mario\anim > 40 And mario\anim < 80 
    mario\frame = #spr_mario_marche_droite2 
  EndIf 
  
  
  If mario\anim = 80 
    mario\anim = 0 
  EndIf 
  
  mario\anim + 1 
  mario\x + mario\vitesse 
  mario\dir_droite = 1 
  
  ; detection de collisions latérales 
  For n = 0 To NbBloc
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, Bloc(n)\x, Bloc(n)\y) 
      mario\x = Bloc(n)\x - 64 
      mario\frame = #spr_mario_droite 
    EndIf 
  Next 
  
EndIf 

If KeyboardReleased(#PB_Key_Right) 
  mario\anim = 0 
  mario\frame = #spr_mario_droite 
EndIf 

If KeyboardPushed(#PB_Key_Left) 
  
  
  
  If mario\anim > 0 And mario\anim < 40 
    mario\frame = #spr_mario_marche_gauche 
  EndIf 
  
  If mario\anim > 40 And mario\anim < 80 
    mario\frame = #spr_mario_marche_gauche2 
  EndIf 
  
  
  If mario\anim = 80 
    mario\anim = 0 
  EndIf 
  
  mario\anim + 1 
  
  
  
  mario\x - mario\vitesse 
  mario\dir_droite = 0 
  
  
  ; detection de collisions latérales 
  For n = 0 To NbBloc 
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, Bloc(n)\x, Bloc(n)\y) 
      mario\x = Bloc(n)\x + 64 
      mario\frame = #spr_mario_gauche 
      
    EndIf 
  Next 
  
EndIf 

If KeyboardReleased(#PB_Key_Left)
  mario\anim = 0 
  mario\frame = #spr_mario_gauche 
EndIf 

If KeyboardPushed(#PB_Key_Left) And KeyboardPushed(#PB_Key_Right) 
  mario\frame = #spr_mario_droite 
EndIf 



;- gravite 


mario\y + 1 


For n = 0 To NbBloc 
  If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, Bloc(n)\x, Bloc(n)\y) 
    mario\y = Bloc(n)\y - 64 
    mario\saut = 0 
    
    
    If mario\frame = #spr_mario_saute_droite 
      mario\frame = #spr_mario_droite 
    EndIf 
    
    If mario\frame = #spr_mario_saute_gauche 
      mario\frame = #spr_mario_gauche 
    EndIf 
    
  EndIf 
Next 


If KeyboardPushed(#PB_Key_Up) Or mario\saut <> 0
  
  
  
  
  If mario\dir_droite = 1 
    mario\frame = #spr_mario_saute_droite 
  Else 
    mario\frame = #spr_mario_saute_gauche 
  EndIf 
  
  If mario\saut < 100 
    mario\y - 2
  EndIf 
  
  
  mario\saut + 1 
  
  For n = 0 To 64 
    If SpriteCollision(mario\frame, mario\x, mario\y, #spr_bloc, Bloc(n)\x, Bloc(n)\y) 
      mario\y = Bloc(n)\y + 64 
    EndIf 
  Next 
  
EndIf 


Return
le principe est le suivant :
on gère le bonhomme et les collisions comme d'habitude, aucun changement de ce coté la

par contre, on a changement au niveau de l'affichage car on a un décalage du au scroling qui apparait.
en clair, on a une carte qu'on affcihe par rapprot à une position de départ x, y

donc on affiche l'objet en le décalant

Code : Tout sélectionner

DisplaySprite(#Objet, Objet_X - Depar_Carte_X, Objet_Y - Depar_Carte_Y)
pour optimiser le code, on peut afficher seulement les objets dont les coordonnées sont sur l'écran
ça donne un test du genre

Code : Tout sélectionner

if Objet_X - Depar_Carte_X >= -Taille_Objet_X And  Objet_X - Depar_Carte_X < Taille_Ecran_X And Objet_Y - Depar_Carte_Y >= -Taille_Objet_Y And  Objet_Y - Depar_Carte_Y < Taille_Ecran_Y
  DisplaySprite(#Objet, Objet_X - Depar_Carte_X, Objet_Y - Depar_Carte_Y)
EndIf
ensuite, pour la position de la carte, on souhaite avoir le personnage au milieu de l'écran, d'accord :wink:
donc on positione la carte comme suit

Code : Tout sélectionner

Depar_Carte_X = Personnage_X - Taille_Ecran_X / 2
Depar_Carte_Y = Personnage_Y - Taille_Ecran_Y / 2
sauf qu'avec ce système, même quand on est bord de la carte on affiche le bonhomme au centre donc on a pas le bord de la carte sur le bord de l'écran (j'espère que c'est clair)
il faut donc donner des limites à la position de la carte

Code : Tout sélectionner

If Depart_Carte_X < 0
  Depart_Carte_X = 0
EndIf

If Depart_Carte_X > Dimension_Carte_X - Taille_Ecran_X - 1
  Depart_Carte_X = Dimension_Carte_X - Taille_Ecran_X - 1
EndIf

If Depart_Carte_Y < 0
  Depart_Carte_Y = 0
EndIf

If Depart_Carte_Y > Dimension_Carte_Y - Taille_Ecran_Y - 1
  Depart_Carte_Y = Dimension_Carte_Y - Taille_Ecran_Y - 1
EndIf
Et voilà, le scroling est réalisé, c'est super simple à intégrer, alors autant le faire dès le début, non ?
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

je sais pas pour vous , mais avec ma carte graphique
il faut remplacer

Code : Tout sélectionner

 FlipBuffers()
par

Code : Tout sélectionner

 FlipBuffers(60)
sinon ça rame !!! mem avec un P4 a 2.8Ghz


reedit : encore que maintenant c'est injouable , ça va trop vite !! :lol:
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

Au sujet de flipbuffers la doc anglaise dit ça :

0 : disable synchronization
1 : enable synchronization (default value)

ton 60 n'a aucune importance :)
hackotedelaplaque
Messages : 121
Inscription : mer. 21/janv./2004 22:18

Message par hackotedelaplaque »

Soldat inconnu> AH !!! Le pied, un scroling comme je voulais !!!! Je viens de rentrer du boulot je n'ai fait que compiler l'exemple mais je m'y pencherai sans fautes ce week end ! Un grand merci.
De même pour la correction du bogue de la "chutte ralentie" , effectivement avec "Or mario\saut<>0" c'est nickel !


Chris> la doc sur la gravité a l'air pas mal. L'anglais me dérange pas dès qu'il s'agit de Pure et je j'y jeterai un regard plus qu'attentif !

Dobro> En effet la demo est super lente si tu ne mets pas de paramètre à FlipBuffer. la raison : mario\vitesse = 1 seulement.
En fait comme le vsync ne marche pas chez moi (l'écran "glitches" pour faire style !) je mets toujours 0 en paramètre dans flipbuffers.
Et effectivement Comtois, flipbufers n'accepte que 0 ou 1 comme paramètre, en conséquence de quoi Dobro, si tu mets 60, cela revient au même que de mettre Toto c'est à dire NULL ou "0". Fais l'essaie avec toto tu verras je t'assure le résultat est le même !

Et ben, j'ai bien avancé avec tout ça ! Merci à vous.
Je poursuivrai ce poste quand j'aurai étoffé le code avec toutes les infos que vous m'avez données ! J'essaierai de commenter le code aussi ce serait pas du luxe :wink:
10 CLS
20 PRINT "Vive PureBasic"
30 GOTO 20
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

Voila la suite , il n'y a pas les sources parce que je bosse encore dessus .

Mais je suis curieux de savoir si ça tourne bien ou au ralenti chez vous ?

Je n'ai pas affiché le FPS , va falloir que je m'en occupe rapidement
mais visuellement c'est lent ou rapide pour vous ? sur quelle config ?

http://perso.wanadoo.fr/comtois/sources/plateforme5.zip

Touche Shift gauche pour sauter
F1 pour afficher/cacher les palmiers


Il reste encore 2, 3 bugs ou plus ? j'en connais au moins deux à corriger , et un autre truc à améliorer avant de poursuivre .
Répondre