Last active
July 14, 2018 18:19
-
-
Save yvan/d6551ace488adfced53f35d87fa6293e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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