grafika+object skała+agent nie wychodzi poza mapę
BIN
__pycache__/agent.cpython-39.pyc
Normal file
BIN
__pycache__/config.cpython-39.pyc
Normal file
BIN
__pycache__/map_add_ons.cpython-310.pyc
Normal file
BIN
__pycache__/map_add_ons.cpython-39.pyc
Normal file
19
agent.py
@ -17,11 +17,12 @@ class Agent(pygame.sprite.Sprite):
|
||||
self.x_change = 0
|
||||
self.y_change = 0
|
||||
|
||||
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf.jpg")
|
||||
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf.png")
|
||||
self.AGENT = pygame.transform.scale(self.AGENT_IMG,(64,64))
|
||||
|
||||
self.image = pygame.Surface([self.width, self.height])
|
||||
self.image.blit(self.AGENT, (0,0))
|
||||
self.image.set_colorkey((0, 0, 0))
|
||||
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.x = self.x
|
||||
@ -40,11 +41,11 @@ class Agent(pygame.sprite.Sprite):
|
||||
|
||||
def movement(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT]:
|
||||
self.x_change -= PLAYER_SPEED
|
||||
if keys[pygame.K_RIGHT]:
|
||||
self.x_change += PLAYER_SPEED
|
||||
if keys[pygame.K_UP]:
|
||||
self.y_change -= PLAYER_SPEED
|
||||
if keys[pygame.K_DOWN]:
|
||||
self.y_change += PLAYER_SPEED
|
||||
if keys[pygame.K_LEFT] and self.rect.x > 0:
|
||||
self.x_change -= TILE_SIZE
|
||||
if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64:
|
||||
self.x_change += TILE_SIZE
|
||||
if keys[pygame.K_UP] and self.rect.y > 0:
|
||||
self.y_change -= TILE_SIZE
|
||||
if keys[pygame.K_DOWN] and self.rect.y < 832 - 64:
|
||||
self.y_change += TILE_SIZE
|
@ -1,6 +1,6 @@
|
||||
FRAMERATE = 30
|
||||
WIDTH, HEIGHT = 800, 800
|
||||
WIDTH, HEIGHT = 832, 832
|
||||
TILE_SIZE = 64
|
||||
BLACK = ((0,0,0))
|
||||
WHITE = ((255,255,255))
|
||||
PLAYER_SPEED = 3
|
||||
#PLAYER_SPEED = 3
|
37
main.py
@ -1,7 +1,7 @@
|
||||
import pygame
|
||||
import random
|
||||
from config import *
|
||||
from agent import *
|
||||
from map_add_ons import *
|
||||
|
||||
class Game:
|
||||
|
||||
@ -11,29 +11,35 @@ class Game:
|
||||
self.running = True
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
|
||||
# te wszystkie obrazki trzeba dać w oddzielnej klasie dla potworków jak coś później
|
||||
self.ARCHER_ORK_IMG = pygame.image.load("./zdjecia/ork_lucznik.jpg")
|
||||
self.INFATRY_ORK_IMG = pygame.image.load("./zdjecia/ork-piechota.jpg")
|
||||
self.INFANTRY_ORK2_IMG = pygame.image.load("./zdjecia/ork-piechota2.jpg")
|
||||
self.SAURON_JPG = pygame.image.load("./zdjecia/sauron.jpg")
|
||||
# te wszystkie obrazki trzeba dać w oddzielnej klasie dla potworków jak coś później
|
||||
#self.ARCHER_ORK_IMG = pygame.image.load("./zdjecia/ork_lucznik.png")
|
||||
#self.INFATRY_ORK_IMG = pygame.image.load("./zdjecia/ork-piechota.png")
|
||||
#self.INFANTRY_ORK2_IMG = pygame.image.load("./zdjecia/ork-piechota2.png")
|
||||
#self.SAURON_IMG = pygame.image.load("./zdjecia/sauron.png")
|
||||
self.BACKGROUND_IMG= pygame.image.load("./zdjecia/podloze.jpg")
|
||||
|
||||
|
||||
self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64))
|
||||
self.INFATRY_ORK = pygame.transform.scale(self.INFATRY_ORK_IMG,(64,64))
|
||||
self.INFANTRY_ORK2 = pygame.transform.scale(self.INFANTRY_ORK2_IMG,(64,64))
|
||||
self.SAURON = pygame.transform.scale(self.SAURON_JPG,(64,64))
|
||||
#self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64))
|
||||
#self.INFATRY_ORK = pygame.transform.scale(self.INFATRY_ORK_IMG,(64,64))
|
||||
#self.INFANTRY_ORK2 = pygame.transform.scale(self.INFANTRY_ORK2_IMG,(64,64))
|
||||
#self.SAURON = pygame.transform.scale(self.SAURON_png,(64,64))
|
||||
self.BACKGROUND = pygame.transform.scale(self.BACKGROUND_IMG,(64,64))
|
||||
|
||||
self.ORK_LIST = [self.ARCHER_ORK,self.INFANTRY_ORK2, self.INFATRY_ORK]
|
||||
#self.ORK_LIST = [self.ARCHER_ORK,self.INFANTRY_ORK2, self.INFATRY_ORK]
|
||||
|
||||
pygame.display.set_caption('Do_Nazwania')
|
||||
|
||||
def new(self): # tworzy się nowa sesja grania
|
||||
self.all_sprites = pygame.sprite.LayeredUpdates()
|
||||
self.rock_sprites = pygame.sprite.Group()
|
||||
self.agent = Agent(self,1,1)
|
||||
for y in range(5):
|
||||
self.rock = Rocks(self,3,y)
|
||||
|
||||
def update(self): # update postaci na mapie, związane z poruszaniem się
|
||||
self.all_sprites.update()
|
||||
pygame.sprite.spritecollide(self.agent, self.rock_sprites, True)
|
||||
#ograniczyć ruch agenta gdy jest kolizja ze skałami
|
||||
|
||||
def events(self):
|
||||
for event in pygame.event.get():
|
||||
@ -42,13 +48,14 @@ class Game:
|
||||
pygame.quit()
|
||||
|
||||
def map(self): # tworzenie mapy
|
||||
self.SCREEN.fill(BLACK)
|
||||
self.all_sprites.draw(self.SCREEN)
|
||||
self.clock.tick(FRAMERATE)
|
||||
for x in range(0, WIDTH, TILE_SIZE):
|
||||
for y in range(0, HEIGHT, TILE_SIZE):
|
||||
self.SCREEN.blit(self.BACKGROUND,(x,y))
|
||||
self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
||||
pygame.draw.rect(self.SCREEN, WHITE, self.rect, 1)
|
||||
pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1)
|
||||
self.all_sprites.draw(self.SCREEN)
|
||||
self.rock_sprites.draw(self.SCREEN)
|
||||
pygame.display.update()
|
||||
|
||||
def main(self):
|
||||
|
26
map_add_ons.py
Normal file
@ -0,0 +1,26 @@
|
||||
import pygame
|
||||
from config import *
|
||||
|
||||
class Rocks(pygame.sprite.Sprite):
|
||||
|
||||
def __init__(self,game,x,y):
|
||||
self.game = game
|
||||
self.groups = self.game.rock_sprites
|
||||
pygame.sprite.Sprite.__init__(self, self.groups)
|
||||
|
||||
self.x = x * TILE_SIZE
|
||||
self.y = y * TILE_SIZE
|
||||
self.width = TILE_SIZE
|
||||
self.height = TILE_SIZE
|
||||
|
||||
self.ROCKS_PNG = pygame.image.load("./zdjecia/rock.png")
|
||||
self.ROCKS = pygame.transform.scale(self.ROCKS_PNG,(64,64))
|
||||
|
||||
self.image = pygame.Surface([self.width, self.height])
|
||||
self.image.blit(self.ROCKS,(0,0))
|
||||
self.image.set_colorkey((0, 0, 0))
|
||||
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.x = self.x
|
||||
self.rect.y = self.y
|
||||
|
Before Width: | Height: | Size: 88 KiB |
BIN
zdjecia/gandalf.png
Normal file
After Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 90 KiB |
BIN
zdjecia/ork-piechota.png
Normal file
After Width: | Height: | Size: 212 KiB |
Before Width: | Height: | Size: 183 KiB |
BIN
zdjecia/ork-piechota2.png
Normal file
After Width: | Height: | Size: 216 KiB |
Before Width: | Height: | Size: 97 KiB |
BIN
zdjecia/ork_lucznik.png
Normal file
After Width: | Height: | Size: 227 KiB |
BIN
zdjecia/podloze.jpg
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
zdjecia/rock.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
zdjecia/rock3.png
Normal file
After Width: | Height: | Size: 69 KiB |
Before Width: | Height: | Size: 66 KiB |
BIN
zdjecia/sauron.png
Normal file
After Width: | Height: | Size: 135 KiB |