The main problem right now is that the player sprites disappear as soon as I zoom in or out the qrid scales correctly though. I had it working with the player sprites on screen then their movement stopped working. Got a little frustrated, then deleted the zoom altogether. Restarted, and now I'm here so I figured posting my first question because the internet didn't have the answers readily available.
import pygame as pg
class game():
def __init__(self):
self.WIDTH, self.HEIGHT = 1000, 700
self.win = pg.display.set_mode((self.WIDTH, self.HEIGHT), pg.RESIZABLE)
self.mapsurface = pg.surface.Surface((10000, 10000))
self.walls = pg.sprite.Group()
self.all_sprites = pg.sprite.Group()
self.player = Player("map assets/tokens/firegenasiwizard.png", self, 5, 5, self.mapsurface)
self.jplayer = Player("map assets/tokens/goliathbarbarian.png", self, 4, 4, self.mapsurface)
self.players = [self.player, self.jplayer]
def event_tracker(self):
global cellsize, spritesize
for event in pg.event.get():
if event.type is pg.QUIT:
pg.display.quit()
pg.quit()
sys.exit()
if event.type == pg.MOUSEBUTTONDOWN:
pos = pg.mouse.get_pos()
for play in self.players:
if play.rect.x <= pos[0] <= play.rect.x + spritesize and \
play.rect.y <= pos[1] <= play.rect.y + spritesize and play.selected is False:
play.selected = True
elif play.rect.x <= pos[0] <= play.rect.x + spritesize and \
play.rect.y <= pos[1] <= play.rect.y + spritesize and play.selected is True:
play.selected = False
if event.type == pg.KEYDOWN:
for play in self.players:
if event.key == pg.K_UP and play.selected is True:
play.move(dx=0, dy=-1)
if event.key == pg.K_DOWN and play.selected is True:
play.move(dx=0, dy=1)
if event.key == pg.K_LEFT and play.selected is True:
play.move(dx=-1, dy=0)
if event.key == pg.K_RIGHT and play.selected is True:
play.move(dx=1, dy=0)
if event.type == pg.MOUSEWHEEL:
if event.y > 0:
self.mapsurface = pg.transform.scale(self.mapsurface, (self.mapsurface.get_width() + 10,
self.mapsurface.get_height() + 10))
cellsize += 10
spritesize += 10
for play in self.players:
play.scale(10)
if event.y < 0:
self.mapsurface = pg.transform.scale(self.mapsurface, (self.mapsurface.get_width() - 10,
self.mapsurface.get_height() - 10))
cellsize -= 10
spritesize -= 10
for play in self.players:
play.scale(-10)
def draw_grid(self):
self.mapsurface.fill(white)
for x in range(0, self.mapsurface.get_width(), cellsize):
pg.draw.line(self.mapsurface, black, (x, 0), (x, 10000), 1)
for y in range(0, self.mapsurface.get_height(), cellsize):
pg.draw.line(self.mapsurface, black, (0, y), (10000, y), 1)
def draw_window(self):
self.draw_grid()
for play in self.players:
play.draw()
self.win.blit(self.mapsurface, (0, 0))
pg.display.update()