Compare commits

...

20 commits

Author SHA1 Message Date
569b3394a0 Merge pull request 'Development' (#8) from InfoProjekt/game:Development into main
Reviewed-on: #8
2024-03-07 15:35:48 +00:00
9396218a11 Merge pull request 'main' (#72) from Spafi/game:main into Development
Reviewed-on: InfoProjekt/game#72
2024-03-07 14:27:03 +00:00
321dac7cca wrong location
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-07 14:26:57 +00:00
abfa24ced8 wrong location
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-07 14:26:52 +00:00
11c7a9037b wrong location
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-07 14:26:45 +00:00
9c36e8d570 wrong location
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-07 14:26:36 +00:00
SpagettiFisch
a68bba70bb image files changed
new mob sprites
relocated all image files
disabled collision between player and npcs and mobs

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-07 14:57:18 +01:00
SpagettiFisch
b7fb7e1f1e Merge branch 'main' of https://git.spafi.eu/Lyzzy/game
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-07 13:56:24 +01:00
SpagettiFisch
5010609378 relocated image files
changed room generation

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-07 13:55:01 +01:00
1d03d60ac2 Merge pull request 'new river sprite file added' (#67) from Spafi/game:main into Development
Reviewed-on: InfoProjekt/game#67
2024-03-07 08:51:52 +00:00
SpagettiFisch
c3c44bbc71 new river sprite file added
new idea lol

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-07 09:50:10 +01:00
a41ee41fba Merge pull request 'main' (#66) from jaffa/game:main into Development
Reviewed-on: InfoProjekt/game#66
2024-03-07 08:24:16 +00:00
47c93f61dc Upload files to "art/sprite files" 2024-03-07 08:18:47 +00:00
1fd852e31e Merge pull request 'Development' (#1) from InfoProjekt/game:Development into main
Reviewed-on: jaffa/game#1
2024-03-07 08:13:31 +00:00
f21d980352 Merge pull request 'doubled image size' (#65) from Spafi/game:main into Development
Reviewed-on: InfoProjekt/game#65
2024-03-07 06:51:08 +00:00
SpagettiFisch
1b6ccb17b0 Merge branch 'Development' of https://git.spafi.eu/InfoProjekt/game 2024-03-07 07:49:49 +01:00
SpagettiFisch
6034a8382f changed image size
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-07 07:49:16 +01:00
SpagettiFisch
746982641a Merge https://git.spafi.eu/InfoProjekt/game 2024-03-07 07:46:26 +01:00
b3c7d87926 Merge pull request 'Added Label class' (#64) from Lyzzy/game:main into Development
Reviewed-on: InfoProjekt/game#64
2024-03-07 06:45:57 +00:00
6fce7e0fd2 Merge pull request 'Development' (#57) from Development into main
Reviewed-on: InfoProjekt/game#57
2024-03-03 12:28:45 +00:00
42 changed files with 462 additions and 454 deletions

1
.idea/ideas.txt generated
View file

@ -38,6 +38,7 @@ Story:
Henker Henker
armer Bauer armer Bauer
"Hexe" "Hexe"
Patrice, fragt nach Lightning Anschluss -> Lightning Spell freigeschaltet
Ziel(e) Ziel(e)
-> Zurückkommen -> Zurückkommen

View file

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

View file

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View file

Before

Width:  |  Height:  |  Size: 68 B

After

Width:  |  Height:  |  Size: 68 B

View file

Before

Width:  |  Height:  |  Size: 581 B

After

Width:  |  Height:  |  Size: 581 B

View file

Before

Width:  |  Height:  |  Size: 635 B

After

Width:  |  Height:  |  Size: 635 B

View file

Before

Width:  |  Height:  |  Size: 329 B

After

Width:  |  Height:  |  Size: 329 B

View file

Before

Width:  |  Height:  |  Size: 644 B

After

Width:  |  Height:  |  Size: 644 B

View file

Before

Width:  |  Height:  |  Size: 433 B

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

View file

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View file

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 450 B

View file

Before

Width:  |  Height:  |  Size: 433 B

After

Width:  |  Height:  |  Size: 433 B

View file

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 462 B

View file

Before

Width:  |  Height:  |  Size: 438 B

After

Width:  |  Height:  |  Size: 438 B

View file

Before

Width:  |  Height:  |  Size: 441 B

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

View file

Before

Width:  |  Height:  |  Size: 674 B

After

Width:  |  Height:  |  Size: 674 B

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
art/images/people/rat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

View file

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View file

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

View file

Before

Width:  |  Height:  |  Size: 495 B

After

Width:  |  Height:  |  Size: 495 B

View file

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

View file

@ -52,7 +52,7 @@ class Button():
self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height) self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.buttonSurf = self.font.render(buttonText, True, (0,0,0)) self.buttonSurf = self.font.render(buttonText, True, '#baab80')
def update(self, screen): def update(self, screen):
mousePos = pygame.mouse.get_pos() mousePos = pygame.mouse.get_pos()
@ -76,7 +76,7 @@ class Button():
screen.blit(self.box, self.buttonRect) screen.blit(self.box, self.buttonRect)
class Label(): class Label():
def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color = (0,0,0), sprite = 'label.png') -> None: def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color = '#1e90ff', sprite = 'label.png') -> None:
self.x = x self.x = x
self.y = y self.y = y
self.width = width self.width = width
@ -285,5 +285,5 @@ class Obstacle(GameObjects):
if not self.hidden: if not self.hidden:
screen.blit(self.background, self.rect) screen.blit(self.background, self.rect)
else: else:
pygame.draw.rect(screen, (0,0,0), self.rect, 2) pygame.draw.rect(screen, '#e7f8e0', self.rect, 2)

18
main.py
View file

@ -14,6 +14,7 @@ def setUp(config):
else: else:
screen = pygame.display.set_mode(config["res"]) screen = pygame.display.set_mode(config["res"])
clock = pygame.time.Clock() clock = pygame.time.Clock()
pygame.display.set_caption('Between The Pages')
return screen, clock, True, True, "start.png", [] return screen, clock, True, True, "start.png", []
def readConfig(): def readConfig():
@ -30,30 +31,31 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list):
room_objects = [] room_objects = []
#room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] #room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)]
room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66))) room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66)))
room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)]
rooms = [ rooms = [
Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 0), Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j)
Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 1), for j in range(random.randint(5, 10))
Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 2), ]
] #rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j)
return rooms
return rooms
def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
main = [MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)] main = [MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)]
mobs = [Skeleton(i, random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))]+[Zombie(i, random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 100) for i in range(0,random.randint(2, 8))] mobs = [Skeleton(i, random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))]+[Zombie(i, random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 100) for i in range(0,random.randint(2, 8))]
weapons = [] weapons = []
others = [Fire('f1', 0, 200, 300)] others = [Fire('f1', 0, 200, 300)]
npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)] npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)]
objects = [main, mobs, npcs, weapons, others] objects = [main, mobs, npcs, weapons, others]
level = [] level = []
rooms = genRooms(WIDTH, HEIGHT, 'background/grass', objects) rooms = genRooms(WIDTH, HEIGHT, 'grass', objects)
level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms))
scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level)
freeze = False #Gameplay is freezed in certain situations freeze = False #Gameplay is freezed in certain situations
while running: while running:
screen.fill((0,0,0)) screen.fill('#000000')
events = pygame.event.get() events = pygame.event.get()
for event in events: for event in events:
if event.type == pygame.QUIT: if event.type == pygame.QUIT:

View file

@ -1,443 +1,448 @@
import pygame as pg import pygame as pg
from classes import * from classes import *
from main import * from main import *
vec = pg.math.Vector2 vec = pg.math.Vector2
fps = 60 fps = 60
pg.font.init() pg.font.init()
fonts = { fonts = {
'medieval': 'medieval.ttf', 'medieval': 'medieval.ttf',
'minecraft': 'Minecraft Evenings.otf', 'minecraft': 'Minecraft Evenings.otf',
'3dpixel': '3D-Pixel.ttf', '3dpixel': '3D-Pixel.ttf',
'8bit': '8bitlim.ttf', '8bit': '8bitlim.ttf',
'8bito': '8blimro.ttf', '8bito': '8blimro.ttf',
'arcade': 'ARCADECLASSIC.ttf', 'arcade': 'ARCADECLASSIC.ttf',
'modern_game': 'astron boy video.otf', 'modern_game': 'astron boy video.otf',
'modern': 'astron boy.otf', 'modern': 'astron boy.otf',
'wonder': 'Beyond Wonderland.ttf', 'wonder': 'Beyond Wonderland.ttf',
'curved': 'Digitag.ttf', 'curved': 'Digitag.ttf',
'simple': 'DisposableDroidBB.ttf', 'simple': 'DisposableDroidBB.ttf',
'rounded': 'dpcomic.ttf', 'rounded': 'dpcomic.ttf',
'playfull': 'Endalian Script.ttf', 'playfull': 'Endalian Script.ttf',
'blocky': 'FREAKSOFNATURE.ttf', 'blocky': 'FREAKSOFNATURE.ttf',
'catchy': 'Future TimeSplitters.otf', 'catchy': 'Future TimeSplitters.otf',
'simple_wide': 'Halo3.ttf', 'simple_wide': 'Halo3.ttf',
'simple_fat': 'INVASION2000.ttf', 'simple_fat': 'INVASION2000.ttf',
'very_gamy': 'ka1.ttf', 'very_gamy': 'ka1.ttf',
'simple_round': 'Karma Suture.otf', 'simple_round': 'Karma Suture.otf',
'mono': 'manaspc.ttf', 'mono': 'manaspc.ttf',
'damaged': 'Merchant Copy.ttf', 'damaged': 'Merchant Copy.ttf',
'big_natural': 'MorialCitadel.TTF', 'big_natural': 'MorialCitadel.TTF',
'spacy': 'nasalization-rg.otf', 'spacy': 'nasalization-rg.otf',
'sci-fi': 'neuropol.otf', 'sci-fi': 'neuropol.otf',
'hollow_big_edge': 'papercut.ttf', 'hollow_big_edge': 'papercut.ttf',
'space_shuttle': 'pdark.ttf', 'space_shuttle': 'pdark.ttf',
'thin': 'PixelFJVerdana12pt.ttf', 'thin': 'PixelFJVerdana12pt.ttf',
'random': 'Seattle Avenue.ttf', 'random': 'Seattle Avenue.ttf',
'pixel': 'yoster.ttf' 'pixel': 'yoster.ttf'
} }
class Objects(): class Objects():
def __init__(self, name, ms, sprite, x, y) -> None: def __init__(self, name, ms, sprite, x, y) -> None:
self.name = name self.name = name
self.speed = ms self.speed = ms
with open(f'art/images/{sprite}') as i: with open(f'art/images/{sprite}') as i:
self.sprite = pg.transform.scale2x(pg.image.load(i)) self.sprite = pg.transform.scale2x(pg.image.load(i))
self.x = x self.x = x
self.y = y self.y = y
self.hidden = False self.hidden = False
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
def draw(self, screen): def draw(self, screen):
if self.hidden: if self.hidden:
return return
self.rect.x, self.rect.y = self.x, self.y self.rect.x, self.rect.y = self.x, self.y
screen.blit(self.sprite, self.rect) screen.blit(self.sprite, self.rect)
pg.draw.rect(screen, (0,0,0), self.rect, 2) pg.draw.rect(screen, '#ef0120', self.rect, 2)
class NPC(Objects): class NPC(Objects):
def __init__(self, name, ms, sprite, convo_act, x, y) -> None: def __init__(self, name, ms, sprite, convo_act, x, y) -> None:
self.talking = False super().__init__(name, ms, sprite, x, y)
self.hidden = True self.talking = False
super().__init__(name, ms, sprite, x, y) self.hidden = False
self.conversation = Convo('Hello, you can shoot fireballs with f now.', convo_act, 'person') self.conversation = Convo('Hello, you can shoot fireballs with f now.', convo_act, 'person')
def talk(self, objects): def talk(self, objects):
self.talking = True self.talking = True
objects[0][0].talking = True objects[0][0].talking = True
self.conversation.hidden = False self.conversation.hidden = False
def draw(self, screen): def draw(self, screen):
super().draw(screen) super().draw(screen)
if self.talking == True: if self.talking:
self.conversation.draw(screen) self.conversation.draw(screen)
def update(self, keys, objects): def update(self, keys, objects):
if self.talking: if self.talking:
self.conversation.update(keys, objects) self.conversation.update(keys, objects)
class Convo(Label): class Convo(Label):
def __init__(self, text, convo_act, person, x = 140, y = 600, width = 1000, height = 100, font='simple', font_size = 20) -> None: def __init__(self, text, convo_act, person, x = 140, y = 600, width = 1000, height = 100, font='simple', font_size = 20) -> None:
super().__init__(x, y, width, height, text, font, font_size) super().__init__(x, y, width, height, text, font, font_size)
def update(self, keys, objects): def update(self, keys, objects):
if keys[pg.K_SPACE]: if keys[pg.K_SPACE]:
objects[0][0].book.addspell('fireball') objects[0][0].book.addspell('fireball')
self.talking = False self.talking = False
objects[0][0].talking = False objects[0][0].talking = False
self.hidden = True self.hidden = True
class Fighter(Objects): class Fighter(Objects):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None:
super().__init__(name, ms, sprite, x, y) super().__init__(name, ms, sprite, x, y)
self.health = health self.health = health
self.damage = damage self.damage = damage
self.level = level self.level = level
self.attack_speed = asp self.attack_speed = asp
self.attack_range = atr self.attack_range = atr
self.lastHurt = pg.time.get_ticks() self.lastHurt = pg.time.get_ticks()
self.lastAttack = pg.time.get_ticks() self.lastAttack = pg.time.get_ticks()
self.hurtCooldown = 0 self.hurtCooldown = 0
class MainCharacter(Fighter): class MainCharacter(Fighter):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
self.book = Book(0, 0, [], None, None) self.book = Book(0, 0, [], None, None)
self.talking = False self.talking = False
self.level = Level(1000, 38, 150, 40, f'will to live: {level}%', 'simple', 20) self.level = Level(1000, 38, 150, 40, f'will to live: {level}%', 'simple', 20, )
self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y= 50, hurtCooldown=self.hurtCooldown) self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y= 50, hurtCooldown=self.hurtCooldown)
self.speech = Speech(self.x+20, self.y-50, 150, 100, 'brr Im freezing') self.speech = Speech(self.x+20, self.y-50, 150, 100, 'brr Im freezing')
self.freezing = True self.freezing = True
def draw(self, screen): def draw(self, screen):
if self.hidden: if self.hidden:
return return
self.rect.x, self.rect.y = self.x, self.y self.rect.x, self.rect.y = self.x, self.y
screen.blit(self.sprite, self.rect) screen.blit(self.sprite, self.rect)
self.health.draw(screen) self.health.draw(screen)
self.level.draw(screen) self.level.draw(screen)
self.book.draw(screen) self.book.draw(screen)
pg.draw.rect(screen, (0,0,0), self.rect, 2) pg.draw.rect(screen, '#e900fa', self.rect, 2)
if self.speech.hidden == False: if self.speech.hidden == False:
self.speech.draw(screen, self.x+20, self.y-100) self.speech.draw(screen, self.x+20, self.y-100)
def hurt(self, damage, objects): def hurt(self, damage, objects):
if not self.talking: if not self.talking:
self.health.hurt(damage) self.health.hurt(damage)
def walk(self, keys, objects): def walk(self, keys, objects):
moveto = vec(0, 0) moveto = vec(0, 0)
if keys[pg.K_w] or keys[pg.K_UP]: if keys[pg.K_w] or keys[pg.K_UP]:
moveto += vec(0, -1) moveto += vec(0, -1)
if keys[pg.K_a] or keys[pg.K_LEFT]: if keys[pg.K_a] or keys[pg.K_LEFT]:
moveto += vec(-1, 0) moveto += vec(-1, 0)
if keys[pg.K_s] or keys[pg.K_DOWN]: if keys[pg.K_s] or keys[pg.K_DOWN]:
moveto += vec(0, 1) moveto += vec(0, 1)
if keys[pg.K_d] or keys[pg.K_RIGHT]: if keys[pg.K_d] or keys[pg.K_RIGHT]:
moveto += vec(1, 0) moveto += vec(1, 0)
if not moveto == vec(0, 0): if not moveto == vec(0, 0):
moveto.scale_to_length(self.speed) moveto.scale_to_length(self.speed)
self.x += moveto[0] / fps self.x += moveto[0] / fps
self.y += moveto[1] / fps self.y += moveto[1] / fps
touches = pg.sprite.spritecollideany(self, objects[1] + objects[2] + objects[3]) touches = pg.sprite.spritecollideany(self, objects[2] + objects[4])
if touches is not None and not isinstance(touches, Weapons): if touches is not None and not isinstance(touches, Weapons):
if isinstance(touches, Obstacle): if isinstance(touches, Obstacle):
if not touches.collision: if not touches.collision:
return return
if touches.type == 'wall': if touches.type == 'wall':
if touches.name == 'wall_l': if touches.name == 'wall_l':
self.x += (2 + (self.x - touches.rect.x)) self.x += (2 + (self.x - touches.rect.x))
elif touches.name == 'wall_r': elif touches.name == 'wall_r':
self.x -= (2 + self.rect.width - (touches.rect.x - self.x)) self.x -= (2 + self.rect.width - (touches.rect.x - self.x))
if touches.name == 'wall_t': if touches.name == 'wall_t':
self.y += (2 + (self.y - touches.rect.y)) self.y += (2 + (self.y - touches.rect.y))
elif touches.name == 'wall_b': elif touches.name == 'wall_b':
self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) self.y -= (2 + self.rect.height - (touches.rect.y - self.y))
return return
elif isinstance(touches, NPC):
if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x)) if keys[pg.K_SPACE]:
elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x)) touches.talk(objects)
#if self.y <= touches.y: pass return
#elif self.y > touches.y: pass else:
self.x -= moveto[0] * 2 / fps return
self.y -= moveto[1] * 2 / fps
if isinstance(touches, NPC): if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x))
touches.talk(objects) elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x))
""" #if self.y <= touches.y: pass
if self.x <= 32: #elif self.y > touches.y: pass
self.x = 33 self.x -= moveto[0] * 2 / fps
elif self.x >= objects[3][0].width - 32: self.y -= moveto[1] * 2 / fps
self.x = objects[3][0].width - 32 - self.rect.width + 1
if self.y <= 32: """
self.y = 33 if self.x <= 32:
elif self.y >= objects[3][0].height - 32: self.x = 33
self.y = objects[3][0].height - 32 - self.rect.height + 1 elif self.x >= objects[3][0].width - 32:
""" self.x = objects[3][0].width - 32 - self.rect.width + 1
if self.y <= 32:
def attack(self, obj, mouse): self.y = 33
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): elif self.y >= objects[3][0].height - 32:
moveto = mouse- vec(self.x, self.y) self.y = objects[3][0].height - 32 - self.rect.height + 1
if self.book.current_sp == 'fireball': """
weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
elif self.book.current_sp == 'windslash': def attack(self, obj, mouse):
weapon = Windslash('ws1', 100, self.x, self.y, moveto, 5) if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
else: moveto = mouse- vec(self.x, self.y)
return if self.book.current_sp == 'fireball':
obj[3].append(weapon) weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
self.lastAttack = pg.time.get_ticks() elif self.book.current_sp == 'windslash':
weapon = Windslash('ws1', 100, self.x, self.y, moveto, 5)
def update(self, keys, mouse, objects): else:
if not self.talking: return
self.walk(keys, objects) obj[3].append(weapon)
if keys[pg.K_f]: self.lastAttack = pg.time.get_ticks()
self.attack(objects, vec(mouse))
self.speech.update(self) def update(self, keys, mouse, objects):
if self.health.health <= 0: if not self.talking:
return False self.walk(keys, objects)
else: if keys[pg.K_f]:
return True self.attack(objects, vec(mouse))
self.speech.update(self)
class Hearts(): if self.health.health <= 0:
def __init__(self, health, sprite, x, y, hurtCooldown) -> None: return False
self.x = x else:
self.y = y return True
self.health = health
self.lastHurt = pg.time.get_ticks() class Hearts():
self.hurtCooldown = hurtCooldown def __init__(self, health, sprite, x, y, hurtCooldown) -> None:
self.hidden = False self.x = x
self.sprite=[] self.y = y
for parts in sprite: self.health = health
with open(f'art/images/main_attributes/{parts}') as i: self.lastHurt = pg.time.get_ticks()
self.sprite.append(pg.image.load(i)) self.hurtCooldown = hurtCooldown
self.rect = [] self.hidden = False
for each in self.sprite: self.sprite=[]
self.rect.append(pg.Rect(self.x, self.y, each.get_width(), each.get_height())) for parts in sprite:
with open(f'art/images/main_attributes/{parts}') as i:
def hurt(self,damage): self.sprite.append(pg.image.load(i))
if self.lastHurt + self.hurtCooldown < pg.time.get_ticks(): self.rect = []
self.health -= damage for each in self.sprite:
self.lastHurt = pg.time.get_ticks() self.rect.append(pg.Rect(self.x, self.y, each.get_width(), each.get_height()))
self.update()
def hurt(self,damage):
def draw(self, screen): if self.lastHurt + self.hurtCooldown < pg.time.get_ticks():
if self.hidden: self.health -= damage
return self.lastHurt = pg.time.get_ticks()
for i in range(0, 5): self.update()
self.rect[i].x, self.rect[i].y = self.x + i * 20, self.y
screen.blit(self.sprite[i], self.rect[i]) def draw(self, screen):
if self.hidden:
def update(self): return
sprite = [] for i in range(0, 5):
for i in range(0, 5): self.rect[i].x, self.rect[i].y = self.x + i * 20, self.y
if self.health >= 4 + 4 * i: screen.blit(self.sprite[i], self.rect[i])
sprite.append('fullheart.png')
elif self.health == 3 + 4 * i: def update(self):
sprite.append('dreiviertelheart.png') sprite = []
elif self.health >= 2 + 4 * i: for i in range(0, 5):
sprite.append('halfheart.png') if self.health >= 4 + 4 * i:
elif self.health >= 1 + 4 * i: sprite.append('fullheart.png')
sprite.append('viertelheart.png') elif self.health == 3 + 4 * i:
elif self.health <= 4 * i: sprite.append('dreiviertelheart.png')
sprite.append('noheart.png') elif self.health >= 2 + 4 * i:
self.sprite = [] sprite.append('halfheart.png')
for parts in sprite: elif self.health >= 1 + 4 * i:
with open(f'art/images/main_attributes/{parts}') as i: sprite.append('viertelheart.png')
self.sprite.append(pg.image.load(i)) elif self.health <= 4 * i:
sprite.append('noheart.png')
self.sprite = []
class Level(Label): for parts in sprite:
def __init__(self, x, y, width, height, text, font, font_size) -> None: with open(f'art/images/main_attributes/{parts}') as i:
super().__init__(x, y, width, height, text, font, font_size) self.sprite.append(pg.image.load(i))
class Speech(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color=(0,0,0), sprite='speech.png') -> None: class Level(Label):
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite) def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color='#1e90ff', sprite='label.png') -> None:
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
def draw(self, screen, x, y):
if self.hidden: class Speech(Label):
return def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='speech.png') -> None:
self.x = x super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
self.y = y
super().draw(screen) def draw(self, screen, x, y):
if self.hidden:
def update(self, main): return
if not self.hidden: self.x = x
if not main.freezing: self.y = y
self.hidden = True super().draw(screen)
class Book(): def update(self, main):
def __init__(self, x, y, spells, current_spell, current_shield) -> None: if not self.hidden:
with open(f'art/images/main_attributes/book.png') as i: if not main.freezing:
self.sprite = pg.image.load(i) self.hidden = True
self.sprite = pg.transform.scale(self.sprite, (1280, 720))
self.x = x class Book():
self.y = y def __init__(self, x, y, spells, current_spell, current_shield) -> None:
self.hidden = True with open(f'art/images/main_attributes/book.png') as i:
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) self.sprite = pg.image.load(i)
self.sp_list = spells self.sprite = pg.transform.scale(self.sprite, (1280, 720))
self.current_sp = current_spell self.x = x
self.labels = [Label(100, 100, 500, 50, "Dear User, ", font_color=(0,0,0), sprite='empty.png'), self.y = y
Label(100, 150, 500, 50, "this book will help you to survive.", font_color=(0,0,0), sprite='empty.png'), self.hidden = True
Label(100, 200, 500, 50, "Click on a picture to choose your spell.", font_color=(0,0,0), sprite='empty.png'), self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
Label(100, 250, 500, 50, "Talk to fairies to unlock new spells!", font_color=(0,0,0), sprite='empty.png')] self.sp_list = spells
self.buttons=[] self.current_sp = current_spell
self.buttons_height = 400 self.labels = [Label(100, 100, 500, 50, "Dear User, ", font_color='#000000', sprite='empty.png'),
Label(100, 150, 500, 50, "this book will help you to survive.", font_color='#000000', sprite='empty.png'),
def draw(self, screen): Label(100, 200, 500, 50, "Click on a picture to choose your spell.", font_color='#000000', sprite='empty.png'),
if self.hidden: Label(100, 250, 500, 50, "Talk to fairies to unlock new spells!", font_color='#000000', sprite='empty.png')]
return self.buttons=[]
self.rect.x, self.rect.y = self.x, self.y self.buttons_height = 400
screen.blit(self.sprite, self.rect)
for label in self.labels: def draw(self, screen):
label.draw(screen) if self.hidden:
for button in self.buttons: return
button.update(screen) self.rect.x, self.rect.y = self.x, self.y
screen.blit(self.sprite, self.rect)
def addspell(self, spell): for label in self.labels:
if spell not in self.sp_list: label.draw(screen)
self.sp_list.append(spell) for button in self.buttons:
self.current_sp = spell button.update(screen)
self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}_icon.png', 'medieval', 23, attributes=[spell], onclickFunction=self.update_spell))
self.buttons_height += 100 def addspell(self, spell):
if spell not in self.sp_list:
def update_spell(self, spell): self.sp_list.append(spell)
self.current_sp = spell self.current_sp = spell
self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}_icon.png', 'medieval', 23, attributes=[spell], onclickFunction=self.update_spell))
def update(self): self.buttons_height += 100
pass
class Mobs(Fighter): def update_spell(self, spell):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None: self.current_sp = spell
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
self.drops = drops * (self.level / 2) def update(self):
pass
def chase(self, obj): class Mobs(Fighter):
x = obj[0][0].x def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None:
y = obj[0][0].y super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
moveto = vec(x, y) - vec(self.x, self.y) self.drops = drops * (self.level / 2)
if not (moveto).length() <= self.attack_range:
moveto.scale_to_length(self.speed) def chase(self, obj):
self.x += moveto[0] / fps x = obj[0][0].x
self.y += moveto[1] / fps y = obj[0][0].y
else: moveto = vec(x, y) - vec(self.x, self.y)
self.attack(moveto, obj) if not (moveto).length() <= self.attack_range:
moveto.scale_to_length(self.speed)
self.x += moveto[0] / fps
def hurt(self, damage, objects): self.y += moveto[1] / fps
self.health -= damage else:
if self.health <= 0: self.attack(moveto, obj)
self.hidden = True
objects[1].remove(self)
def hurt(self, damage, objects):
self.health -= damage
def update(self, obj): if self.health <= 0:
self.chase(obj) self.hidden = True
objects[1].remove(self)
class Skeleton(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite = 'people/skeleton.png', drops=0) -> None: def update(self, obj):
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops) self.chase(obj)
def attack(self, moveto, obj):
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): class Skeleton(Mobs):
obj[3].append(Arrow("arrow", 200, self.x, self.y, moveto, self.damage)) def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite = 'people/skeleton.png', drops=0) -> None:
self.lastAttack = pg.time.get_ticks() super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj):
class Zombie(Mobs): if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/zombie.png', drops=0) -> None: obj[3].append(Arrow("arrow", 200, self.x, self.y, moveto, self.damage))
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops) self.lastAttack = pg.time.get_ticks()
def attack(self, moveto, obj): class Zombie(Mobs):
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/zombie.png', drops=0) -> None:
obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage)) super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
self.lastAttack = pg.time.get_ticks()
class Weapons(Objects): def attack(self, moveto, obj):
def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None: if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
super().__init__(name, ms, sprite, x, y) obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage))
self.moveto = moveto self.lastAttack = pg.time.get_ticks()
self.damage = damage
self.life_ticks= life_ticks class Weapons(Objects):
self.spawn_tick = pg.time.get_ticks() def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None:
pos = vec(1,0) super().__init__(name, ms, sprite, x, y)
angle = pos.angle_to(moveto) self.moveto = moveto
with open(f'art/images/{sprite}') as i: self.damage = damage
self.sprite =pg.transform.scale2x(pg.transform.rotate(pg.image.load(i), -angle)) self.life_ticks= life_ticks
self.spawn_tick = pg.time.get_ticks()
def die(self, objects, kills): pos = vec(1,0)
touches = pg.sprite.spritecollideany(self, objects[0] + objects[1]) angle = pos.angle_to(moveto)
if touches is not None and isinstance(touches, kills):
touches.hurt(self.damage, objects) self.sprite = pg.transform.rotate(self.sprite, -angle)
self.hidden = True
objects[3].remove(self) def die(self, objects, kills):
touches = pg.sprite.spritecollideany(self, objects[0] + objects[1])
def move(self, objects): if touches is not None and isinstance(touches, kills):
self.moveto.scale_to_length(self.speed) touches.hurt(self.damage, objects)
self.x += self.moveto[0] / fps self.hidden = True
self.y += self.moveto[1] / fps objects[3].remove(self)
if pg.time.get_ticks() - self.spawn_tick > self.life_ticks:
self.hidden = True def move(self, objects):
objects[3].remove(self) self.moveto.scale_to_length(self.speed)
self.x += self.moveto[0] / fps
class Spells(Weapons): self.y += self.moveto[1] / fps
def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None: if pg.time.get_ticks() - self.spawn_tick > self.life_ticks:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) self.hidden = True
objects[3].remove(self)
class Fireball(Spells):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/fireball.png', life_ticks=5000) -> None: class Spells(Weapons):
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
def update(self, objects):
self.move(objects) class Fireball(Spells):
self.die(objects, Mobs) def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/fireball.png', life_ticks=5000) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
class Windslash(Spells):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=700) -> None: def update(self, objects):
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) self.move(objects)
self.die(objects, Mobs)
def update(self, objects):
self.move(objects) class Windslash(Spells):
self.die(objects, Mobs) def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=700) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
def move(self, objects):
super().move(objects) def update(self, objects):
self.moveto = self.moveto.rotate(5) self.move(objects)
self.die(objects, Mobs)
class Arrow(Weapons): def move(self, objects):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/arrow.png', life_ticks=5000) -> None: super().move(objects)
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) self.moveto = self.moveto.rotate(5)
def update(self, objects):
self.move(objects) class Arrow(Weapons):
self.die(objects, MainCharacter) def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/arrow.png', life_ticks=5000) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
class Punch(Weapons): def update(self, objects):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/empty.png', life_ticks=100) -> None: self.move(objects)
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) self.die(objects, MainCharacter)
def update(self, objects):
self.move(objects) class Punch(Weapons):
self.die(objects, MainCharacter) def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/empty.png', life_ticks=100) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
class Fire(Objects):
def __init__(self, name, ms, x, y, sprite='background/fireplace.png') -> None: def update(self, objects):
super().__init__(name, ms, sprite, x, y) self.move(objects)
self.die(objects, MainCharacter)
def warming(self, objects):
touches = pg.sprite.spritecollideany(self, objects[0]) class Fire(Objects):
if touches is not None and isinstance(touches, MainCharacter): def __init__(self, name, ms, x, y, sprite='background/fireplace.png') -> None:
touches.freezing = False super().__init__(name, ms, sprite, x, y)
def update(self, objects): def warming(self, objects):
self.warming(objects) touches = pg.sprite.spritecollideany(self, objects[0])
if touches is not None and isinstance(touches, MainCharacter):
touches.freezing = False
def update(self, objects):
self.warming(objects)