⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baspacman.bas

📁 Pacman Game Using VB6
💻 BAS
字号:
Attribute VB_Name = "basPacman"
Option Explicit

Sub PacmanMovement()

  Dim HitWall As Boolean
  Dim nLoop As Integer
  Dim XD2 As Integer
  Dim YD2 As Integer
  
  ' atur pacman tidak dalam posisi memakan pil
  Pacman.DotGone = False
  
  ' penggunaan UDTpacman
  With Pacman
  
    .FirstGo = False ' matikan inisial musik
    ' simpan posisi pacman
    Sprite(0).OXpos = .Xpos - 16
    Sprite(0).OYpos = .Ypos - 16
       
    ' Naik
    If GetAsyncKeyState(vbKeyUp) And .Offset = 0 Then
      If PacLevel((.Xpos - 8) / 16, (.Ypos - 8) / 16 - 1).Block <> Pac.Wall Then
      .Direction = 0
      End If
    End If
    
    ' Turun
    If GetAsyncKeyState(vbKeyDown) And .Offset = 0 Then
      If PacLevel((.Xpos - 8) / 16, (.Ypos - 8) / 16 + 1).Block <> Pac.Wall Then
      .Direction = 1
      End If
    End If
    
    ' Kiri
    If GetAsyncKeyState(vbKeyLeft) And .Offset = 0 Then
      If PacLevel((.Xpos - 8) / 16 - 1, (.Ypos - 8) / 16).Block <> Pac.Wall Then
      .Direction = 2
      End If
    End If
    
    ' Kanan
    If GetAsyncKeyState(vbKeyRight) And .Offset = 0 Then
      If PacLevel((.Xpos - 8) / 16 + 1, (.Ypos - 8) / 16).Block <> Pac.Wall Then
      .Direction = 3
      End If
    End If
    
    ' Jika menabrak dinding maka jangan gerakkan pacmman(berjalan menyusuri dinding)
    HitWall = False
    
    ' XD2/YD2 menyimpan posisi pacman
    XD2 = (Pacman.Xpos + XD(Pacman.Direction) * 16 - 8) / 16
    YD2 = (Pacman.Ypos + YD(Pacman.Direction) * 16 - 8) / 16
    
    ' Jika pacman menuju jalur kotak (setiap 16 pixels)
    If .Offset = 0 Then
      Select Case PacLevel(XD2, YD2).Block
        Case Pac.Wall
          HitWall = True ' menabrak dinding, hentikan gerak pacman
        
        Case Pac.Pill
          .DotsLeft = .DotsLeft - 1
          PacLevel(XD2, YD2).Block = 0 ' hapus pil dari buffer/data
          sndPlay "eatpill", SoundOps.SND_ASYNC 'mainkan musik makan
          .DotGone = True ' atur state pacman menjadi makan pil sehingga pil hilang
          AddScore 10
        
        Case Pac.PowerPill
          .GhostsEaten = 0
          .DotsLeft = .DotsLeft - 1
          PacLevel(XD2, YD2).Block = 0 ' hapus power pill (pil warna merah) dari buffer
          sndPlay "fruiteat", SoundOps.SND_ASYNC
          .DotGone = True ' atur state pacman menjadi makan pil sehingga pil hilang
          AddScore 10
          ' pengaturan state ghost menjadi siap dimakan dan penentuan timer serta pembalikan arah ghost
          For nLoop = 1 To 4
            If Ghost(nLoop).Eyesonly = False And Ghost(nLoop).InGame Then
              Ghost(nLoop).PPTimer = (1000 - 100 * Pacman.Level) / Game.Speed ' bergantung level
              Ghost(nLoop).Direction = Rev(Ghost(nLoop).Direction)
            End If
          Next
      End Select
    End If
  
    ' gerakan pacman jika tidak ada dinding didepan arah geraknya
    If HitWall = False Then
        .Xpos = .Xpos + XD(.Direction) * .Speed
        .Ypos = .Ypos + YD(.Direction) * .Speed
        .Offset = (.Offset + OffDir(.Direction) * .Speed + 16) Mod 16
        If .Xpos > 416 Then .Xpos = .Xpos - 416
        If .Xpos < 16 Then .Xpos = .Xpos + 416
    End If
    
    ' animasikan mulutnya setiap 5 frame
    .MouthSpeed = .MouthSpeed + 1
    If .MouthSpeed > 4 Then
      .Mouth = .Mouth + .MouthDir
      .MouthSpeed = 0
    End If
    If .Mouth > 2 Or .Mouth < 1 Then
      .MouthDir = -.MouthDir
    End If
  
  End With
  
  ' pengaturan sprite pacman
  With Sprite(0)
    .NXpos = Pacman.Xpos - 16
    .NYpos = Pacman.Ypos - 16
    .XSprite = Pacman.Direction * 32
    .YSprite = Pacman.Mouth * 32 + 4 * 32
  End With
    
End Sub




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -