Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- from vikingclasses import Main
- pygame.init()
- # create
- window = pygame.display.set_mode((600, 500))
- pygame.display.set_caption("Viking Game")
- # colors
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- GREY = (100, 100, 100)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- BLUE = (0, 0, 255)
- # main class
- grid = Main(600, 500, 50, GREY, window)
- # player size and coordinates
- playerx = 100
- playery = 100
- # clock
- clock = pygame.time.Clock()
- run = True
- # mainloop
- while run:
- clock.tick(30)
- for event in pygame.event.get():
- # escape function
- if event.type == pygame.K_ESCAPE:
- run = False
- if event.type == pygame.QUIT:
- run = False
- # movement input
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_w:
- playery -= tilesize
- if event.key == pygame.K_s:
- playery += tilesize
- if event.key == pygame.K_a:
- playerx -= tilesize
- if event.key == pygame.K_d:
- playerx += tilesize
- grid.draw_grid()
- # background
- window.fill(BLACK)
- # player
- pygame.draw.rect(window, (0,200,0), (playerx, playery, grid.tilesize, grid.tilesize))
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement