Page 1 sur 1

Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 15:14
par boby
Un peut de temps à tuer... Quoi de mieux que de sortir PB pour faire n'importe quoi avec !
(Bon... pour les IA j'ai eu la flemme donc Inky, Pinky et Clyde sont exactement les mêmes)

Code : Tout sélectionner

EnableExplicit
If CreateFile(0,"Map")
  WriteStringN(0,"28")
  WriteStringN(0,"29")
  WriteStringN(0,"1111111111111111111111111111")
  WriteStringN(0,"1333333333333113333333333331")
  WriteStringN(0,"1311113111113113111113111131")
  WriteStringN(0,"1511113111113113111113111151")
  WriteStringN(0,"1311113111113113111113111131")
  WriteStringN(0,"1333333333333333333333333331")
  WriteStringN(0,"1311113113111111113113111131")
  WriteStringN(0,"1311113113111111113113111131")
  WriteStringN(0,"1333333113333113333113333331")
  WriteStringN(0,"1111113111112112111113111111")
  WriteStringN(0,"2222213111112112111113122222")
  WriteStringN(0,"2222213112222222222113122222")
  WriteStringN(0,"1111113112111221112113111111")
  WriteStringN(0,"2222223222122222212223222222")
  WriteStringN(0,"1111113112111111112113111111")
  WriteStringN(0,"2222213112222222222113122222")
  WriteStringN(0,"2222213112111111112113122222")
  WriteStringN(0,"1111113112111111112113111111")
  WriteStringN(0,"1333333333333113333333333331")
  WriteStringN(0,"1311113111113113111113111131")
  WriteStringN(0,"1311113111113113111113111131")
  WriteStringN(0,"1533113333333433333333113351")
  WriteStringN(0,"1113113113111111113113113111")
  WriteStringN(0,"1113113113111111113113113111")
  WriteStringN(0,"1333333113333113333113333331")
  WriteStringN(0,"1311111111113113111111111131")
  WriteStringN(0,"1311111111113113111111111131")
  WriteStringN(0,"1333333333333333333333333331")
  WriteStringN(0,"1111111111111111111111111111")
  WriteStringN(0,"14")
  WriteStringN(0,"12")
  WriteStringN(0,"12")
  WriteStringN(0,"14")
  WriteStringN(0,"14")
  WriteStringN(0,"14")
  WriteStringN(0,"16")
  WriteString(0,"14")
  CloseFile(0)
Else
  End
EndIf
#Wall = 1
#Empty = 2
#Blob = 3
#Player = 4
#PacGum = 5
#GameWait = 1
#GamePlay = 2
#GameDeath = 3
#GameWin = 4
Structure fantome
  x.a
  y.a
  xold.a
  yold.a
  Startx.a
  Starty.a
  lastdir.a
  timer.l
  nextdirection.i
  state.a
EndStructure
Declare draw()
Declare LoadMap(file$)
Declare Events()
Declare Death()
Declare CheckCrossRoad(*ghost)
Declare CanGo(Direction,*ghost)
Declare Win()
Global Dim world(1,1), Dim worldcopy(1,1)
Global score,x,y,startx,starty,LastDir,Dir,timer,Blinky.fantome,Pinky.fantome,Inky.fantome,Clyde.fantome, game = #GameWait,width,heigh, blobs, totalblobs, Pacgum, GumTime
LoadMap("Map")
OpenConsole("MacMan !!!!")
EnableGraphicalConsole(1)
draw()
timer = ElapsedMilliseconds()
Repeat
  Inkey()
  Select  RawKey()
    Case 0
      Delay(10)
    Case 37 ; gauche
      Dir = 1
    Case 38 ; haut
      Dir = 2
    Case 39 ; droite
      Dir = 3
    Case 40 ; bas
      Dir = 4
  EndSelect
  Select game
    Case #GameWait
      If Dir : game = #GamePlay : EndIf
    Case #GamePlay
      Events()
    Case #GameDeath
      Death()
    Case #GameWin
      Win()
  EndSelect
ForEver
Procedure draw()
  Protected loopX,loopY
  ConsoleColor(7,0)
  Print("SCORE : "+Str(score))
  For loopX = 0 To width
    For loopY = 0 To heigh
      ConsoleLocate(loopX,loopY+4)
      Select world(loopX,loopY)
        Case #Blob
          ConsoleColor(7,0)
          Print(".")
        Case #Wall
          ConsoleColor(1,0)
          Print("O")
        Case #Player
          ConsoleColor(14,0)
          Print("C")
        Case #PacGum
          ConsoleColor(7,0)
          Print("o")
      EndSelect
    Next loopY
  Next loopX
  ConsoleLocate(Blinky\x,Blinky\y+4) : ConsoleColor(4,0) : Print("M")
  ConsoleLocate(Pinky\x,Pinky\y+4) : ConsoleColor(5,0) : Print("M")
  ConsoleLocate(Inky\x,Inky\y+4) : ConsoleColor(9,0) : Print("M")
  ConsoleLocate(Clyde\x,Clyde\y+4) : ConsoleColor(6,0) : Print("M")
EndProcedure
Procedure LoadMap(file$)
  Protected loopX, loopY
  blobs = 0
  ReadFile(0,file$)
  width = Val(ReadString(0))
  heigh = Val(ReadString(0))
  Dim world(width,heigh)  : Dim worldcopy(width,heigh)
  For loopY = 1 To heigh
    For loopX = 1 To width
      world(loopX,loopY) = Val(ReadString(0,#PB_Ascii,1))
      If world(loopX,loopY) = #Blob : blobs + 1 : EndIf
      If world(loopX,loopY) = #Player : x = loopX : y = loopY : EndIf
    Next loopX
    ReadString(0)
  Next loopY
  startx = x : starty = y
  totalblobs = blobs
  CopyArray(world(),worldcopy())
  Blinky\Startx = Val(ReadString(0)) : Blinky\Starty = Val(ReadString(0)) : Blinky\x = Blinky\Startx : Blinky\y = Blinky\Starty : Blinky\xold = Blinky\x : Blinky\yold = Blinky\y
  Pinky\Startx = Val(ReadString(0)) : Pinky\Starty = Val(ReadString(0)) : Pinky\x = Pinky\Startx : Pinky\y = Pinky\Starty : Pinky\xold = Pinky\x : Pinky\yold = Pinky\y
  Inky\Startx = Val(ReadString(0)) : Inky\Starty = Val(ReadString(0)) : Inky\x = Inky\Startx : Inky\y = Inky\Starty : Inky\xold = Inky\x : Inky\yold = Inky\y
  Clyde\Startx = Val(ReadString(0)) : Clyde\Starty = Val(ReadString(0)) : Clyde\x = Clyde\Startx : Clyde\y = Clyde\Starty : Clyde\xold = Clyde\x : Clyde\yold = Clyde\y
  CloseFile(0)
  DeleteFile(file$)
EndProcedure
Procedure Death()
  ClearConsole()
  CopyArray(worldcopy(),world())
  x = startx : y = starty : blobs = totalblobs
  Blinky\x = Blinky\Startx : Blinky\y = Blinky\Starty : Blinky\xold = Blinky\x : Blinky\yold = Blinky\y
  Pinky\x = Pinky\Startx : Pinky\y = Pinky\Starty : Pinky\xold = Pinky\x : Pinky\yold = Pinky\y
  Inky\x = Inky\Startx : Inky\y = Inky\Starty : Inky\xold = Inky\x : Inky\yold = Inky\y
  Clyde\x = Clyde\Startx : Clyde\y = Clyde\Starty : Clyde\xold = Clyde\x : Clyde\yold = Clyde\y
  draw()
  Blinky\state = 0 : Pinky\state = 0 : Inky\state = 0 : Clyde\state = 0
  Blinky\lastdir = 0 : Pinky\lastdir = 0 : Inky\lastdir = 0 : Clyde\lastdir = 0
  LastDir = 0
  Dir = 0
  score = 0
  game = #GameWait
EndProcedure
Procedure Win()
  ConsoleLocate(12,20)
  ConsoleColor(12,0)
  Print("YOU WIN")
  Delay(2000)
  ClearConsole()
  CopyArray(worldcopy(),world())
  x = startx : y = starty : blobs = totalblobs
  Blinky\x = Blinky\Startx : Blinky\y = Blinky\Starty : Blinky\xold = Blinky\x : Blinky\yold = Blinky\y
  Pinky\x = Pinky\Startx : Pinky\y = Pinky\Starty : Pinky\xold = Pinky\x : Pinky\yold = Pinky\y
  Inky\x = Inky\Startx : Inky\y = Inky\Starty : Inky\xold = Inky\x : Inky\yold = Inky\y
  Clyde\x = Clyde\Startx : Clyde\y = Clyde\Starty : Clyde\xold = Clyde\x : Clyde\yold = Clyde\y
  Blinky\state = 0 : Pinky\state = 0 : Inky\state = 0 : Clyde\state = 0
  Blinky\lastdir = 0 : Pinky\lastdir = 0 : Inky\lastdir = 0 : Clyde\lastdir = 0
  Pacgum = 0
  GumTime = 0
  draw()
  LastDir = 0
  Dir = 0
  game = #GameWait
EndProcedure
Procedure Events()
  Static GumCol
  Protected result, time = ElapsedMilliseconds(), DispBlinky, DispPinky, DispInky, DispClyde
  If time - timer >= 100 ; Controle du joueur
    Select Dir
      Case 1
        If Not world(x-1,y) = #Wall : LastDir = 1 : EndIf
      Case 2
        If Not world(x,y-1) = #Wall : LastDir = 2 : EndIf
      Case 3
        If x < width
          If Not world(x+1,y) = #Wall : LastDir = 3 : EndIf
        EndIf
      Case 4
        If y < heigh
          If Not world(x,y+1) = #Wall : LastDir = 4 : EndIf
        EndIf
    EndSelect
    Select LastDir ;{ Déplacement
      Case 1 ;gauche
        If x-1 =0 : ConsoleLocate(x,y+4) : Print(" ") : x = width+1 : EndIf
        If Not world(x-1,y) = #Wall
          If world(x-1,y) = #Blob : score + 10 : blobs - 1 : world(x-1,y) = #Empty : EndIf
          If world(x-1,y) = #PacGum : GumCol = 0 : GumTime = ElapsedMilliseconds() : Pacgum = ElapsedMilliseconds() : If Not Blinky\state = 3 : Blinky\timer = 0 : Blinky\lastdir = 0 : Blinky\state = 2 : EndIf : Pinky\timer = 0 : If Not Pinky\state = 3 : Pinky\lastdir = 0 :  Pinky\state = 2 : EndIf : If Not Inky\state = 3 : Inky\timer = 0 : Inky\lastdir = 0 :  Inky\state = 2 : EndIf : If Not Clyde\state = 3 : Clyde\timer = 0 : Clyde\lastdir = 0 :   Clyde\state = 2 : EndIf : world(x-1,y) = #Empty : EndIf
          ConsoleLocate(x,y+4)
          Print(" ")
          x-1
          ConsoleLocate(x,y+4)
          ConsoleColor(14,0)
          Print("C")
        EndIf
      Case 2 ;haut
        If y-1 =0 : ConsoleLocate(x,y+4) : Print(" ") : y = heigh : EndIf
        If Not world(x,y-1) = #Wall
          If world(x,y-1) = #Blob : score + 10 : blobs - 1 : world(x,y-1) = #Empty : EndIf
          If world(x,y-1) = #PacGum : GumCol = 0 : GumTime = ElapsedMilliseconds() : Pacgum = ElapsedMilliseconds() : If Not Blinky\state = 3 : Blinky\timer = 0 : Blinky\lastdir = 0 : Blinky\state = 2 : EndIf : Pinky\timer = 0 : If Not Pinky\state = 3 : Pinky\lastdir = 0 :  Pinky\state = 2 : EndIf : If Not Inky\state = 3 : Inky\timer = 0 : Inky\lastdir = 0 :  Inky\state = 2 : EndIf : If Not Clyde\state = 3 : Clyde\timer = 0 : Clyde\lastdir = 0 :   Clyde\state = 2 : EndIf : world(x,y-1) = #Empty : EndIf
          ConsoleLocate(x,y+4)
          Print(" ")
          y-1
          ConsoleLocate(x,y+4)
          ConsoleColor(14,0)
          Print("C")
        EndIf
      Case 3 ;droite
        If x = width : ConsoleLocate(x,y+4) : Print(" ") : x = 0 : EndIf
        If Not world(x+1,y) = #Wall
          If world(x+1,y) = #Blob : score + 10 : blobs - 1 : world(x+1,y) = #Empty : EndIf
          If world(x+1,y) = #PacGum : GumCol = 0 : GumTime = ElapsedMilliseconds() : Pacgum = ElapsedMilliseconds() : If Not Blinky\state = 3 : Blinky\timer = 0 : Blinky\lastdir = 0 : Blinky\state = 2 : EndIf : Pinky\timer = 0 : If Not Pinky\state = 3 : Pinky\lastdir = 0 :  Pinky\state = 2 : EndIf : If Not Inky\state = 3 : Inky\timer = 0 : Inky\lastdir = 0 :  Inky\state = 2 : EndIf : If Not Clyde\state = 3 : Clyde\timer = 0 : Clyde\lastdir = 0 :   Clyde\state = 2 : EndIf : world(x+1,y) = #Empty : EndIf
          ConsoleLocate(x,y+4)
          Print(" ")
          x+1
          ConsoleLocate(x,y+4)
          ConsoleColor(14,0)
          Print("C")
        EndIf
      Case 4 ;bas
        If y = heigh : ConsoleLocate(x,y+4) : Print(" ") : y = 2 : EndIf
        If Not world(x,y+1) = #Wall
          If world(x,y+1) = #Blob : score + 10 : blobs - 1 : world(x,y+1) = #Empty : EndIf
          If world(x,y+1) = #PacGum : GumCol = 0 : GumTime = ElapsedMilliseconds() : Pacgum = ElapsedMilliseconds() : If Not Blinky\state = 3 : Blinky\timer = 0 : Blinky\lastdir = 0 : Blinky\state = 2 : EndIf : Pinky\timer = 0 : If Not Pinky\state = 3 : Pinky\lastdir = 0 :  Pinky\state = 2 : EndIf : If Not Inky\state = 3 : Inky\timer = 0 : Inky\lastdir = 0 :  Inky\state = 2 : EndIf : If Not Clyde\state = 3 : Clyde\timer = 0 : Clyde\lastdir = 0 :   Clyde\state = 2 : EndIf : world(x,y+1) = #Empty : EndIf
          ConsoleLocate(x,y+4)
          Print(" ")
          y+1
          ConsoleLocate(x,y+4)
          ConsoleColor(14,0)
          Print("C")
        EndIf ;}
    EndSelect
    timer = ElapsedMilliseconds()
    ConsoleLocate(0,0)
    ConsoleColor(7,0)
    Print("SCORE : "+Str(score))
    If blobs = 0
      game = #GameWin
    EndIf
  EndIf 
  
  If LastDir
    ;{ AI Blinky "Suit Mac-Man comme son ombre"
    If Blinky\state < 2 And time - Blinky\timer => 130
      DispBlinky = 1
      If Abs(Blinky\x - x) < 7 Or Abs(Blinky\y - y) < 7: Blinky\state = 1 : Else : Blinky\state = 0 : EndIf
      Blinky\xold = Blinky\x : Blinky\yold = Blinky\y
      If CheckCrossRoad(@Blinky)
        Blinky\nextdirection = 0
        If Blinky\state = 0 ; Patrouille
          If Blinky\x < width/2
            If CanGo(3,@Blinky)
              Blinky\x +1 : Blinky\lastdir = 3 : Blinky\nextdirection = 1
            EndIf
          EndIf
          If Blinky\nextdirection = 0 And Blinky\y < heigh/2
            If CanGo(4,@Blinky)
              Blinky\y +1 : Blinky\lastdir = 4 : Blinky\nextdirection = 1
            EndIf
          EndIf
          If Blinky\nextdirection = 0
            result = 0
            If CanGo(1,@Blinky) : result + 1 : EndIf
            If CanGo(2,@Blinky) : result + 1 : EndIf
            If CanGo(3,@Blinky) : result + 1 : EndIf
            If CanGo(4,@Blinky) : result + 1 : EndIf
            If result
              Repeat
                result = Random(4,1)
                If CanGo(result,@Blinky)
                  Blinky\lastdir = result
                  Break
                EndIf
              ForEver
              If Blinky\lastdir = 1 : Blinky\x - 1
              ElseIf Blinky\lastdir = 2 : Blinky\y - 1
              ElseIf Blinky\lastdir = 3 : Blinky\x + 1
              ElseIf Blinky\lastdir = 4 : Blinky\y + 1 : EndIf
            Else
              Blinky\lastdir = 0
            EndIf
          EndIf
        ElseIf Blinky\state = 1 ;En chasse
          If Blinky\x < x
            If CanGo(3,@Blinky)
              Blinky\x + 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 3
            EndIf
          ElseIf Blinky\x > x
            If CanGo(1,@Blinky)
              Blinky\x - 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 1
            EndIf
          EndIf
          If Blinky\nextdirection = 0
            If Blinky\y < y
              If CanGo(4,@Blinky)
                Blinky\y+1 : Blinky\nextdirection = 1 : Blinky\lastdir = 4
              EndIf
            ElseIf Blinky\y > y
              If CanGo(2,@Blinky)
                Blinky\y-1 : Blinky\nextdirection = 1 : Blinky\lastdir = 2
              EndIf
            EndIf
          EndIf
          If Blinky\nextdirection = 0
            Repeat
              result = Random(4,1)
              If CanGo(result,@Blinky)
                Blinky\lastdir = result
                Break
              EndIf
            ForEver
            If Blinky\lastdir = 1 : Blinky\x - 1
            ElseIf Blinky\lastdir = 2 : Blinky\y - 1
            ElseIf Blinky\lastdir = 3 : Blinky\x + 1
            ElseIf Blinky\lastdir = 4 : Blinky\y + 1 : EndIf
          EndIf
        EndIf
      Else ;{ Continue sa route
        Select Blinky\lastdir
          Case 1
            If CanGo(1,@Blinky)
              Blinky\x - 1
            Else
              Blinky\lastdir=0
            EndIf
          Case 2
            If CanGo(2,@Blinky)
              Blinky\y -1
            Else
              Blinky\lastdir = 0
            EndIf
          Case 3
            If CanGo(3,@Blinky)
              Blinky\x +1
            Else
              Blinky\lastdir = 0
            EndIf
          Case 4
            If CanGo(4,@Blinky)
              Blinky\y +1
            Else
              Blinky\lastdir = 0
            EndIf
        EndSelect ;}
      EndIf 
      Blinky\timer = time
    ElseIf  Blinky\state = 2
      If ElapsedMilliseconds() - Blinky\timer >= 150
        DispBlinky = 1
        Blinky\xold = Blinky\x : Blinky\yold = Blinky\y
        If CheckCrossRoad(@Blinky)
          Blinky\nextdirection = 0
          If Blinky\x > x
            If CanGo(3,@Blinky)
              Blinky\x + 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 3
            EndIf
          Else
            If CanGo(1,@Blinky)
              Blinky\x - 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 1
            EndIf
          EndIf
          If Blinky\nextdirection = 0
            If Blinky\y > y
              If CanGo(4,@Blinky)
                Blinky\y + 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 4
              EndIf
            Else
              If CanGo(2,@Blinky)
                Blinky\y - 1 : Blinky\nextdirection = 1 : Blinky\lastdir = 2
              EndIf
            EndIf
          EndIf
          If Blinky\nextdirection = 0
            Repeat
              result = Random(4,1)
              If CanGo(result,@Blinky)
                Blinky\lastdir = result
                Break
              EndIf
            ForEver
            If Blinky\lastdir = 1 : Blinky\x - 1
            ElseIf Blinky\lastdir = 2 : Blinky\y - 1
            ElseIf Blinky\lastdir = 3 : Blinky\x + 1
            ElseIf Blinky\lastdir = 4 : Blinky\y + 1 : EndIf
          EndIf
        Else ;{ Continue sa route
          Select Blinky\lastdir
            Case 1
              If CanGo(1,@Blinky)
                Blinky\x - 1
              Else
                Blinky\lastdir=0
              EndIf
            Case 2
              If CanGo(2,@Blinky)
                Blinky\y -1
              Else
                Blinky\lastdir = 0
              EndIf
            Case 3
              If CanGo(3,@Blinky)
                Blinky\x +1
              Else
                Blinky\lastdir = 0
              EndIf
            Case 4
              If CanGo(4,@Blinky)
                Blinky\y +1
              Else
                Blinky\lastdir = 0
              EndIf
          EndSelect ;}
        EndIf
        Blinky\timer = ElapsedMilliseconds()
      EndIf
    Else
      If ElapsedMilliseconds() - Blinky\timer >= 2000
        Blinky\x = Blinky\Startx : Blinky\y = Blinky\Starty : Blinky\xold = Blinky\Startx : Blinky\yold = Blinky\Starty
        Blinky\state = 0 : Blinky\timer = 0
      EndIf
    EndIf ;}
    ;{ AI Pinky "Vise l'endroit où va se trouver Mac-Man"
    If Pinky\state < 2 And time - Pinky\timer >= 130
      DispPinky = 1
      Pinky\xold = Pinky\x : Pinky\yold = Pinky\y
      If CheckCrossRoad(@Pinky)
        Repeat
          result = Random(4,1)
          If CanGo(result,@Pinky)
            Pinky\lastdir = result
            Break
          EndIf
        ForEver
        If Pinky\lastdir = 1 : Pinky\x - 1
        ElseIf Pinky\lastdir = 2 : Pinky\y - 1
        ElseIf Pinky\lastdir = 3 : Pinky\x + 1
        ElseIf Pinky\lastdir = 4 : Pinky\y + 1 : EndIf 
      Else ;{ Continue sa route
        Select Pinky\lastdir
          Case 1
            If CanGo(1,@Pinky)
              Pinky\x - 1
            Else
              Pinky\lastdir=0
            EndIf
          Case 2
            If CanGo(2,@Pinky)
              Pinky\y -1
            Else
              Pinky\lastdir = 0
            EndIf
          Case 3
            If CanGo(3,@Pinky)
              Pinky\x +1
            Else
              Pinky\lastdir = 0
            EndIf
          Case 4
            If CanGo(4,@Pinky)
              Pinky\y +1
            Else
              Pinky\lastdir = 0
            EndIf
        EndSelect ;}
      EndIf
      Pinky\timer = time
    ElseIf  Pinky\state = 2
      If ElapsedMilliseconds() - Pinky\timer >= 150
        DispPinky = 1
        Pinky\xold = Pinky\x : Pinky\yold = Pinky\y
        If CheckCrossRoad(@Pinky)
          Pinky\nextdirection = 0
          If Pinky\x > x
            If CanGo(3,@Pinky)
              Pinky\x + 1 : Pinky\nextdirection = 1 : Pinky\lastdir = 3
            EndIf
          Else
            If CanGo(1,@Pinky)
              Pinky\x - 1 : Pinky\nextdirection = 1 : Pinky\lastdir = 1
            EndIf
          EndIf
          If Pinky\nextdirection = 0
            If Pinky\y > y
              If CanGo(4,@Pinky)
                Pinky\y + 1 : Pinky\nextdirection = 1 : Pinky\lastdir = 4
              EndIf
            Else
              If CanGo(2,@Pinky)
                Pinky\y - 1 : Pinky\nextdirection = 1 : Pinky\lastdir = 2
              EndIf
            EndIf
          EndIf
          If Pinky\nextdirection = 0
            Repeat
              result = Random(4,1)
              If CanGo(result,@Pinky)
                Pinky\lastdir = result
                Break
              EndIf
            ForEver
            If Pinky\lastdir = 1 : Pinky\x - 1
            ElseIf Pinky\lastdir = 2 : Pinky\y - 1
            ElseIf Pinky\lastdir = 3 : Pinky\x + 1
            ElseIf Pinky\lastdir = 4 : Pinky\y + 1 : EndIf
          EndIf
        Else ;{ Continue sa route
          Select Pinky\lastdir
            Case 1
              If CanGo(1,@Pinky)
                Pinky\x - 1
              Else
                Pinky\lastdir=0
              EndIf
            Case 2
              If CanGo(2,@Pinky)
                Pinky\y -1
              Else
                Pinky\lastdir = 0
              EndIf
            Case 3
              If CanGo(3,@Pinky)
                Pinky\x +1
              Else
                Pinky\lastdir = 0
              EndIf
            Case 4
              If CanGo(4,@Pinky)
                Pinky\y +1
              Else
                Pinky\lastdir = 0
              EndIf
          EndSelect ;}
        EndIf
        Pinky\timer = ElapsedMilliseconds()
      EndIf
    Else
      If ElapsedMilliseconds() - Pinky\timer >= 2000
        Pinky\x = Pinky\Startx : Pinky\y = Pinky\Starty : Pinky\xold = Pinky\Startx : Pinky\yold = Pinky\Starty
        Pinky\state = 0 : Pinky\timer = 0
      EndIf
    EndIf;}
    ;{ AI Inky "De temps en temps, il part dans la direction opposée à Mac-Man"
    If Inky\state < 2 And time - Inky\timer >= 130
      DispInky = 1
      Inky\xold = Inky\x : Inky\yold = Inky\y
      If CheckCrossRoad(@Inky)
        Repeat
          result = Random(4,1)
          If CanGo(result,@Inky)
            Inky\lastdir = result
            Break
          EndIf
        ForEver
        If Inky\lastdir = 1 : Inky\x - 1
        ElseIf Inky\lastdir = 2 : Inky\y - 1
        ElseIf Inky\lastdir = 3 : Inky\x + 1
        ElseIf Inky\lastdir = 4 : Inky\y + 1 : EndIf 
      Else ;{ Continue sa route
        Select Inky\lastdir
          Case 1
            If CanGo(1,@Inky)
              Inky\x - 1
            Else
              Inky\lastdir=0
            EndIf
          Case 2
            If CanGo(2,@Inky)
              Inky\y -1
            Else
              Inky\lastdir = 0
            EndIf
          Case 3
            If CanGo(3,@Inky)
              Inky\x +1
            Else
              Inky\lastdir = 0
            EndIf
          Case 4
            If CanGo(4,@Inky)
              Inky\y +1
            Else
              Inky\lastdir = 0
            EndIf
        EndSelect ;}
      EndIf
      Inky\timer = time
    ElseIf Inky\state = 2
      If ElapsedMilliseconds() - Inky\timer >= 150
        DispInky = 1
        Inky\xold = Inky\x : Inky\yold = Inky\y
        If CheckCrossRoad(@Inky)
          Inky\nextdirection = 0
          If Inky\x > x
            If CanGo(3,@Inky)
              Inky\x + 1 : Inky\nextdirection = 1 : Inky\lastdir = 3
            EndIf
          Else
            If CanGo(1,@Inky)
              Inky\x - 1 : Inky\nextdirection = 1 : Inky\lastdir = 1
            EndIf
          EndIf
          If Inky\nextdirection = 0
            If Inky\y > y
              If CanGo(4,@Inky)
                Inky\y + 1 : Inky\nextdirection = 1 : Inky\lastdir = 4
              EndIf
            Else
              If CanGo(2,@Inky)
                Inky\y - 1 : Inky\nextdirection = 1 : Inky\lastdir = 2
              EndIf
            EndIf
          EndIf
          If Inky\nextdirection = 0
            Repeat
              result = Random(4,1)
              If CanGo(result,@Inky)
                Inky\lastdir = result
                Break
              EndIf
            ForEver
            If Inky\lastdir = 1 : Inky\x - 1
            ElseIf Inky\lastdir = 2 : Inky\y - 1
            ElseIf Inky\lastdir = 3 : Inky\x + 1
            ElseIf Inky\lastdir = 4 : Inky\y + 1 : EndIf
          EndIf
        Else ;{ Continue sa route
          Select Inky\lastdir
            Case 1
              If CanGo(1,@Inky)
                Inky\x - 1
              Else
                Inky\lastdir=0
              EndIf
            Case 2
              If CanGo(2,@Inky)
                Inky\y -1
              Else
                Inky\lastdir = 0
              EndIf
            Case 3
              If CanGo(3,@Inky)
                Inky\x +1
              Else
                Inky\lastdir = 0
              EndIf
            Case 4
              If CanGo(4,@Inky)
                Inky\y +1
              Else
                Inky\lastdir = 0
              EndIf
          EndSelect ;}
        EndIf
        Inky\timer = ElapsedMilliseconds()
      EndIf
    Else
      If ElapsedMilliseconds() - Inky\timer >= 2000
        Inky\x = Inky\Startx : Inky\y = Inky\Starty : Inky\xold = Inky\Startx : Inky\yold = Inky\Starty
        Inky\state = 0 : Inky\timer = 0
      EndIf
    EndIf;}
    ;{ AI Clyde "De temps en temps, il choisit une direction au hasard"
    If Clyde\state < 2 And time - Clyde\timer >= 130
      DispClyde = 1
      Clyde\xold = Clyde\x : Clyde\yold = Clyde\y
      If CheckCrossRoad(@Clyde)
        Repeat
          result = Random(4,1)
          If CanGo(result,@Clyde)
            Clyde\lastdir = result
            Break
          EndIf
        ForEver
        If Clyde\lastdir = 1 : Clyde\x - 1
        ElseIf Clyde\lastdir = 2 : Clyde\y - 1
        ElseIf Clyde\lastdir = 3 : Clyde\x + 1
        ElseIf Clyde\lastdir = 4 : Clyde\y + 1 : EndIf 
      Else ;{ Continue sa route
        Select Clyde\lastdir
          Case 1
            If CanGo(1,@Clyde)
              Clyde\x - 1
            Else
              Clyde\lastdir=0
            EndIf
          Case 2
            If CanGo(2,@Clyde)
              Clyde\y -1
            Else
              Clyde\lastdir = 0
            EndIf
          Case 3
            If CanGo(3,@Clyde)
              Clyde\x +1
            Else
              Clyde\lastdir = 0
            EndIf
          Case 4
            If CanGo(4,@Clyde)
              Clyde\y +1
            Else
              Clyde\lastdir = 0
            EndIf
        EndSelect ;}
      EndIf 
      Clyde\timer = time
    ElseIf  Clyde\state = 2
      If ElapsedMilliseconds() - Clyde\timer >= 150
        DispClyde = 1
        Clyde\xold = Clyde\x : Clyde\yold = Clyde\y
        If CheckCrossRoad(@Clyde)
          Clyde\nextdirection = 0
          If Clyde\x > x
            If CanGo(3,@Clyde)
              Clyde\x + 1 : Clyde\nextdirection = 1 : Clyde\lastdir = 3
            EndIf
          Else
            If CanGo(1,@Clyde)
              Clyde\x - 1 : Clyde\nextdirection = 1 : Clyde\lastdir = 1
            EndIf
          EndIf
          If Clyde\nextdirection = 0
            If Clyde\y > y
              If CanGo(4,@Clyde)
                Clyde\y + 1 : Clyde\nextdirection = 1 : Clyde\lastdir = 4
              EndIf
            Else
              If CanGo(2,@Clyde)
                Clyde\y - 1 : Clyde\nextdirection = 1 : Clyde\lastdir = 2
              EndIf
            EndIf
          EndIf
          If Clyde\nextdirection = 0
            Repeat
              result = Random(4,1)
              If CanGo(result,@Clyde)
                Clyde\lastdir = result
                Break
              EndIf
            ForEver
            If Clyde\lastdir = 1 : Clyde\x - 1
            ElseIf Clyde\lastdir = 2 : Clyde\y - 1
            ElseIf Clyde\lastdir = 3 : Clyde\x + 1
            ElseIf Clyde\lastdir = 4 : Clyde\y + 1 : EndIf
          EndIf
        Else ;{ Continue sa route
          Select Clyde\lastdir
            Case 1
              If CanGo(1,@Clyde)
                Clyde\x - 1
              Else
                Clyde\lastdir=0
              EndIf
            Case 2
              If CanGo(2,@Clyde)
                Clyde\y -1
              Else
                Clyde\lastdir = 0
              EndIf
            Case 3
              If CanGo(3,@Clyde)
                Clyde\x +1
              Else
                Clyde\lastdir = 0
              EndIf
            Case 4
              If CanGo(4,@Clyde)
                Clyde\y +1
              Else
                Clyde\lastdir = 0
              EndIf
          EndSelect ;}
        EndIf
        Clyde\timer = ElapsedMilliseconds()
      EndIf
    Else
      If ElapsedMilliseconds() - Clyde\timer >= 2000
        Clyde\x = Clyde\Startx : Clyde\y = Clyde\Starty : Clyde\xold = Clyde\Startx : Clyde\yold = Clyde\Starty
        Clyde\state = 0 : Clyde\timer = 0
      EndIf
    EndIf;}
  EndIf
 
  ;{ Affichage des fantomes
  If DispBlinky
    If world(Blinky\xold,Blinky\yold) = #Blob
      ConsoleLocate(Blinky\xold,Blinky\yold+4) : ConsoleColor(7,0) : Print(".")
    ElseIf world(Blinky\xold,Blinky\yold) = #PacGum
      ConsoleLocate(Blinky\xold,Blinky\yold+4) : ConsoleColor(7,0) : Print("o")
    Else
      ConsoleLocate(Blinky\xold,Blinky\yold+4) : Print(" ")
    EndIf
    ConsoleLocate(Blinky\x,Blinky\y+4) 
    If Pacgum And Blinky\state = 2
      If GumCol = 0 Or GumCol = 2
        ConsoleColor(3,0)
      Else
        ConsoleColor(15,0)
      EndIf
    Else
      ConsoleColor(4,0) 
    EndIf
    Print("M")
  EndIf
  If DispPinky
    If world(Pinky\xold,Pinky\yold) = #Blob
      ConsoleLocate(Pinky\xold,Pinky\yold+4) : ConsoleColor(7,0) : Print(".")
    ElseIf world(Pinky\xold,Pinky\yold) = #PacGum
      ConsoleLocate(Pinky\xold,Pinky\yold+4) : ConsoleColor(7,0) : Print("o")
    Else
      ConsoleLocate(Pinky\xold,Pinky\yold+4) : Print(" ")
    EndIf
    ConsoleLocate(Pinky\x,Pinky\y+4)
    If Pacgum And Pinky\state = 2
      If GumCol = 0 Or GumCol = 2
        ConsoleColor(3,0)
      Else
        ConsoleColor(15,0)
      EndIf
    Else
      ConsoleColor(5,0) 
    EndIf
    Print("M")
  EndIf
  If DispInky
    If world(Inky\xold,Inky\yold) = #Blob
      ConsoleLocate(Inky\xold,Inky\yold+4) : ConsoleColor(7,0) : Print(".")
    ElseIf world(Inky\xold,Inky\yold) = #PacGum
      ConsoleLocate(Inky\xold,Inky\yold+4) : ConsoleColor(7,0) : Print("o")
    Else
      ConsoleLocate(Inky\xold,inky\yold+4) : Print(" ")
    EndIf
    ConsoleLocate(Inky\x,Inky\y+4)
    If Pacgum And Inky\state = 2
      If GumCol = 0 Or GumCol = 2
        ConsoleColor(3,0)
      Else
        ConsoleColor(15,0)
      EndIf
    Else
      ConsoleColor(9,0) 
    EndIf
    Print("M")
  EndIf
  If DispClyde
    If world(Clyde\xold,Clyde\yold) = #Blob
      ConsoleLocate(Clyde\xold,Clyde\yold+4) : ConsoleColor(7,0) : Print(".")
    ElseIf world(Clyde\xold,Clyde\yold) = #PacGum
      ConsoleLocate(Clyde\xold,Clyde\yold+4) : ConsoleColor(7,0) : Print("o")
    Else
      ConsoleLocate(Clyde\xold,Clyde\yold+4) : Print(" ")
    EndIf
    ConsoleLocate(Clyde\x,Clyde\y+4)
    If Pacgum And Clyde\state = 2
      If GumCol = 0 Or GumCol = 2
        ConsoleColor(3,0)
      Else
        ConsoleColor(15,0)
      EndIf
    Else
      ConsoleColor(6,0)
    EndIf
    Print("M") 
  EndIf ;}
  If Blinky\x = x And Blinky\y = y : If Blinky\state < 2 : game = #GameDeath : Else : Blinky\state = 3 : Blinky\timer = ElapsedMilliseconds() : score + 250 : EndIf : EndIf
  If Pinky\x = x And Pinky\y = y : If Pinky\state < 2 : game = #GameDeath : Else : Pinky\state = 3 : Pinky\timer = ElapsedMilliseconds() : score + 250 : EndIf : EndIf
  If Inky\x = x And Inky\y = y : If Inky\state < 2 : game = #GameDeath : Else : Inky\state = 3 : Inky\timer = ElapsedMilliseconds() : score + 250 : EndIf : EndIf
  If Clyde\x = x And Clyde\y = y : If Clyde\state < 2 : game = #GameDeath : Else : Clyde\state = 3 : Clyde\timer = ElapsedMilliseconds() : score + 250 : EndIf : EndIf
  If Pacgum
    If ElapsedMilliseconds() - GumTime >= 5000
      GumCol = 1
      GumTime = ElapsedMilliseconds()
    EndIf
    If GumCol And ElapsedMilliseconds() - GumTime >= 200
      If GumCol = 1 : GumCol = 2 : Else : GumCol = 1 : EndIf
      GumTime = ElapsedMilliseconds()
    EndIf
    If ElapsedMilliseconds() - Pacgum >= 8000
      Blinky\timer = 0 : Blinky\lastdir = 0 : If Not Blinky\state = 3 : Blinky\state = 0 : EndIf : Pinky\timer = 0 : Pinky\lastdir = 0 : If Not Pinky\state = 3 : Pinky\state = 0 : EndIf : Inky\timer = 0 : Inky\lastdir = 0 : If Not Inky\state = 3 : Inky\state = 0 : EndIf : Clyde\timer = 0 : Clyde\lastdir = 0 : If Not Clyde\state = 3 : Clyde\state = 0 : EndIf
      Pacgum = 0
    EndIf
  EndIf
EndProcedure
Procedure CheckCrossRoad(*ghost.fantome)
  If (*ghost\x = width Or 0) Or (*ghost\y = heigh Or 0)
    ProcedureReturn #False
  EndIf
  Select *ghost\lastdir
    Case 1,3
      If Not world(*ghost\x,*ghost\y+1) = #Wall Or Not world(*ghost\x,*ghost\y-1) = #Wall
        ProcedureReturn #True
      EndIf
    Case 2,4
      If Not world(*ghost\x+1,*ghost\y) = #Wall Or Not world(*ghost\x-1,*ghost\y) = #Wall
        ProcedureReturn #True
      EndIf
    Default
      ProcedureReturn #True
  EndSelect
  ProcedureReturn #False
EndProcedure
Procedure CanGo(direction,*ghost.fantome)
  Select direction
    Case 1
      If *ghost\x = 1 : ProcedureReturn #False : EndIf
      If Not world(*ghost\x-1,*ghost\y) = #Wall And Not *ghost\lastdir = 3
        ProcedureReturn #True
      EndIf
    Case 2
      If *ghost\y = 1 : ProcedureReturn #False : EndIf
      If Not world(*ghost\x,*ghost\y-1) = #Wall And Not *ghost\lastdir = 4
        ProcedureReturn #True
      EndIf
    Case 3
      If *ghost\x = width-1 : ProcedureReturn #False : EndIf
      If Not world(*ghost\x+1,*ghost\y) = #Wall And Not *ghost\lastdir = 1
        ProcedureReturn #True
      EndIf
    Case 4
      If *ghost\x = heigh-1 : ProcedureReturn #False : EndIf
      If Not world(*ghost\x,*ghost\y+1) = #Wall And Not *ghost\lastdir = 2
        ProcedureReturn #True
      EndIf
  EndSelect
  ProcedureReturn #False
EndProcedure

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 16:06
par djes
"Indice de tableau hors limite"

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 16:51
par boby
Edit : j'ai mis la map dans le code, je n'ai pas de sortie de tableau chez moi :-/

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 17:16
par SPH
Pas d'erreur aussi ici :idea:

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 18:24
par venom
Excellent, merci.






@++

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 19:25
par Fig
On ne peut pas manger des superpacgums pour bouffer les fantômes ?
Sinon très bien, mais un peu rapide pour moi... :mrgreen:

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : mer. 30/août/2017 19:45
par falsam
Merci et je confirme que c'est beaucoup trop rapide.

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : jeu. 31/août/2017 10:42
par boby
Fig a écrit :On ne peut pas manger des superpacgums pour bouffer les fantômes ?
Edit : MAJ du code, fantomes ralentis + Superpacgums.

Les AI étant la même pour pinky inky et clyde (se déplacer au pif) c'est un poil facile maintenant.

Oups, petites réctif de dernière seconde, il y avais un petit bug avec les pacgum.

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : jeu. 31/août/2017 10:53
par djes
Super, ça fonctionne maintenant, et très bien :) Bravo !

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : jeu. 31/août/2017 14:06
par Kwai chang caine
Je n'ose m'imaginer comment il était rapide avant 8O ...parce que là...dire qu'il est lent serait un peu exagéré :lol:
Vraiment cool !!!! en plus il pourrait entrer dans une montre :D
J’espère qu'il te reste encore plein de temps à tuer
Merci du partage 8)

Re: Mac Man !!!!! (mais pas le proxénète)

Publié : ven. 01/sept./2017 1:13
par Ar-S
Très sympa ^^