Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. import pyrite
  2. import random
  3.  
  4. def __config__():
  5.     return {
  6.         # Application name (used for window tile)
  7.         "application_name": "roguelike",
  8.  
  9.         # Application version
  10.         "application_version": "0.1.0",
  11.  
  12.         # Determines the initial viewport size and scale
  13.         "viewport_scale": 2,
  14.         "viewport_width": 10,
  15.         "viewport_height": 10,
  16.  
  17.         # tileset path
  18.         "tileset_path": "tiles.png",
  19.         # Number of tiles along the horizontal axis
  20.         "tileset_width": 2,
  21.         # Number of tiles along the vertical axis
  22.         "tileset_height": 4,
  23.  
  24.         # Names of each tile in order from left to right, top to bottom.
  25.         "tile_names": [
  26.             "square",
  27.             "circle_1",
  28.             "circle_2",
  29.             "circle_3",
  30.             "tree",
  31.             "flowers",
  32.             "read_the_docs",
  33.             "pyrite"
  34.         ]
  35.     }
  36.  
  37. def __event__(event_type, event_data):
  38.     game_data = pyrite.game_data()
  39.  
  40.     if event_type == "LOAD":
  41.         game_data["draw_trees_timer"] = 0.0;
  42.         player = {}
  43.         player["x"], player["y"]= 0,0
  44.         game_data["viewport_width"] = 10
  45.         game_data["viewport_height"] = 10
  46.         game_data["viewport_scale"] = 2
  47.         pass
  48.  
  49.     if event_type == "BUTTON":
  50.         if event_data["button"] == "ESCAPE":
  51.             pyrite.exit()
  52.  
  53.         if event_data["transition"] == "PRESSED":
  54.             if event_data["button"] == "Q":
  55.                 game_data["viewport_width"] += 1
  56.             if event_data["button"] == "W":
  57.                 game_data["viewport_width"] -= 1
  58.             if event_data["button"] == "A":
  59.                 game_data["viewport_height"] += 1
  60.             if event_data["button"] == "S":
  61.                 game_data["viewport_height"] -= 1
  62.             if event_data["button"] == "Z":
  63.                 game_data["viewport_scale"] += 1
  64.             if event_data["button"] == "X":
  65.                 game_data["viewport_scale"] -= 1
  66.  
  67.             pyrite.set_viewport(
  68.                 game_data["viewport_width"],
  69.                 game_data["viewport_height"],
  70.                 game_data["viewport_scale"]
  71.             )
  72.  
  73.     if event_type == "STEP":
  74.         game_data["draw_trees_timer"] -= event_data["delta_time"]
  75.        
  76.         if game_data["draw_trees_timer"] <= 0.0:
  77.             game_data["draw_trees_timer"] += 0.5
  78.  
  79.             for x in range(10):
  80.                 for y in range(10):
  81.                     position = (x, y)
  82.                     if should_plant_tree():
  83.                         pyrite.set_tile(
  84.                             position,
  85.                             "tree",
  86.                             pick_plant_color(),
  87.                             (False, False),
  88.                             "flowers",
  89.                             pick_plant_color(),
  90.                             (False, False),
  91.                         );
  92.                     else:
  93.                         pyrite.set_tile(
  94.                             position,
  95.                             "flowers",
  96.                             pick_plant_color(),
  97.                             (False, False),
  98.                         );
  99.  
  100.         mouse_left = pyrite.button_down("MOUSE_LEFT")
  101.         mouse_right = pyrite.button_down("MOUSE_RIGHT")
  102.         pyrite.set_tile((4, 1), "pyrite", (255, 255, 255), (mouse_left, mouse_right))
  103.         pyrite.set_tile((5, 1), "read_the_docs", (255, 255, 255), (False, False))
  104.         pyrite.set_tile((player["x"], player["y"]), "circle_1", (255, 255, 255), (space))
  105.        
  106. def pick_plant_color():
  107.     return random.choice([(1,145,135), (146,196,86), (199,228,128), (221,193,85)])
  108.  
  109. def should_plant_tree():
  110.     return random.choice([True, False])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement