"Can't Stop Running !"

Programmation avancée de jeux en PureBasic
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

"Can't Stop Running !"

Message par flaith »

Salut les gens

29/01/2010 - Mise à jour
Screenshots
ImageImage

Le fichier zip (avec la source) : http://flaith.free.fr/CSR/CSR.zip :mrgreen:

Dans le jeu :
F1 : pour remettre le joueur à son emplacement initial
F2 : change de map
P : Pause (encore 'P' pour enlever la pause)
Esc : Quitte
Dernière modification par flaith le dim. 31/janv./2010 23:09, modifié 4 fois.
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Jeu sans envergure

Message par venom »

pas mal ce code. bon certes avec un peut plus de design ça serait bien :wink: .
j'adopte

ps: il créer des terrains aléatoirement ???








@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

venom a écrit :pas mal ce code. bon certes avec un peut plus de design ça serait bien :wink: .
j'adopte

ps: il créer des terrains aléatoirement ???
merci :wink: design, oui c'est vrai, mais ca été fait vite fait aussi

Quant au terrain, c'est effectivement créé aléatoirement (en fonction de la constante #difficulty) dans la Procedure Init() et après le "; randomize walls"
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Jeu sans envergure

Message par venom »

flaith a écrit :merci :wink: design, oui c'est vrai, mais ca été fait vite fait aussi
je me doute, j'espère pour toi que tu as pas passer 3 semaines :lol: .
Tu me dira je ne serais même pas faire sa :D
flaith a écrit :Quant au terrain, c'est effectivement créé aléatoirement (en fonction de la constante #difficulty) dans la Procedure Init() et après le "; randomize walls"
mais c'est pas possible de tomber sur un terrain insolvable ?

EDIT:
ah et bien si sa viens de m'arrivais :D




@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

venom a écrit :...mais c'est pas possible de tomber sur un terrain insolvable ?

EDIT:
ah et bien si sa viens de m'arrivais :D
Faudrait que je mette en place un A* pathfinding dans ce cas là :wink:
Octavius
Messages : 312
Inscription : jeu. 26/juil./2007 12:10

Re: Jeu sans envergure

Message par Octavius »

Tu peux faire plus simple. Au lieu de poser aléatoirement les cases rouge et verte, et ensuite de vérifier avec un pathfinding que c'est solvable, tu peux te débrouiller pour que la case verte soit toujours positionnée à un endroit que la case rouge peut atteindre.

Code : Tout sélectionner

Enumeration
  #windows_main
  #Sprite_ScreenPlay
  #Sprite_Player
EndEnumeration

#difficulty = 3       ; hard:1 .. whatever:easy

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(#windows_main, 0, 0, 641, 481, "Find the green exit", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(#windows_main), 0, 0, 641, 481, 1, 0, 0)

    ;player
    If CreateSprite(#Sprite_Player,19,19)
      StartDrawing(SpriteOutput(#Sprite_Player))
        Box(0,0,19,19,RGB(255,0,0))
      StopDrawing()
    EndIf

  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf

EndIf

Global playerX, playerY, starttime, playermove
Global Dim tab.i(32,24)

Procedure Init()
  ; randomize walls
  For i = 0 To 31
    For j = 0 To 23
      t = Random(#difficulty)
      If t = 1
        tab(i,j) = 1
      Else
        tab(i,j) = 0
      EndIf
    Next
  Next
 
  ; randomize player position
  Repeat
    playerX = Random(31)
    playerY = Random(23)
    valplayer = tab(playerX, playerY)
    If valPlayer = 0
      Break
    EndIf
  ForEver
 
  ; randomize Exit
  exit_x = playerX
  exit_y = playerY
  
  For i=0 To 1000
    
    new_x = exit_x
    new_y = exit_y
    
    Select Random(3)
    
      Case 0
        If new_x > 0 : new_x - 1 : EndIf
      Case 1
        If new_y > 0 : new_y - 1 : EndIf
      Case 2
        If new_x < 31 : new_x + 1 : EndIf
      Case 3
        If new_y < 23 : new_y + 1 : EndIf
      
    EndSelect
    
    valexit = tab(new_x, new_y)
    If valexit = 0
      exit_x = new_x
      exit_y = new_y
    EndIf
    
  Next i
  tab(exit_x, exit_y) = 3
 
  ; create our playground
  If CreateSprite(#Sprite_ScreenPlay,641,481)
    StartDrawing(SpriteOutput(#Sprite_ScreenPlay))
      For i = 0 To 31
        For j = 0 To 23
 
          If tab(i,j) = 1
            Box(i*20,j*20,20,20,RGB(0,0,255))
          EndIf
 
          If tab(i,j) = 3
            Box(i*20,j*20,20,20,RGB(0,255,0))
          EndIf
 
        Next
      Next
 
      For j = 0 To 480 Step 20
        Line(0,j,640,1,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
 
      For i = 0 To 640 Step 20
        Line(i,0,1,480,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
 
    StopDrawing()
  EndIf
 
  ; player on you mark, ready, steady ... go !
  starttime = ElapsedMilliseconds()
  playermove = 0
EndProcedure

Init()

Repeat
  Repeat
    Event = WindowEvent()
   
    Select Event
      Case #PB_Event_CloseWindow
        Quit = 1
   
    EndSelect
   
  Until Event = 0
 
  ExamineKeyboard()

  ;If KeyboardPushed(#PB_Key_Up)
  If KeyboardReleased(#PB_Key_Up)
    playerY - 1 : playermove + 1
    If playerY < 0 : playerY = 0 : playermove - 1 : EndIf
    If tab(PlayerX, PlayerY) = 1 : playerY + 1 : playermove - 1 : EndIf
  EndIf     
   
  ;If KeyboardPushed(#PB_Key_Down)
  If KeyboardReleased(#PB_Key_Down)
    playerY + 1 : playermove + 1
    If playerY > 23 : playerY = 23 : playermove - 1 : EndIf
    If tab(PlayerX, PlayerY) = 1 : playerY - 1 : playermove - 1 : EndIf
  EndIf     

  ;If KeyboardPushed(#PB_Key_Left)
  If KeyboardReleased(#PB_Key_Left)
    playerX - 1 : playermove + 1
    If playerX < 0 : playerX = 0 : playermove - 1 : EndIf
    If tab(PlayerX, PlayerY) = 1 : playerX + 1 : playermove - 1 : EndIf
  EndIf     

  ;If KeyboardPushed(#PB_Key_Right)
  If KeyboardReleased(#PB_Key_Right)
    playerX + 1 : playermove + 1
    If playerX > 31 : playerX = 31 : playermove - 1 : EndIf
    If tab(PlayerX, PlayerY) = 1 : playerX - 1 : playermove - 1 : EndIf
  EndIf     

  ; Draw our playground on the screen
  DisplaySprite(#Sprite_ScreenPlay,0,0)

  ; empty box, so we draw our player
  If tab(playerX, playerY) <> 1
    DisplaySprite(#Sprite_Player, playerX * 20 + 1, playerY * 20 + 1)
  EndIf

  ; The exit has been reached
  If tab(playerX, playerY) = 3
    time = ElapsedMilliseconds() - starttime
    If MessageRequester("You made it !","Elapsed time : "+Str(time/1000)+" seconds for "+Str(playermove)+" moves."+#CRLF$+#CRLF$+"----- Start Again ?",#PB_MessageRequester_YesNo) = 6
      Init()
    Else     
      End
    EndIf
  EndIf

  FlipBuffers()
Until Quit Or KeyboardPushed(#PB_Key_Escape)
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

Bien vu la boucle permettant de s'éloigner le plus possible en allant dans des directions aléatoires :D
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Jeu sans envergure

Message par venom »

Oui mais le problème, c'est qu'en mode difficile ils ne se séparent pas de beaucoup :s
si non c'est pas mal en effet.





@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Octavius
Messages : 312
Inscription : jeu. 26/juil./2007 12:10

Re: Jeu sans envergure

Message par Octavius »

Oui c'est le problème. Après on peut toujours augmenter le nombre d'itérations. Mais c'est vrai qu'il doit y avoir une méthode plus élégante pour résoudre un tel problème. Peut-être par exemple en définissant un trajet aléatoire avant d'établir les murs ou autre chose.
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

En voila une idée qu'elle est bonne :D
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

Une version différente, ici le joueur (bloc rouge) ne s'arrête que lorsqu'il rencontre un obstacle ou alors qu'il trouve la sortie (bloc vert)
F1: régénère une nouvelle map
Esc: Quitte

Code : Tout sélectionner

Enumeration 
  #windows_main
  #Sprite_ScreenPlay
  #Sprite_Player
EndEnumeration

Enumeration 
  #GO_UP
  #GO_DOWN
  #GO_LEFT
  #GO_RIGHT
  #GO_NOWHERE
EndEnumeration

#difficulty = 3       ; hard:2 .. whatever:easy

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(#windows_main, 0, 0, 641, 481, "Find the green exit - F1: Reset - Esc: End", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(#windows_main), 0, 0, 641, 481, 1, 0, 0)

    ;player
    If CreateSprite(#Sprite_Player,19,19)
      StartDrawing(SpriteOutput(#Sprite_Player))
        Box(0,0,19,19,RGB(255,0,0))
      StopDrawing()
    EndIf

  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf

EndIf

Global playerX, playerY, starttime, playermove, _Direction
Global Dim tab.i(32,24)

Procedure Init()
  ; randomize walls
  For i = 0 To 31
    For j = 0 To 23
      t = Random(#difficulty)

      ; put a wall around the playground
      If i = 0 Or i = 31 Or j = 0 Or j = 23
        t = 1
      EndIf

      If t = 1
        tab(i,j) = 1
      Else
        tab(i,j) = 0
      EndIf
    Next
  Next
  
  ; randomize player position
  Repeat
    playerX = Random(31)
    playerY = Random(23)
    valplayer = tab(playerX, playerY)
    If valPlayer = 0
      Break
    EndIf
  ForEver
  
  ; randomize Exit
;   Repeat
;     exit_x = Random(31)
;     exit_y = Random(23)
;     valexit = tab(exit_x, exit_y)
;     If valexit = 0
;       tab(exit_x, exit_y) = 3
;       Break
;     EndIf
;   ForEver

	; randomize Exit
	exit_x = playerX
	exit_y = playerY
	
	For i=0 To 31*23*#difficulty
		
		new_x = exit_x
		new_y = exit_y
		
		Select Random(3)
		
			Case 0
				If new_x > 0 : new_x - 1 : EndIf
			Case 1
				If new_y > 0 : new_y - 1 : EndIf
			Case 2
				If new_x < 31 : new_x + 1 : EndIf
			Case 3
				If new_y < 23 : new_y + 1 : EndIf
			
		EndSelect
		
		valexit = tab(new_x, new_y)
		If valexit = 0
			exit_x = new_x
			exit_y = new_y
		EndIf
		
	Next i
	tab(exit_x, exit_y) = 3
  
  ; create our playground
  If CreateSprite(#Sprite_ScreenPlay,641,481)
    StartDrawing(SpriteOutput(#Sprite_ScreenPlay))
      For i = 0 To 31
        For j = 0 To 23
  
          If tab(i,j) = 1
            Box(i*20,j*20,20,20,RGB(0,0,255))
          EndIf
  
          If tab(i,j) = 3
            Box(i*20,j*20,20,20,RGB(0,255,0))
          EndIf
  
        Next
      Next
  
      For j = 0 To 480 Step 20
        Line(0,j,640,1,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
  
      For i = 0 To 640 Step 20
        Line(i,0,1,480,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
  
    StopDrawing()
  EndIf
  
  ; player on you mark, ready, steady ... go !
  starttime = ElapsedMilliseconds()
  playermove = 0
  _Direction = #GO_NOWHERE
EndProcedure

Procedure CheckPosition(Dir)
  If tab(playerX, playerY) = 1
    _Direction = #GO_NOWHERE

    Select Dir
      Case #GO_UP
        playerY + 1
      Case #GO_DOWN
        playerY - 1
      Case #GO_RIGHT
        playerX - 1
      Case #GO_LEFT
        playerX + 1
    EndSelect
;   Else
;     If playerX = 0  : _Direction = #GO_NOWHERE : EndIf
;     If playerX = 31 : _Direction = #GO_NOWHERE : EndIf
;     If playerY = 0  : _Direction = #GO_NOWHERE : EndIf
;     If playerY = 23 : _Direction = #GO_NOWHERE : EndIf
;     Debug "Direction = "+Str(_Direction)
;     Debug "PlayerX   = "+Str(playerX)
;     Debug "PlayerY   = "+Str(playerY)
  EndIf
EndProcedure

Init()

Repeat
  Repeat
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_CloseWindow
        Quit = 1
    
    EndSelect
    
  Until Event = 0
  
  ExamineKeyboard()

  If KeyboardReleased(#PB_Key_Up)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_UP
      playermove + 1
    EndIf
  EndIf     
    
  If KeyboardReleased(#PB_Key_Down)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_DOWN
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_Left)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_LEFT
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_Right)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_RIGHT
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_F1)
    Init()
  EndIf

  ; Draw our playground on the screen
  DisplaySprite(#Sprite_ScreenPlay,0,0)

  ; empty box, so we draw our player
  Select _Direction
    Case #GO_UP
      playerY - 1
      If playerY < 0 : playerY = 0 : EndIf
      CheckPosition(#GO_UP)
    Case #GO_DOWN
      playerY + 1
      If playerY > 23 : playerY = 23 : EndIf
      CheckPosition(#GO_DOWN)
    Case #GO_LEFT
      playerX - 1
      If playerX < 0 : playerX = 0 : EndIf
      CheckPosition(#GO_LEFT)
    Case #GO_RIGHT
      playerX + 1
      If playerX > 31 : playerX = 31 : EndIf
      CheckPosition(#GO_RIGHT)
  EndSelect

  DisplaySprite(#Sprite_Player, playerX * 20 + 1, playerY * 20 + 1)

  ; The exit has been reached
  If tab(playerX, playerY) = 3
    time = ElapsedMilliseconds() - starttime
    If MessageRequester("You made it !","Elapsed time : "+Str(time/1000)+" seconds for "+Str(playermove)+" moves."+#CRLF$+#CRLF$+"----- Start Again ?",#PB_MessageRequester_YesNo) = 6
      Init()
    Else      
      End
    EndIf
  EndIf

;  _Direction = #GO_NOWHERE

  FlipBuffers()
Until Quit Or KeyboardPushed(#PB_Key_Escape)
C'est plus compliqué pour réussir et on ne peut pas réussir à tous les coups, je prévois de faire des maps plus petites et définies par avance :mrgreen:

**EDIT** : petite modification dans les directions pour ne pas bloquer si on change de direction pendant le déplacement

**EDIT** :oops: des petites erreurs sur ce programme (si c'est au bord vous êtes bloqués :lol: )

**EDIT** : En mettant un bord tout autour ca marche mieux (a défaut de trouver une parade)
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

Un petit dernier code avant une version plus finalisée (dire qu'au début c'était juste pour faire des tests pour un autre jeu :roll: )
Ici vous pouvez modifier la largeur/hauteur des sprites et du terrain plus facilement (attention à ne pas dépasser votre taille d'écran)

Code : Tout sélectionner

Enumeration 
  #windows_main
  #Sprite_ScreenPlay
  #Sprite_Player
EndEnumeration

Enumeration 
  #GO_UP
  #GO_DOWN
  #GO_LEFT
  #GO_RIGHT
  #GO_NOWHERE
EndEnumeration

#difficulty = 2   ; hard:2 .. whatever:easy
#MAX_WIDTH  = 16  ;32
#MAX_HEIGHT = 16  ;24

#SPR_WIDTH  = 25
#SPR_HEIGHT = 25

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(#windows_main, 0, 0, #MAX_WIDTH * #SPR_WIDTH + 1, #MAX_HEIGHT * #SPR_HEIGHT + 1, "Find the green exit - F1: Restart - F2: Change - Esc: End", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(#windows_main), 0, 0, #MAX_WIDTH * #SPR_WIDTH + 1, #MAX_HEIGHT * #SPR_HEIGHT + 1, 1, 0, 0)

    ;player
    If CreateSprite(#Sprite_Player,#SPR_WIDTH-1,#SPR_HEIGHT-1)
      StartDrawing(SpriteOutput(#Sprite_Player))
        Box(0,0,#SPR_WIDTH-1,#SPR_HEIGHT-1,RGB(255,0,0))
      StopDrawing()
    EndIf

  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf

EndIf

Global playerX, playerY, Reinit_Player_X, Reinit_Player_Y, starttime, playermove, _Direction
Global Dim tab.i(#MAX_WIDTH,#MAX_HEIGHT)

Procedure Init()
  ; randomize walls
  For i = 0 To #MAX_WIDTH - 1
    For j = 0 To #MAX_HEIGHT - 1
      t = Random(#difficulty)

      ; put a wall around the playground
      If i = 0 Or i = #MAX_WIDTH-1 Or j = 0 Or j = #MAX_HEIGHT-1
        t = 1
      EndIf

      If t = 1
        tab(i,j) = 1
      Else
        tab(i,j) = 0
      EndIf
    Next
  Next
  
  ; randomize player position
  Repeat
    playerX = Random(#MAX_WIDTH-1)
    playerY = Random(#MAX_HEIGHT-1)
    valplayer = tab(playerX, playerY)
    If valPlayer = 0
      Break
    EndIf
  ForEver
  
  ; Keep value for reinit
  Reinit_Player_X = playerX
  Reinit_Player_Y = playerY

	; randomize Exit
	exit_x = playerX
	exit_y = playerY
	
	For i=0 To #MAX_WIDTH*#MAX_HEIGHT*#difficulty
		
		new_x = exit_x
		new_y = exit_y
		
		Select Random(3)
		
			Case 0
				If new_x > 0                : new_x - 1 : EndIf
			Case 1
				If new_y > 0                : new_y - 1 : EndIf
			Case 2
				If new_x < #MAX_WIDTH - 1   : new_x + 1 : EndIf
			Case 3
				If new_y < #MAX_HEIGHT - 1  : new_y + 1 : EndIf
			
		EndSelect
		
		valexit = tab(new_x, new_y)
		If valexit = 0
			exit_x = new_x
			exit_y = new_y
		EndIf
		
	Next i
	tab(exit_x, exit_y) = 3
  
  ; create our playground
  If CreateSprite(#Sprite_ScreenPlay,#MAX_WIDTH * #SPR_WIDTH + 1,#MAX_HEIGHT * #SPR_HEIGHT + 1)
    StartDrawing(SpriteOutput(#Sprite_ScreenPlay))
      For i = 0 To #MAX_WIDTH-1
        For j = 0 To #MAX_HEIGHT-1
  
          If tab(i,j) = 1
            Box(i*#SPR_WIDTH,j*#SPR_HEIGHT,#SPR_WIDTH,#SPR_HEIGHT,RGB(0,0,255))
          EndIf
  
          If tab(i,j) = 3
            Box(i*#SPR_WIDTH,j*#SPR_HEIGHT,#SPR_WIDTH,#SPR_HEIGHT,RGB(0,255,0))
          EndIf
  
        Next
      Next
  
      For j = 0 To #MAX_HEIGHT * #SPR_HEIGHT Step #SPR_HEIGHT
        Line(0,j,#MAX_WIDTH * #SPR_WIDTH,1,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
  
      For i = 0 To #MAX_WIDTH * #SPR_WIDTH Step #SPR_WIDTH
        Line(i,0,1,#MAX_HEIGHT * #SPR_HEIGHT,$C0C0C0) ;RGB(Random(255),Random(255),Random(255)))
      Next
  
    StopDrawing()
  EndIf
  
  ; player on you mark, ready, steady ... go !
  starttime = ElapsedMilliseconds()
  playermove = 0
  _Direction = #GO_NOWHERE
EndProcedure

Procedure CheckPosition(Dir)
  If tab(playerX, playerY) = 1
    _Direction = #GO_NOWHERE

    Select Dir
      Case #GO_UP
        playerY + 1
      Case #GO_DOWN
        playerY - 1
      Case #GO_RIGHT
        playerX - 1
      Case #GO_LEFT
        playerX + 1
    EndSelect
  EndIf
EndProcedure

Init()

Repeat
  Repeat
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_CloseWindow
        Quit = 1
    
    EndSelect
    
  Until Event = 0
  
  ExamineKeyboard()

  If KeyboardReleased(#PB_Key_Up)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_UP
      playermove + 1
    EndIf
  EndIf     
    
  If KeyboardReleased(#PB_Key_Down)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_DOWN
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_Left)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_LEFT
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_Right)
    If _Direction = #GO_NOWHERE
      _Direction = #GO_RIGHT
      playermove + 1
    EndIf
  EndIf     

  If KeyboardReleased(#PB_Key_F1)
    playerX = Reinit_Player_X
    playerY = Reinit_Player_Y
  EndIf

  If KeyboardReleased(#PB_Key_F2)
    Init()
  EndIf

  ; Draw our playground on the screen
  DisplaySprite(#Sprite_ScreenPlay,0,0)

  ; empty box, so we draw our player
  Select _Direction
    Case #GO_UP
      playerY - 1
      If playerY < 0 : playerY = 0 : EndIf
      CheckPosition(#GO_UP)
    Case #GO_DOWN
      playerY + 1
      If playerY > #MAX_HEIGHT-1 : playerY = #MAX_HEIGHT-1 : EndIf
      CheckPosition(#GO_DOWN)
    Case #GO_LEFT
      playerX - 1
      If playerX < 0 : playerX = 0 : EndIf
      CheckPosition(#GO_LEFT)
    Case #GO_RIGHT
      playerX + 1
      If playerX > #MAX_WIDTH-1 : playerX = #MAX_WIDTH-1 : EndIf
      CheckPosition(#GO_RIGHT)
  EndSelect

  DisplaySprite(#Sprite_Player, playerX * #SPR_WIDTH + 1, playerY * #SPR_HEIGHT + 1)

  ; The exit has been reached
  If tab(playerX, playerY) = 3
    time = ElapsedMilliseconds() - starttime
    If MessageRequester("You made it !","Elapsed time : "+Str(time/1000)+" seconds for "+Str(playermove)+" moves."+#CRLF$+#CRLF$+"----- Start Again ?",#PB_MessageRequester_YesNo) = 6
      Init()
    Else      
      End
    EndIf
  EndIf

  FlipBuffers() : Delay(15)
Until Quit Or KeyboardPushed(#PB_Key_Escape)
:mrgreen:

**Edit** : Ajout/modif : touche F1 recommence le jeu courant, F2: change de plateau
Dernière modification par flaith le mer. 25/nov./2009 9:48, modifié 1 fois.
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Jeu sans envergure

Message par venom »

c'est vrai a la base tu a poster ce code sans penser y retoucher :lol:
par contre ton dernier code chez moi la carré est un poil accélérer 8O :lol: c'est normale ???






@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Jeu sans envergure

Message par flaith »

venom a écrit :c'est vrai a la base tu a poster ce code sans penser y retoucher :lol:
c'est vrai, mais on ne se refait pas, je suis plutôt perfectionniste et je n'aime pas laisser un goût d'inachevé :wink:
venom a écrit :par contre ton dernier code chez moi la carré est un poil accélérer 8O :lol: c'est normale ???
@++
C'est le but, le carré ne s'arrête que lorsqu'il rencontre le mur (carré bleu) ou qu'il trouve la sortie (carré vert) :)
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Jeu sans envergure

Message par venom »

flaith a écrit :C'est le but, le carré ne s'arrête que lorsqu'il rencontre le mur (carré bleu) ou qu'il trouve la sortie (carré vert) :)
ok mais quand au démarrage tu boot au milieux et que sa bloque en haut et en bas c'est pas top :lol: ou meme si tu te coince tout seul au milieu mais bon. tous les codes sont disponible après chacun a sa sauce :wink:






@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Répondre