s464891-patch-1 #2

Merged
s464891 merged 2 commits from s464891-patch-1 into master 2022-03-09 19:53:33 +01:00
6 changed files with 90 additions and 1 deletions

BIN
assets/images/dirt.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
assets/images/gravel.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
assets/images/sky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
assets/images/tractor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

49
main.py
View File

@ -1 +1,48 @@
print("Hello World")
import pygame
from pygame.locals import *
from world_creator import World
SCREEN_WIDTH = 1100
SCREEN_HEIGHT = 1100
def draw_line(screen: pygame.display, tile_size):
for line in range(0, 11):
pygame.draw.line(screen, (255, 255, 255), (0, line * tile_size), (SCREEN_WIDTH, line*tile_size))
pygame.draw.line(screen, (255, 255, 255), (line * tile_size, 0), (line * tile_size, SCREEN_HEIGHT))
def main():
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
tile_size = 110
world = World(tile_size)
pygame.display.set_caption('TRAKTOHOLIK')
background_image = pygame.image.load('assets/images/sky.png')
background_image = pygame.transform.scale(background_image, (SCREEN_WIDTH, SCREEN_HEIGHT))
tractor_image = pygame.transform.scale(pygame.image.load('assets/images/tractor.png'), (0.9*tile_size, 0.9*tile_size))
run = True
while run:
screen.blit(background_image, (0, 0))
world.draw(screen)
draw_line(screen, tile_size)
screen.blit(tractor_image, (6*tile_size, 5*tile_size))
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()
if __name__ == '__main__':
main()

42
world_creator.py Normal file
View File

@ -0,0 +1,42 @@
import pygame
class World:
world_data = [
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
] # it will be changed when miguel sends his code
def __init__(self, tile_size):
self.tile_list = []
self.dirt_image = pygame.image.load('assets/images/dirt.jpeg')
self.gravel_image = pygame.image.load('assets/images/gravel.jpeg')
row_count = 0
for row in self.world_data:
col_count = 0
for tile in row:
if tile == 1:
img = pygame.transform.scale(self.dirt_image, (tile_size, tile_size))
elif tile == 0:
img = pygame.transform.scale(self.gravel_image, (tile_size, tile_size))
img_rect = img.get_rect()
img_rect.x = col_count * tile_size
img_rect.y = row_count * tile_size
tile = (img, img_rect)
self.tile_list.append(tile)
col_count += 1
row_count += 1
def draw(self, screen):
for tile in self.tile_list:
screen.blit(tile[0], tile[1])