agent poruszający się po mapie + zmiany w main
This commit is contained in:
parent
46524da263
commit
af8529865d
BIN
__pycache__/agent.cpython-310.pyc
Normal file
BIN
__pycache__/agent.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-310.pyc
Normal file
BIN
__pycache__/config.cpython-310.pyc
Normal file
Binary file not shown.
50
agent.py
Normal file
50
agent.py
Normal file
@ -0,0 +1,50 @@
|
||||
import pygame
|
||||
from config import *
|
||||
|
||||
class Agent(pygame.sprite.Sprite):
|
||||
|
||||
|
||||
def __init__(self, game, x, y):
|
||||
self.game = game
|
||||
self.groups = self.game.all_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.x_change = 0
|
||||
self.y_change = 0
|
||||
|
||||
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf.jpg")
|
||||
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.rect = self.image.get_rect()
|
||||
self.rect.x = self.x
|
||||
self.rect.y = self.y
|
||||
|
||||
self.health = 100
|
||||
|
||||
def update(self):
|
||||
self.movement()
|
||||
|
||||
self.rect.x += self.x_change
|
||||
self.rect.y += self.y_change
|
||||
|
||||
self.x_change = 0
|
||||
self.y_change = 0
|
||||
|
||||
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
|
@ -1,5 +1,6 @@
|
||||
FRAMERATE = 30
|
||||
WIDTH, HEIGHT = 1100, 1100
|
||||
TILE_SIZE = 100
|
||||
WIDTH, HEIGHT = 800, 800
|
||||
TILE_SIZE = 64
|
||||
BLACK = ((0,0,0))
|
||||
WHITE = ((255,255,255))
|
||||
WHITE = ((255,255,255))
|
||||
PLAYER_SPEED = 3
|
76
main.py
76
main.py
@ -1,46 +1,62 @@
|
||||
import pygame
|
||||
import random
|
||||
from config import *
|
||||
from agent import *
|
||||
|
||||
pygame.init()
|
||||
class Game:
|
||||
|
||||
ARCHER_ORK_IMG = pygame.image.load("./zdjecia/ork_lucznik.jpg")
|
||||
INFATRY_ORK_IMG = pygame.image.load("./zdjecia/ork-piechota.jpg")
|
||||
INFANTRY_ORK2_IMG = pygame.image.load("./zdjecia/ork-piechota2.jpg")
|
||||
SAURON_JPG = pygame.image.load("./zdjecia/sauron.jpg")
|
||||
AGENT_IMG = pygame.image.load("./zdjecia/gandalf.jpg")
|
||||
def __init__(self):
|
||||
pygame.init()
|
||||
self.SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
self.running = True
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
|
||||
ARCHER_ORK = pygame.transform.scale(ARCHER_ORK_IMG,(100,100))
|
||||
INFATRY_ORK = pygame.transform.scale(INFATRY_ORK_IMG,(100,100))
|
||||
INFANTRY_ORK2 = pygame.transform.scale(INFANTRY_ORK2_IMG,(100,100))
|
||||
SAURON = pygame.transform.scale(SAURON_JPG,(100,100))
|
||||
AGENT = pygame.transform.scale(AGENT_IMG,(100,100))
|
||||
# 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")
|
||||
|
||||
pygame.display.set_caption('Do_Nazwania')
|
||||
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
|
||||
def map():
|
||||
SCREEN.fill(BLACK)
|
||||
ORK_LIST = [ARCHER_ORK,INFANTRY_ORK2, INFATRY_ORK]
|
||||
for x in range(0, WIDTH, TILE_SIZE):
|
||||
|
||||
for y in range(0, HEIGHT, TILE_SIZE):
|
||||
rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
||||
pygame.draw.rect(SCREEN, WHITE, rect, 1)
|
||||
SCREEN.blit(AGENT, (500,1000))
|
||||
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))
|
||||
|
||||
def main():
|
||||
running = True
|
||||
clock = pygame.time.Clock()
|
||||
map()
|
||||
self.ORK_LIST = [self.ARCHER_ORK,self.INFANTRY_ORK2, self.INFATRY_ORK]
|
||||
|
||||
while running:
|
||||
clock.tick(FRAMERATE)
|
||||
pygame.display.set_caption('Do_Nazwania')
|
||||
|
||||
def new(self): # tworzy się nowa sesja grania
|
||||
self.all_sprites = pygame.sprite.LayeredUpdates()
|
||||
self.agent = Agent(self,1,1)
|
||||
|
||||
def update(self): # update postaci na mapie, związane z poruszaniem się
|
||||
self.all_sprites.update()
|
||||
|
||||
def events(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
pygame.quit()
|
||||
|
||||
pygame.display.flip()
|
||||
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.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
||||
pygame.draw.rect(self.SCREEN, WHITE, self.rect, 1)
|
||||
pygame.display.update()
|
||||
|
||||
main()
|
||||
def main(self):
|
||||
self.events()
|
||||
self.update()
|
||||
self.map()
|
||||
|
||||
g = Game()
|
||||
g.new()
|
||||
while g.running:
|
||||
g.main()
|
Loading…
Reference in New Issue
Block a user