ASCII+CGArne游戏快乐奶牛

简单的游戏, 让奶牛快乐。真正的 ASCII + CGArne 调色板。FreeBASIC。


随机性地形发生器:



森林组


游戏周期:


羊吃草草
草再生长

完全吃草不再生长

  ScreenRes 640, 480, 8, 4
  
  '' CGArne COLOR PALETTE
  Palette 0, 0, 0, 0
  Palette 1, 34, 52, 209
  Palette 2, 12, 126, 69
  Palette 3, 68, 170, 204
  Palette 4, 138, 54, 34
  Palette 5, 92, 46, 120
  Palette 6, 170, 92, 61
  Palette 7, 181, 181, 182
  Palette 8, 94, 96, 110
  Palette 9, 76, 129, 251
  Palette 10, 108, 217, 71
  Palette 11, 123, 226, 249
  Palette 12, 235, 138, 96
  Palette 13, 226, 61, 105
  Palette 14, 225, 217, 63
  Palette 15, 255, 255, 255
  
  Randomize, 1
  
  Dim ascii_terrain(5) As Integer = > {0, 176, 177, 178, 219}
  Dim ascii_forest(5) As Integer = > {23, 30, 5, 6, 237}
  Dim ascii_water(4) As Integer = > {0, 0, 176, 177}
  Dim ascii_player(2) As Integer = > {1, 2}
  
  Dim palette_grass(4) As Integer = > {10, 2}
  Dim palette_forest(3) As Integer = > {0, 5, 4}
  Dim palette_cow(6) As Integer = > {15, 15, 15, 15, 7, 7}
  Dim palette_player(4) As Integer = > {12, 13, 14, 11}
  
  Dim As Integer max_players = 0
  Dim As Integer max_forest = 1 + Rnd * 2
  Dim As Integer max_cows = 32
  Dim As Integer cow(max_cows, 3)
  
  Dim As Integer max_x = LoWord(Width)
  Dim As Integer max_y = HiWord(Width)
  Dim As Integer terrain(max_x, max_y)
  Dim As Integer no_go(max_x, max_y, 4)
  
  Dim As boolean game_over = 0
  Dim As String key
  Dim As Integer i, x, y, t, no = 0, frames = 0, p, c
  Dim As Integer new_pos_x, new_pos_y, length
  Dim As Integer lake_x, lake_y, lake_size
  Dim As Integer starting_forest(4, 2), starting_forest_id
  Dim As Integer grass_max, grass_hp
  Dim As Integer cows_movement, cows_hunger, cows_alert_length
  Dim As Integer player(4, 4), player_taming = 1
  Dim page As Integer = 0
  
  
  Do
      nexit =0
      grass_max = 0
      grass_hp = 0
      cows_hunger = 5
      cows_movement = 15
      cows_alert_length = 12
      lake_size = 4 + Rnd * 12
      lake_x = max_x / 2 + Rnd * 24
      lake_y = max_y / 2 + Rnd * 24
      max_forest = 1 + Rnd * 3
      starting_forest_id = 0
      
      '' GENERATE COWS
      For i = 0 To max_cows
          cow(i, 0) = max_cows / 2 + Rnd *max_cows
          cow(i, 1) = max_cows / 2 + Rnd *max_cows
          cow(i, 2) = Rnd * 5
      Next
      
      '' SPAWN PLAYER(S)
      For i = 0 To max_players
          x = Rnd *max_x
          y = Rnd *max_y
          player(i, 0) = x
          player(i, 1) = y
          player(i, 2) = ascii_player(Rnd * 1)
          player(i, 3) = 0
      Next
      
      '' GENERATE FOREST
      For i = 0 To max_forest
          x = Rnd *max_x
          y = Rnd *max_y
          no_go(x, y, 0) = ascii_forest(Rnd * 4)
          no_go(x, y, 1) = palette_forest(Rnd * 2)
          no_go(x, y, 2) = 10
          no_go(x, y, 3) = 0
          starting_forest(starting_forest_id, 0) = x
          starting_forest(starting_forest_id, 1) = y
          starting_forest_id = starting_forest_id + 1
      Next
      
      
      '' GENERATE TERRAIN
      For y = 0 To max_y
          For x = 0 To max_x
              
              '' GRASS
              terrain(x, y) = 2 + Rnd * 1
              
              '' EMPTY SPACE
              no_go(x, y, 0) = -1
              no_go(x, y, 3) = -1
              
              '' FOREST
              For i = 0 To max_forest
                  length = Sqr((starting_forest(i, 0) - x) ^ 2 + (starting_forest(i, 1) - y) ^ 2)
                  If length < 2 + Rnd * 12 And Rnd * 10 < 7 Then
                      no_go(x, y, 0) = ascii_forest(Rnd * 4)
                      no_go(x, y, 1) = palette_forest(Rnd * 2)
                      no_go(x, y, 2) = 10
                      no_go(x, y, 3) = 0
                  End If
              Next
              
              '' LAKES
              If Rnd * 100 < 5 Then
                  lake_x = lake_x + (2 - Rnd * 4)
                  lake_y = lake_y + (2 - Rnd * 4)
              End If
              length = Sqr((lake_x - x) ^ 2 + (lake_y - y) ^ 2)
              If (length < lake_size - 1) Or (length < lake_size And Rnd * 10 < 3) Then
                  no_go(x, y, 0) = ascii_water(Rnd * 3)
                  no_go(x, y, 1) = 11
                  no_go(x, y, 2) = 3
                  no_go(x, y, 3) = 1
              End If
              
              '' COUNT GRASS
              If terrain(x, y) > 0 And no_go(x, y, 0) < 0 Then
                  grass_max = grass_max + 1
              End If
          Next
      Next
      
      
      '' START SIMULATION
      Color 0, 15
      Cls
      
      Do
          key = Inkey()
          
          '' PLAYER(S) MOVEMENT EVENTS
          new_pos_x = player(0, 0)
          new_pos_y = player(0, 1)
          '' UP
          If key = Chr(255, 72) Then
              new_pos_y = player(0, 1) - 1
          End If
          '' DOWN
          If key = Chr(255, 80) Then
              new_pos_y = player(0, 1) + 1
          End If
          '' LEFT
          If key = Chr(255, 75) Then
              new_pos_x = player(0, 0) - 1
          End If
          '' RIGHT
          If key = Chr(255, 77) Then
              new_pos_x = player(0, 0) + 1
          End If
          
          '' TAMING (ENTER)
          If key = Chr(9) Then
              player_taming = player_taming * -1
          End If
          
          If new_pos_y > 0 And new_pos_y <= max_y And new_pos_x > 0 And new_pos_x <= max_x Then
              player(0, 0) = new_pos_x
              player(0, 1) = new_pos_y
          End If
          
          
          
          ''ScreenLock()
          
          
          ScreenSet page, page Xor 1
          
          
          grass_hp = 0
          
          '' RENDER TERRAIN (ANIMATE WATER)
          For y = 0 To max_y
              For x = 0 To max_x
                  Locate y, x
                  If no_go(x, y, 0) > -1 Then
                      Color no_go(x, y, 1), no_go(x, y, 2)
                      '' ANIMATE WATER
                      If no_go(x, y, 3) > 0 And Rnd * 100 < 5 Then
                          no_go(x, y, 0) = ascii_water(Rnd * 3)
                      End If
                      '' RENDER NO-GO (trees, water, fences..)
                      Print Chr(no_go(x, y, 0));
                  Else
                      Color palette_grass(0), palette_grass(1)
                      
                      '' GRASS GROWING
                      If terrain(x, y) < 4 And Rnd * 2000 < 1 Then
                          terrain(x, y) = terrain(x, y) + 1
                      End If
                      
                      '' RENDER TERRAIN
                      Print Chr(ascii_terrain(terrain(x, y)));
                      
                      '' COUNT GRASS HP
                      If terrain(x, y) > 0 Then
                          grass_hp = grass_hp + 1
                      End If
                  End If
              Next
          Next
          
          '' RENDER COW
          For i = 0 To max_cows
              Locate cow(i, 1), cow(i, 0)
              Color palette_cow(cow(i, 2)), palette_grass(1)
              Print Chr(64);
          Next
          
          
          '' RENDER PLAYER(S)
          For i = 0 To max_players
              Locate player(i, 1), player(i, 0)
              If frames Mod 10 = 0 Then
                  player(i, 3) = player(i, 3) + 1
                  If player(i, 3) > 3 Then
                      player(i, 3) = 0
                  End If
              End If
              Color palette_player(player(i, 3)), palette_grass(1)
              Print Chr(player(i, 2));
          Next
          
          '' AI
          For c = 0 To max_cows
              For p = 0 To max_players
                  length = Sqr((player(p, 0) - cow(c, 0)) ^ 2 + (player(p, 1) - cow(c, 1)) ^ 2)
                  If (length < cows_alert_length + Rnd * 6 And Rnd * 10 > 5) Or Rnd * 100 < 10 Then
                      If Rnd * 100 < cows_movement Then
                          If length > cows_alert_length Then
                              new_pos_x = cow(c, 0) - 1 + Rnd * 2
                          Else
                              If cow(c, 0) - player(p, 0) >= 0 Then
                                  new_pos_x = cow(c, 0) + player_taming
                              Else
                                  new_pos_x = cow(c, 0) - player_taming
                              End If
                          End If
                          If new_pos_x <= max_x And new_pos_x > 0 And no_go(new_pos_x, cow(c, 1), 0) < 0 Then
                              cow(c, 0) = new_pos_x
                          End If
                      End If
                      If Rnd * 100 < cows_movement Or Rnd * 100 < 10 Then
                          If length > cows_alert_length Then
                              new_pos_y = cow(c, 1) - 1 + Rnd * 2
                          Else
                              If cow(c, 1) - player(p, 1) >= 0 Then
                                  new_pos_y = cow(c, 1) + player_taming
                              Else
                                  new_pos_y = cow(c, 1) - player_taming
                              End If
                          End If
                          If new_pos_y <= max_y And new_pos_y > 0 And no_go(cow(c, 0), new_pos_y, 0) < 0 Then
                              cow(c, 1) = new_pos_y
                          End If
                      End If
                  End If
                  
                  If Rnd * 100 < cows_hunger Then
                      t = terrain(cow(c, 0), cow(c, 1))
                      If t > 0 Then
                          terrain(cow(c, 0), cow(c, 1)) = t - 1
                      End If
                  End If
                  
              Next
          Next
          
          '' HUD
          Locate 2, 2
          Color 14, 13
          Print "DAY ";
          Print no;
          Locate 2, 16
          Print "COWS ";
          Print max_cows;
          Locate 2, 32
          Print "GRASS HP ";
          Print grass_hp;
          Print "/";
          Print grass_max
          Locate 2, max_x - 14
          Print "HAPPY COWS V07"
          
          '' CLOCKS
          frames = frames + 1
          If frames > 24 * 60 Then
              frames = 0
              no = no + 1
          End If
          
          ''ScreenUnlock()
          page Xor = 1
          ScreenSet page, page Xor 1
          
          Sleep(3, 1)
          
      Loop Until nstop Or nexit
  Loop Until nstop


猜你喜欢

转载自blog.csdn.net/yfvb2010/article/details/80597153
今日推荐