To add a map, simply
map[last map number+1]
. For example, if the last map was named map2
, name your map map3
. Each number represents a block in the world.
To see which available blocks you can paint the map with, go to map.py.
In the draw
function, there should be a list of all the numbers and sprites to paint the map with.
See adding sprites to add your own tile to paint the map with.
img
folderspriteName = pygame.image.load('img/fileName.png');
draw()
function.if tile == '1':
display.blit(sprites.dirt, (x * TILE_SIZE, y * TILE_SIZE))
elif tile == '2':
display.blit(sprites.grass, (x * TILE_SIZE, y * TILE_SIZE))
elif tile == 'lastNumber+1':
display.blit(sprites.spriteName, (x * TILE_SIZE, y * TILE_SIZE))
Now you can add the tile in a map using the tile number you assigned it to!
player = Player(pygame.Rect(50, 50, sprites.player.get_width(), sprites.player.get_height()))
enemy = Enemy(pygame.Rect(50, 50, sprites.enemy.get_width(), sprites.enemy.get_height())
enemyName = Enemy(pygame.Rect(50, 50, sprites.enemyName.get_width(), sprites.enemyName.get_height())
display.blit(sprites.enemyName, (enemyName.rect.x, enemyName.rect.y))
enemyName.moveRoutine(pygame, map, player)
Run the code; the enemy should be in there!
The player and enemy classes are found in enemy.py and player.py. Shown in the __init__() function, they share the same movement properties, including:
rect
, the hitbox of the player/enemyair_timer
, the amount of time the player/enemy is in the airmovement
, stores vertical and horizontal movement of the player/enemy. It's an array with two values - [x, y]
. The first value, x
, represents horizontal movement, and the second value, y
, represents vertical movement.direction
, horizontal direction of player/enemy. -1 = moving left, 0 = not moving horizontally, 1 = moving right.y_momentum
, vertical speed of the enemy/player.collides
: returns true if the player is colliding the rect
passed in as a parameter.move
: moves the player based off of the player's direction, collisions, and y_momentum. Called in main.py.getMovementInput
: gets WASD input from the keyboard.moveRoutine
: moves enemy in a routine.moveRight
, stopMovement
, and moveLeft
: moves enemy right, left, or stops movement.move
: moves the player based off of the enemy's direction, collisions, and y_momentum. Called in main.py.