SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3. from vikingclasses import Main
  4.  
  5. pygame.init()
  6. # create
  7. window = pygame.display.set_mode((600, 500))
  8. pygame.display.set_caption("Viking Game")
  9.  
  10.  
  11. # colors
  12. WHITE = (255, 255, 255)
  13. BLACK = (0, 0, 0)
  14. GREY = (100, 100, 100)
  15. RED = (255, 0, 0)
  16. GREEN = (0, 255, 0)
  17. BLUE = (0, 0, 255)
  18.  
  19.  
  20. # main class
  21. grid = Main(600, 500, 50, GREY, window)
  22.  
  23.  
  24.  
  25. # player size and coordinates
  26. playerx = 100
  27. playery = 100
  28.  
  29.  
  30. # clock
  31. clock = pygame.time.Clock()
  32.  
  33.  
  34.  
  35.  
  36. run = True
  37.  
  38. # mainloop
  39. while run:
  40.     clock.tick(30)
  41.     for event in pygame.event.get():
  42.         # escape function
  43.         if event.type == pygame.K_ESCAPE:
  44.             run = False
  45.         if event.type == pygame.QUIT:
  46.             run = False
  47.         # movement input
  48.         if event.type == pygame.KEYDOWN:
  49.             if event.key == pygame.K_w:
  50.                 playery -= tilesize
  51.             if event.key == pygame.K_s:
  52.                 playery += tilesize
  53.             if event.key == pygame.K_a:
  54.                 playerx -= tilesize
  55.             if event.key == pygame.K_d:
  56.                 playerx += tilesize
  57.  
  58.     grid.draw_grid()
  59.  
  60.  
  61.  
  62.  
  63.  
  64.     # background
  65.     window.fill(BLACK)
  66.     # player
  67.     pygame.draw.rect(window, (0,200,0), (playerx, playery, grid.tilesize, grid.tilesize))
  68.  
  69.     pygame.display.update()
  70.  
  71. pygame.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top