This commit is contained in:
Weranda 2023-04-21 09:10:12 +02:00
commit bf66823c64
12 changed files with 95 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,11 +29,19 @@ class Agent(pygame.sprite.Sprite):
self.rect.y = self.y self.rect.y = self.y
self.level = 1 self.level = 1
self.health = 10000*self.level
self.current_health = 500
self.max_health = 1000
self.health_bar_length = 300
self.health_ratio = self.max_health/self.health_bar_length
def update(self): def update(self):
self.health_bar()
self.movement() self.movement()
self.collide_mob() self.collide_mob()
self.disp_level()
self.rect.x += self.x_change self.rect.x += self.x_change
self.collide_blocks('x') self.collide_blocks('x')
@ -46,13 +54,13 @@ class Agent(pygame.sprite.Sprite):
def movement(self): def movement(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.rect.x > 0: if keys[pygame.K_LEFT] and self.rect.x > 0:
self.x_change -= TILE_SIZE/2 self.x_change -= TILE_SIZE
if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64: if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64:
self.x_change += TILE_SIZE/2 self.x_change += TILE_SIZE
if keys[pygame.K_UP] and self.rect.y > 0: if keys[pygame.K_UP] and self.rect.y > 0:
self.y_change -= TILE_SIZE/2 self.y_change -= TILE_SIZE
if keys[pygame.K_DOWN] and self.rect.y < 832 - 64: if keys[pygame.K_DOWN] and self.rect.y < 768 - 64:
self.y_change += TILE_SIZE/2 self.y_change += TILE_SIZE
def collide_blocks(self, direction): def collide_blocks(self, direction):
if direction == "x": if direction == "x":
@ -77,38 +85,47 @@ class Agent(pygame.sprite.Sprite):
hits_infantry_ork = pygame.sprite.spritecollide(self, self.game.infantry_orks, False) hits_infantry_ork = pygame.sprite.spritecollide(self, self.game.infantry_orks, False)
hits_infantry_ork2 = pygame.sprite.spritecollide(self, self.game.infantry_orks2, False) hits_infantry_ork2 = pygame.sprite.spritecollide(self, self.game.infantry_orks2, False)
hits_sauron = pygame.sprite.spritecollide(self, self.game.sauronL, False) hits_sauron = pygame.sprite.spritecollide(self, self.game.sauronL, False)
#hits_unknown_mob = pygame.sprite.spritecollide(self, self.game.unknown_mobs, False) #unknown mob
#if hits_unknown_mob:
# self.game.unknown_mob.kill()
# self.game.archer_orks = pygame.sprite.LayeredUpdates()
# self.game.archer_ork = Archer_ork(self,3,2)
if hits_archer_ork: if hits_archer_ork:
if self.game.archer_ork.level > self.level or self.game.archer_ork.damage > self.health: if self.game.archer_ork.level > self.level or self.game.archer_ork.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.archer_ork.kill() self.game.archer_ork.kill()
self.health=self.health-self.game.archer_ork.damage self.get_damage(self.game.archer_ork.damage)
self.level+=self.level self.level+=self.level
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_infantry_ork: if hits_infantry_ork:
if self.game.infantry_ork.level > self.level or self.game.infantry_ork.damage > self.health: if self.game.infantry_ork.level > self.level or self.game.infantry_ork.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.infantry_ork.kill() self.game.infantry_ork.kill()
self.health=self.health-self.game.infantry_ork.damage self.get_damage(self.game.infantry_ork.damage)
self.level+=self.level self.level+=self.level
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_infantry_ork2: if hits_infantry_ork2:
if self.game.infantry_ork2.level > self.level or self.game.infantry_ork2.damage > self.health: if self.game.infantry_ork2.level > self.level or self.game.infantry_ork2.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
self.game.infantry_ork2.kill() self.game.infantry_ork2.kill()
self.health=self.health-self.game.infantry_ork2.damage self.get_damage(self.game.infantry_ork2.damage)
self.level+=self.level self.level+=self.level
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
if hits_sauron: if hits_sauron:
if self.game.sauron.level > self.level or self.game.sauron.damage > self.health: if self.game.sauron.level > self.level or self.game.sauron.damage > self.current_health:
self.kill() self.kill()
self.game.new() self.game.new()
else: else:
@ -118,6 +135,33 @@ class Agent(pygame.sprite.Sprite):
#zmniejszenie życia o damage moba #zmniejszenie życia o damage moba
#level up #level up
def get_damage(self,amount):
if self.current_health > 0:
self.current_health -= amount
if self.current_health <= 0:
self.current_health = 0
#zmienic potem na smierc oraz później trzeba będzie tutaj ująć wszystkie statystyki
#i ze statystyk obliczyć ile dmg dostanie agent
def get_health(self, amount):
if self.current_health < self.max_health:
self.current_health += amount
if self.current_health >= self.max_health:
self.current_health = self.max_health
def health_bar(self):
pygame.draw.rect(self.game.SCREEN, (255,0,0), (10,780,self.health_bar_length,25))
pygame.draw.rect(self.game.SCREEN, (0,255,0), (10,780,self.current_health/self.health_ratio,25))
pygame.draw.rect(self.game.SCREEN, (255,255,255), (10,780,self.health_bar_length, 25),2)
def disp_level(self):
font = pygame.font.SysFont(None, 40)
lvlDisplay = font.render(str(self.level), 1, WHITE)
pygame.draw.rect(self.game.SCREEN, BLACK, (370, 780, 40, 40))
self.game.SCREEN.blit(lvlDisplay, (370,780))
# brakuje levelowania postaci gdy zabije moba, jest zrobione tylko, że jeśli za wysoki poziom, lub brak życia to ginie i od nowa zaczyna # brakuje levelowania postaci gdy zabije moba, jest zrobione tylko, że jeśli za wysoki poziom, lub brak życia to ginie i od nowa zaczyna
# brakuje dodania miejsca w którym agent się leczy # brakuje dodania miejsca w którym agent się leczy

10
main.py
View File

@ -6,6 +6,7 @@ from archer_ork import *
from infantry_ork import * from infantry_ork import *
from infantry_ork2 import * from infantry_ork2 import *
from sauron import * from sauron import *
#from unknown_mob import * #unknown mob
class Game: class Game:
@ -18,6 +19,9 @@ class Game:
self.BACKGROUND_IMG= pygame.image.load("./zdjecia/podloze.jpg") self.BACKGROUND_IMG= pygame.image.load("./zdjecia/podloze.jpg")
self.BACKGROUND = pygame.transform.scale(self.BACKGROUND_IMG,(64,64)) self.BACKGROUND = pygame.transform.scale(self.BACKGROUND_IMG,(64,64))
self.LVL_ICON_PNG = pygame.image.load("./zdjecia/lvl_icon.png")
self.LVL_ICON = pygame.transform.scale(self.LVL_ICON_PNG,(24,24))
#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('Gra-SI') pygame.display.set_caption('Gra-SI')
@ -29,14 +33,17 @@ class Game:
self.infantry_orks = pygame.sprite.LayeredUpdates() self.infantry_orks = pygame.sprite.LayeredUpdates()
self.infantry_orks2 = pygame.sprite.LayeredUpdates() self.infantry_orks2 = pygame.sprite.LayeredUpdates()
self.sauronL = pygame.sprite.LayeredUpdates() self.sauronL = pygame.sprite.LayeredUpdates()
#self.unknown_mobs = pygame.sprite.LayeredUpdates() #unknown mob
self.agent = Agent(self,1,1) self.agent = Agent(self,1,1)
self.archer_ork = Archer_ork(self,10,10) self.archer_ork = Archer_ork(self,10,10)
self.infantry_ork = Infantry_ork(self,10,4) self.infantry_ork = Infantry_ork(self,10,4)
self.infantry_ork2 = Infantry_ork2(self,6,3) self.infantry_ork2 = Infantry_ork2(self,6,3)
self.sauron = Sauron(self, 1, 10) self.sauron = Sauron(self, 1, 10)
#self.unknown_mob = Unknown_mob(self,8,8) #unknown mob
for y in range(5): for y in range(5):
self.rock = Rocks(self,3,y) self.rock = Rocks(self,3,y)
def update(self): def update(self):
self.all_sprites.update() self.all_sprites.update()
@ -50,12 +57,13 @@ class Game:
def map(self): # tworzenie mapy def map(self): # tworzenie mapy
self.clock.tick(FRAMERATE) self.clock.tick(FRAMERATE)
for x in range(0, WIDTH, TILE_SIZE): for x in range(0, WIDTH, TILE_SIZE):
for y in range(0, HEIGHT, TILE_SIZE): for y in range(0, 768, TILE_SIZE):
self.SCREEN.blit(self.BACKGROUND,(x,y)) self.SCREEN.blit(self.BACKGROUND,(x,y))
self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE) self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1) pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1)
self.all_sprites.draw(self.SCREEN) self.all_sprites.draw(self.SCREEN)
self.rock_sprites.draw(self.SCREEN) self.rock_sprites.draw(self.SCREEN)
self.SCREEN.blit(self.LVL_ICON, (340 ,780))
pygame.display.update() pygame.display.update()
def main(self): def main(self):

29
unknown_mob.py Normal file
View File

@ -0,0 +1,29 @@
import pygame
from config import *
class Unknown_mob(pygame.sprite.Sprite):
def __init__(self, game, x, y):
self.game = game
self.groups = self.game.all_sprites, self.game.unknown_mobs
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.UNKNOWN_MOB_IMG = pygame.image.load("./zdjecia/dragon.jpg")
self.UKNOWN_MOB = pygame.transform.scale(self.UNKNOWN_MOB_IMG,(64,64))
self.image = pygame.Surface([self.width, self.height])
self.image.blit(self.UKNOWN_MOB, (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
self.level = 1
self.damage = 50*self.level

BIN
zdjecia/dragon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
zdjecia/lvl_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB