# Game_Matrix

a guest
Jan 4th, 2018
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #-- include('examples/showgrabbox.py')--#
2. import pyscreenshot as ImageGrab
3. from time import sleep
4.
5.
6. #------------------------------------------------
8. #User must change these varibles for specific screen size.
9. #Current values are set for 1920x1080 screens
12. x_width = 1348
13. y_length = 944
14.
15. #starting square for bottom left cell
16. x_start = 279
17. y_start = 542
18.
19. #------------------------------------------------
20.
21. gameMatrix = [[0 for x in range(10)] for y in range(20)] #matrix for game grid
22.
23.
24. def getGameState():
26.
27.
28.     for y in range (0,20):
29.         row_block_count = 0 #reset after every row
30.
31.         #----------------------------------------------------------------------#
32.             #row scanning sub method
33.         for x in range (0,10):
34.             colour = pix[(x_start + (x * 26)), (y_start - (y * 26))] #gets the rgb value of cell every cell (left to right), (bottom to top)
35.             #print (colour)
36.             if not(colour[0] < 10 and colour[1] < 10 and colour [2] < 10): #if the cell isn't empty
37.
38.                 gameMatrix[y][x] = 1 #add a 1 to that cell position
39.                 row_block_count
40.                 #check if there is a block in this spot
41.         #----------------------------------------------------------------------#
42.         if (x == 0):
43.             return()
44.             #break scanning if whole row is empty to save time
45.     return()
46.     #once done
47.
48. if __name__ == "__main__":
49.     # part of the screen
50.     sleep(5)
51.     #im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
53.     #im.show()
54.     im.save("GAMESCREEN.png")
55.     getGameState()
56.
57.
58. #-------------------------------------------------
59. #code for testing. Check with screenshot to see if the code is working correctly.
60.     for y in range (19,-1,-1):
61.         print ("\n")
62.         for x in range (0,10):
63.             print(gameMatrix[y][x], end='')
64.
65. #-------------------------------------------------
66.
67. #-#
RAW Paste Data