Skip to content

Instantly share code, notes, and snippets.

@yvan
Last active July 14, 2018 18:19
Show Gist options
  • Save yvan/d6551ace488adfced53f35d87fa6293e to your computer and use it in GitHub Desktop.
Save yvan/d6551ace488adfced53f35d87fa6293e to your computer and use it in GitHub Desktop.
import pygame
# declare the size of the map
# and the size of map tiles
# tile size is in pixels
# other sizes are in number of
# tiles
TILESIZE = 40
MAPWIDTH = 30
MAPHEIGHT = 20
# load the image for the player's
# character
player = pygame.image.load('char.png')
# set the player's position
# the first element controls left-right
# the second element controls up-down
playerPos = [0,0]
# initilaize the game object
pygame.init()
# intialize the display surface. this surface is what pygame draws
# things on
DISPLAYSURF = pygame.display.set_mode((MAPWIDTH*TILESIZE,MAPHEIGHT*TILESIZE))
# this loop runs once every few milliseconds
# executing the code inside it
while True:
# place the player object (the loaded image)
# on the tile in playerPos, [0, 0], multiplying by TILESIZE
# tells us to put the character at the right nummer of pixels
DISPLAYSURF.blit(player,(playerPos[0]*TILESIZE, playerPos[1]*TILESIZE))
# update the display every iteration of this loop
pygame.display.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment