feat: adjust window size based on TILE_SIZE
This commit is contained in:
parent
f8e5d9574f
commit
d9f07cdfe6
@ -1,12 +1,16 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
from field import Field
|
from field import Field
|
||||||
|
import os
|
||||||
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pygame.init()
|
pygame.init()
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
SCREEN_WIDTH, SCREEN_HEIGHT = 1024, 1024
|
# loading TILE_SIZE to adjust window size
|
||||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
load_dotenv(find_dotenv())
|
||||||
|
WINDOW_SIZE = int(os.getenv("TILE_SIZE")) * 16
|
||||||
|
screen = pygame.display.set_mode((WINDOW_SIZE, WINDOW_SIZE))
|
||||||
field = Field()
|
field = Field()
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
|
11
src/tile.py
11
src/tile.py
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import pygame
|
import pygame
|
||||||
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
|
||||||
class Tile(pygame.sprite.Sprite):
|
class Tile(pygame.sprite.Sprite):
|
||||||
def __init__(self, id, type, field):
|
def __init__(self, id, type, field):
|
||||||
@ -11,7 +12,10 @@ class Tile(pygame.sprite.Sprite):
|
|||||||
self.field = field
|
self.field = field
|
||||||
self.set_type(type)
|
self.set_type(type)
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.topleft = (x * 64, y * 64)
|
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||||
|
self.rect.topleft = (x * TILE_SIZE, y * TILE_SIZE)
|
||||||
|
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
self.tiles.draw(surface)
|
self.tiles.draw(surface)
|
||||||
@ -20,6 +24,9 @@ class Tile(pygame.sprite.Sprite):
|
|||||||
self.type = type
|
self.type = type
|
||||||
if self.type == 'grass':
|
if self.type == 'grass':
|
||||||
self.image = pygame.image.load('src/images/grass.png').convert()
|
self.image = pygame.image.load('src/images/grass.png').convert()
|
||||||
self.image = pygame.transform.scale(self.image, (64, 64))
|
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||||
|
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import os
|
import os
|
||||||
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
|
||||||
class Tractor(pygame.sprite.Sprite):
|
class Tractor(pygame.sprite.Sprite):
|
||||||
def __init__(self, field):
|
def __init__(self, field):
|
||||||
super().__init__
|
super().__init__
|
||||||
self.field = field
|
self.field = field
|
||||||
self.image = pygame.image.load('src/images/tractor.png').convert_alpha()
|
self.image = pygame.image.load('src/images/tractor.png').convert_alpha()
|
||||||
self.image = pygame.transform.scale(self.image, (64, 64))
|
# you can set TILE_SIZE in the .env to adjust window size
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||||
|
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
x, y = 0, 0
|
x, y = 0, 0
|
||||||
self.rect.topleft = (x, y)
|
self.rect.topleft = (x, y)
|
||||||
@ -14,14 +19,18 @@ class Tractor(pygame.sprite.Sprite):
|
|||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|
||||||
def move(self, direction):
|
def move(self, direction):
|
||||||
|
# you can set TILE_SIZE in the .env to adjust window size
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||||
|
|
||||||
if direction == "up":
|
if direction == "up":
|
||||||
self.rect.y -= 64
|
self.rect.y -= TILE_SIZE
|
||||||
elif direction == "down":
|
elif direction == "down":
|
||||||
self.rect.y += 64
|
self.rect.y += TILE_SIZE
|
||||||
elif direction == "left":
|
elif direction == "left":
|
||||||
self.rect.x -= 64
|
self.rect.x -= TILE_SIZE
|
||||||
elif direction == "right":
|
elif direction == "right":
|
||||||
self.rect.x += 64
|
self.rect.x += TILE_SIZE
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
Loading…
Reference in New Issue
Block a user