Setting up the land
After posting the first devlog I quickly ran to set up some things.
Firstly I made a new Trello board to keep track of the development of the game.
After that I went to my code editor to start the basic skeleton of the game. I set up a main file to run the game and started working on a tile map system.
Tile map rendering
I've already made some tile map rendering systems for some of my other games (for as long as they survived). To be honest, most of them were not the most efficient. I actually never managed to find a good way to render tile maps with pygame, but I'll try better for this one project.
For now, I've created a very inefficient function to render layers (basically 2 dimensional lists)
import pygame as pg
import settings as stgs
def render(layer, center):
gw, gh = stgs.grid_w, stgs.grid_h
x, y = center
left, right = x - gw, x + gw
top, bottom = y - gh, y + gh
if left < 0: left = 0
if right > (l := len(layer[0])): right = l
if top < 0: top = 0
if bottom > (l := len(layer)): bottom = l
chunck = layer[top:bottom]
ts = stgs.tile_size
for y, row in enumerate(chunck):
for x, tile in enumerate(row):
stgs.screen.blit(
tile.image, (
x*ts+stgs.margin_w,
y*ts+stgs.margin_h
)
)
center
will be the player coordinate position within the grid.
The grid_w
is the amount of tiles that fit the width of the screen. I calculate that in the settings file (maybe not the best place) just by dividing the width of the screen by the size of each tile. Same works for the grid_h
but for the height.
Just so I don't have to explain everything one by one, here's the settings file for now:
import pygame as pg
pg.init()
# SETUP
screen = pg.display.set_mode()
clock = pg.time.Clock()
running = True
# SCREEN
W, H = screen.get_size()
# TILES
tile_pixels = 16
tile_size = 64
# GRID
grid_w = W // tile_size
grid_w -= 0 if grid_w % 2 else 1
grid_h = H // tile_size
grid_h -= 0 if grid_h % 2 else 1
margin_w = W/2 - grid_w * tile_size / 2
margin_h = H/2 - grid_h * tile_size / 2
(The reason I'm modifying grid_w
and grid_h
if their value is even is to have a central tile to render the player right in the middle of the screen.)
Finally, I created a tile class for testing:
class Tile:
def __init__(self):
size = stgs.tile_size
self.image = pg.Surface((size, size))
self.image.fill(
choice(['green', 'blue'])
)
Putting all of it together and setting a test layer full of these tiles, I've got something like this:
I need sleep
Honestly, I didn't really "run" to do these things as I said in the beginning of this post. After the first post I just laid on my bed and fought against my brain for a good amount of hours. It's past 1am now and I've only got what I showed. I know this is not a place to rant but I think it'll be fun reading this in the future and probably finding out I didn't change much ๐
Final words
For now that's it. The plan for tomorrow is sketching some basic art for the game and implementing the player movement.
Thanks for reading!
Top comments (0)