Guest User

Untitled

a guest
Jul 4th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     ' Project Dead Sea-Bass
  2.      
  3.     #include "fbgfx.bi"
  4.      
  5.     screenres 640,480,32
  6.      
  7.     #define true 1
  8.     #define false not( true )
  9.      
  10.     type door
  11.        as integer x, y
  12.        as integer is_open
  13.        as uinteger color
  14.        as integer switch_number
  15.        as integer enabled
  16.     end type
  17.      
  18.     type switch
  19.        as integer x,y
  20.        as uinteger color
  21.        as integer door_number
  22.        as integer enabled
  23.         as integer player_number
  24.     end type
  25.      
  26.     dim as door doorlist( 0 to 9 )
  27.     dim as switch switchlist( 0 to 9 )
  28.      
  29.     ' Set up a door
  30.     doorlist( 0 ).x = 5
  31.     doorlist( 0 ).y = 5
  32.     doorlist( 0 ).color = RGB(255,0,0)
  33.     doorlist( 0 ).is_open = false ' true means its open
  34.     doorlist( 0 ).enabled = true
  35.      
  36.  
  37.     ' Set up a switch
  38.     switchlist( 0 ).x = 7
  39.     switchlist( 0 ).y = 8
  40.     switchlist( 0 ).color = RGB(0,255,0)
  41.     switchlist( 0 ).door_number = 1
  42.     switchlist( 0 ).enabled = true
  43.     switchlist( 0 ).player_number = 1
  44.     ' Set up a switch
  45.      
  46.     doorlist( 1 ).x = 3
  47.     doorlist( 1 ).y = 3
  48.     doorlist( 1 ).color = RGB(255,0,0)
  49.     doorlist( 1 ).is_open = false ' true means its open
  50.     doorlist( 1 ).enabled = true
  51.  
  52.     switchlist( 1 ).x = 1
  53.     switchlist( 1 ).y = 4
  54.     switchlist( 1 ).color = RGB(255,255,255)
  55.     switchlist( 1 ).door_number = 0
  56.     switchlist( 1 ).enabled = true
  57.     switchlist( 1 ).player_number = 2
  58.     ' These will store our player coordinates
  59.     ' We give these values later when we search the map for the player start position
  60.     dim as integer player_x, player_y
  61.     Dim as integer player2_x, Player2_y
  62.     ' Our 10 by 10 grid for the map
  63.     dim map( 0 to 9, 0 to 9 ) as Integer => { _
  64.           {9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, _
  65.           {9, 0, 0, 9, 0, 0, 0, 0, 2, 9}, _
  66.           {9, 3, 0, 9, 0, 0, 0, 0, 0, 9}, _
  67.           {9, 0, 0, 0, 0, 0, 0, 0, 0, 9}, _
  68.           {9, 0, 0, 9, 0, 0, 0, 0, 0, 9}, _
  69.           {9, 9, 9, 9, 9, 0, 9, 9, 9, 9}, _
  70.           {9, 0, 0, 0, 0, 0, 0, 0, 0, 9}, _
  71.           {9, 0, 0, 0, 0, 0, 0, 0, 0, 9}, _
  72.           {9, 1, 0, 0, 0, 0, 0, 0, 0, 9}, _
  73.           {9, 9, 9, 9, 9, 9, 9, 9, 9, 9} _
  74.           }
  75.      
  76.     ' The values in the map array mean the below things.....
  77.     ' 0 = Floor
  78.     ' 1 = Player start
  79.     ' 2 = Exit
  80.     ' 3= Player2
  81.     ' 9 = Wall
  82.    
  83.    
  84.     ' 10 = Door
  85.     ' 11 = Switch
  86.     ' 12 = Door
  87.     ' 13 = Switch
  88.      
  89.     ' Finds the player start position in the map array
  90.     '
  91.    
  92.     for map_y as integer = 0 to 9 ' Look at each row...
  93.        for map_x as integer = 0 to 9 ' Look at each position in the row...
  94.           if( map( map_x, map_y ) = 1 ) then ' If the map at this coordinate stores a 1...
  95.              ' We found our player start position.
  96.              player_x = map_x
  97.              player_y = map_y
  98.              
  99.              
  100.              exit for
  101.              exit for
  102.          
  103.           end if
  104.        next map_x
  105.     next map_y
  106.      
  107.        for map_y as integer = 0 to 9 ' Look at each row...
  108.        for map_x as integer = 0 to 9 ' Look at each position in the row...
  109.              if (map (map_x, Map_y) = 3) Then  
  110.                 Player2_x = map_x
  111.                 Player2_y = map_y
  112.    
  113.              
  114.              
  115.              exit for
  116.              exit for
  117.          
  118.           end if
  119.        next map_x
  120.     next map_y
  121.        
  122.  
  123.    ' These will hold where the player WANTS to go!
  124.     dim as integer new_player_x, new_player_y
  125.    
  126.     dim as integer New_Player2_x, new_player2_y
  127.    
  128.     do ' Start our main game loop
  129.      
  130.        while inkey <> "": wend ' clear the key buffer
  131.      
  132.        
  133.        new_player_x = player_x
  134.        new_player_y = player_y
  135.        
  136.        new_player2_x = player2_x
  137.        new_player2_y = player2_y
  138.        
  139.      
  140.        ' See where the plater wants to go...
  141.        if multikey (FB.SC_Right ) then new_player_x = player_x + 1
  142.        If Multikey (FB.SC_left  ) Then new_player_x = player_x - 1
  143.        If Multikey (FB.SC_up   ) THen new_player_y = player_y - 1
  144.        If Multikey (FB.SC_down  ) THen new_player_y = player_y + 1
  145.        
  146.        
  147.         If multikey (FB.sc_w  ) then new_player2_Y = player2_y - 1
  148.         If Multikey (FB.SC_s  ) THen new_player2_y = player2_y + 1
  149.         if multikey (FB.SC_d  ) then new_player2_x = player2_x + 1
  150.         If Multikey (FB.SC_a  ) Then new_player2_x = player2_x - 1
  151.        ' Allow the player to "slide" along the walls
  152.        ' If the player is able to move vertically then apply that to the player position
  153.        if( map( player_x, new_player_y ) < 9 ) then
  154.           player_y = new_player_y
  155.        end if
  156.        
  157.        ' If the player is able to move horizontally then apply that to the player position
  158.        if( map( new_player_x, player_y ) < 9 ) then
  159.           player_x = new_player_x
  160.        end if
  161.        
  162.        
  163.        
  164.        if( map( player2_x, new_player2_y ) < 9 ) then
  165.           player2_y = new_player2_y
  166.        end if
  167.        
  168.        ' If the player is able to move horizontally then apply that to the player position
  169.        if( map( new_player2_x, player2_y ) < 9 ) then
  170.           player2_x = new_player2_x
  171.        end if
  172.      
  173.       'for exit
  174.       if( map( player_x, player_y ) = 2 ) AND ( map( player2_x, player2_y ) = 2 ) then
  175.          print "nice"
  176.        end if
  177.      
  178.        screenlock
  179.      
  180.           cls
  181.      
  182.           ' Draw the map on the screen
  183.           for map_y as integer = 0 to 9
  184.              for map_x as integer = 0 to 9
  185.                
  186.                 ' c will store a colour
  187.                 dim as uinteger c
  188.                
  189.                 ' Remember the values in the map array mean the below things.....
  190.                 ' 0 = Floor
  191.                 ' 1 = Player start
  192.                 ' 2 = Exit
  193.                 ' 9 = Wall
  194.                 ' 10 = Door
  195.                 ' 11 = Switch
  196.                 ' 12 = Door
  197.                 ' 13 = Switch            
  198.                
  199.                 select case map( map_x, map_y )
  200.                 case 0
  201.                    c = RGB( 0,0,0 )
  202.                 case 1
  203.                    c = RGB( 0,0,0 )
  204.                 case 2
  205.                    c = RGB( 255,255,0 )
  206.                 case 9
  207.                    c = RGB( 128,128,128 )
  208.                 end select
  209.                
  210.                 ' Draw a coloured box depending on the map
  211.                 line ( map_x * 16, map_y * 16 )-step( 15, 15 ), c, BF
  212.                
  213.              next map_x
  214.           next map_y
  215.          
  216.           ' cycle through all doors and switches
  217.           for i as integer = 0 to 9
  218.              
  219.              ' this door is enabled so lets see if its open or closed
  220.              if( doorlist( i ).enabled = true ) then
  221.                
  222.                 ' Draw this door if its closed
  223.                 if( doorlist( i ).is_open = false ) then
  224.                    
  225.                    line ( doorlist( i ).x * 16, doorlist( i ).y * 16 )-step( 15, 15 ), doorlist( i ).color, B
  226.                    
  227.                    ' Edit the map and place a wall where this closed door is.
  228.                    map( doorlist( i ).x, doorlist( i ).y ) = 10
  229.                    
  230.                 else ' If the door is open...
  231.                    
  232.                    ' Edit the map and place a floor where this open door is.
  233.                    map( doorlist( i ).x, doorlist( i ).y ) = 0
  234.                 end if
  235.              end if
  236.              
  237.              ' this switch is enabled so draw it
  238.              if( switchlist( i ).enabled = true ) then
  239.                
  240.                 ' Draw the switch            
  241.                 circle ( switchlist( i ).x * 16 + 7, switchlist( i ).y * 16 + 7 ), 5, switchlist( i ).color
  242.                
  243.                if (switchlist (i).player_number = 1) then
  244.                ' Are we standing on it??
  245.                 if( player_x = switchlist( i ).x ) AND ( player_y = switchlist( i ).y ) then
  246.                    
  247.                    doorlist( switchlist( i ).door_number ).is_open = true
  248.                 else
  249.                    
  250.                    doorlist( switchlist( i ).door_number ).is_open = false
  251.                    
  252.                 end if
  253.                end if
  254.                
  255.                if (switchlist (i).player_number = 2) then
  256.                ' Are we standing on it??
  257.                 if( player2_x = switchlist( i ).x ) AND ( player2_y = switchlist( i ).y ) then
  258.                    
  259.                    doorlist( switchlist( i ).door_number ).is_open = true
  260.                 else
  261.                    
  262.                    doorlist( switchlist( i ).door_number ).is_open = false
  263.                    
  264.                 end if
  265.                end if
  266.              end if
  267.              
  268.           next i
  269.      
  270.           ' Draw the player
  271.           circle ( player_x * 16 + 7, player_y * 16 + 7 ), 4, RGB( 0, 255, 0 ),,,,F
  272.           ' Draw our collision check (the place the player WANTS to go)
  273.           circle ( new_player_x * 16 + 7, new_player_y * 16 + 7 ), 2, RGB( 0, 255, 255 ),,,,F
  274.        
  275.         Circle (player2_x  * 16 + 7, player2_y * 16 + 7), 4, RGB (255, 255, 255),,,,F
  276.        
  277.        screenunlock
  278.      
  279.        sleep 70, 1  ' Deep sleep (ignore keypresses)
  280.      
  281.     loop until multikey( FB.SC_ESCAPE )
Add Comment
Please, Sign In to add comment