Dodanie Pola i traktora, ale traktor jeszcze nie jeździ. inicjacja pygame.
This commit is contained in:
parent
b1736d80d0
commit
282144395b
BIN
program/.DS_Store
vendored
Normal file
BIN
program/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
program/__pycache__/field.cpython-311.pyc
Normal file
BIN
program/__pycache__/field.cpython-311.pyc
Normal file
Binary file not shown.
BIN
program/__pycache__/tile.cpython-311.pyc
Normal file
BIN
program/__pycache__/tile.cpython-311.pyc
Normal file
Binary file not shown.
BIN
program/__pycache__/tractor.cpython-311.pyc
Normal file
BIN
program/__pycache__/tractor.cpython-311.pyc
Normal file
Binary file not shown.
14
program/field.py
Normal file
14
program/field.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import pygame
|
||||||
|
from tile import Tile
|
||||||
|
from tractor import Tractor
|
||||||
|
|
||||||
|
class Field:
|
||||||
|
def __init__(self):
|
||||||
|
self.tiles = pygame.sprite.Group()
|
||||||
|
for x in range(256):
|
||||||
|
self.tiles.add(Tile(x, 'grass', self))
|
||||||
|
self.tractor = Tractor(self)
|
||||||
|
|
||||||
|
def draw(self, surface):
|
||||||
|
self.tiles.draw(surface)
|
||||||
|
self.tractor.draw(surface)
|
BIN
program/images/grass.png
Normal file
BIN
program/images/grass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 408 B |
BIN
program/images/tractor.png
Normal file
BIN
program/images/tractor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
21
program/main.py
Normal file
21
program/main.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import sys
|
||||||
|
import pygame
|
||||||
|
from field import Field
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pygame.init()
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
SCREEN_WIDTH, SCREEN_HEIGHT = 1024, 1024
|
||||||
|
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
|
field = Field()
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
screen.fill(WHITE)
|
||||||
|
field.draw(screen)
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.time.Clock().tick(30)
|
19
program/tile.py
Normal file
19
program/tile.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
class Tile(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, id, type, field):
|
||||||
|
super().__init__()
|
||||||
|
self.id = id
|
||||||
|
x = id%16
|
||||||
|
y = id//16
|
||||||
|
self.type = type
|
||||||
|
self.field = field
|
||||||
|
if type=='grass':
|
||||||
|
self.image = pygame.image.load('images/grass.png').convert()
|
||||||
|
self.image = pygame.transform.scale(self.image, (64, 64))
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.topleft = (x * 64, y * 64)
|
||||||
|
|
||||||
|
def draw(self, surface):
|
||||||
|
self.tiles.draw(surface)
|
15
program/tractor.py
Normal file
15
program/tractor.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import pygame
|
||||||
|
import os
|
||||||
|
class Tractor(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, field):
|
||||||
|
super().__init__()
|
||||||
|
self.type = type
|
||||||
|
self.field = field
|
||||||
|
self.image = pygame.image.load('images/tractor.png').convert_alpha()
|
||||||
|
self.image = pygame.transform.scale(self.image, (64, 64))
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
x, y = 0, 0
|
||||||
|
self.rect.topleft = (x, y)
|
||||||
|
|
||||||
|
def draw(self, surface):
|
||||||
|
surface.blit(self.image, self.rect)
|
Loading…
Reference in New Issue
Block a user