Development #2

Merged
jaffa merged 114 commits from InfoProjekt/game:Development into Development 2024-03-11 00:39:31 +01:00
6 changed files with 84 additions and 36 deletions
Showing only changes of commit 73508253c4 - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 B

View file

@ -85,6 +85,7 @@ class Label():
self.font_color = font_color self.font_color = font_color
self.text = text self.text = text
self.hidden = False self.hidden = False
self.sprite = sprite
with open(f'art/images/box/{sprite}', 'r') as tb: with open(f'art/images/box/{sprite}', 'r') as tb:
self.box = pygame.image.load(tb) self.box = pygame.image.load(tb)
self.box = pygame.transform.scale(self.box, (width, height)) self.box = pygame.transform.scale(self.box, (width, height))
@ -93,6 +94,9 @@ class Label():
def draw(self, screen): def draw(self, screen):
if self.hidden: if self.hidden:
return return
with open(f'art/images/box/{self.sprite}', 'r') as tb:
self.box = pygame.image.load(tb)
self.box = pygame.transform.scale(self.box, (self.width,self.height))
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height) self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.labelSurf = self.font.render(self.text, True, self.font_color) self.labelSurf = self.font.render(self.text, True, self.font_color)
self.box.blit(self.labelSurf, [ self.box.blit(self.labelSurf, [

View file

@ -42,7 +42,7 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list):
def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
main = [herbert] main = [herbert]
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('skeleton', 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, 5))]+[Zombie('zombie', random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 25) for i in range(0,random.randint(2, 5))]
weapons = [] weapons = []
others = [] others = []
npcs = [] npcs = []
@ -115,7 +115,6 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
mobs = [] mobs = []
weapons = [] weapons = []
others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500),
Obstacle('portal', 'interactable', 'art/images/background/portal.png', False, 700, 300),
Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)]
npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)]
objects = [main, mobs, npcs, weapons, others] objects = [main, mobs, npcs, weapons, others]
@ -170,7 +169,6 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
npc.update(pygame.key.get_pressed(), objects) npc.update(pygame.key.get_pressed(), objects)
npc.draw(screen) npc.draw(screen)
objects[0][0].book.addspell('windslash')
room.update(objects) room.update(objects)
else: else:
@ -187,7 +185,7 @@ def house(screen, clock, running, background, isblack, WIDTH, HEIGHT):
mobs = [] mobs = []
weapons = [] weapons = []
others = [] others = []
npcs = [NPC('oldman', 100, 'people/reddy.png', 0, 200, 200)] npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)]
objects = [main, mobs, npcs, weapons, others] objects = [main, mobs, npcs, weapons, others]
room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0)
freeze = False #Gameplay is freezed in certain situations freeze = False #Gameplay is freezed in certain situations

View file

@ -1,6 +1,7 @@
import pygame as pg import pygame as pg
from classes import * from classes import *
from main import * from main import *
import random
vec = pg.math.Vector2 vec = pg.math.Vector2
fps = 60 fps = 60
@ -74,7 +75,10 @@ class NPC(Objects):
if self.talking: if self.talking:
self.conversation.draw(screen) self.conversation.draw(screen)
def update(self, keys, objects): def update(self, keys, objects):
if self.name == 'oldlady':
if self.conversation.convo_scene==0 and 'rat' in objects[0][0].killed and objects[1]==[]:
self.conversation.convo_scene=1
if self.lastUpdate + 200 < pg.time.get_ticks(): if self.lastUpdate + 200 < pg.time.get_ticks():
if self.talking: if self.talking:
self.conversation.update(keys, objects) self.conversation.update(keys, objects)
@ -93,28 +97,41 @@ class Convo(Label):
self.npc = npc self.npc = npc
self.convo_scene = convo_scene self.convo_scene = convo_scene
self.convos = [ self.convos = [
['oldlady', 0, ['Hello', 'How are you?']], ['oldlady', 0, ['There are so many rats here.', 'I wish someone would to something against that.','An experienced fighter could kill them.', 'For them it only takes a mouseclick.']],
['oldman', 0, ['Please help', 'there are so many bad people']] ['oldlady', 1, ['Oh, did you kill all the rats?', 'You must be the chosen one!', 'It would be nice if you would go and talk to the village elder.']],
['elder', 0, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']],
['elder', 1, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']]
] ]
def draw(self, screen): def draw(self, screen):
self.text = self.findConversation()[self.convo_act] self.text = self.findConversation()[2][self.convo_act]
super().draw(screen) super().draw(screen)
def findConversation(self): def findConversation(self):
for convo in self.convos: for convo in self.convos:
if convo[0] == self.npc.name and convo[1] == self.convo_scene: if convo[0] == self.npc.name and convo[1] == self.convo_scene:
return convo[2] return convo
return ['ERROR'] return ['ERROR']
def update(self, keys, objects): def update(self, keys, objects):
if keys[pg.K_SPACE]: if keys[pg.K_f]:
convo = self.findConversation() convo = self.findConversation()
if self.convo_act+1 < len(convo): if self.convo_act+1 < len(convo[2]):
self.text = convo[self.convo_act] self.text = convo[2][self.convo_act]
self.convo_act += 1 self.convo_act += 1
else: else:
if convo[0] == 'oldlady':
if convo[1] == 0:
for i in range(0,5):
objects[1].append(Rat('rat', random.randint(150,250), 800, 400+i*20, 1, 1, 1, 100, 25))
elif convo[1] == 1:
objects[0][0].level.level = 5
while 'rat' in objects[0][0].killed: objects[0][0].killed.remove('rat')
if convo[0] == 'elder':
if convo[1] == 0:
objects[4].append(Obstacle('portal', 'interactable', 'art/images/background/portal.png', False, 700, 300))
self.convo_scene += 1
self.convo_act = 0 self.convo_act = 0
self.npc.talking = False self.npc.talking = False
objects[0][0].talking = False objects[0][0].talking = False
@ -134,14 +151,15 @@ class Fighter(Objects):
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, killed =[]) -> 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, level, 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.thinks = Thinks(self.x+20, self.y-50, 150, 100, 'brr Im freezing') self.thinks = Thinks(self.x+20, self.y-50, 150, 100, 'brr I\'m freezing')
self.freezing = True self.freezing = True
self.killed = killed #amount of mobs that were killed
def draw(self, screen): def draw(self, screen):
if self.hidden: if self.hidden:
@ -164,9 +182,11 @@ class MainCharacter(Fighter):
if touches is not None: if touches is not None:
if touches.name == 'fireplace': if touches.name == 'fireplace':
self.freezing = False self.freezing = False
elif touches.name == 'portal': elif touches.name == 'portal' and self.level.level != 1:
return 'play' return 'play'
elif touches.name == 'house': elif touches.name == 'house' and self.level.level != 1:
self.x = 500
self.y = 400
return 'house' return 'house'
elif 'wall' in touches.name: elif 'wall' in touches.name:
return 'wall' return 'wall'
@ -205,11 +225,7 @@ class MainCharacter(Fighter):
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): elif isinstance(touches, NPC):
if keys[pg.K_f]: return
touches.talk(objects)
return
else:
return
if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x)) if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x))
elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x - touches.rect.width * 0.66)) elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x - touches.rect.width * 0.66))
@ -235,9 +251,9 @@ class MainCharacter(Fighter):
if self.book.current_sp == 'fireball': if self.book.current_sp == 'fireball':
weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5) weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
elif self.book.current_sp == 'windslash': elif self.book.current_sp == 'windslash':
weapon = Windslash('ws1', 100, self.x, self.y, moveto, 5) weapon = Windslash('ws1', 100, self.x, self.y, moveto, 10)
else: else:
return weapon = Punch('punch', 100, self.x, self.y, moveto, 1, Mobs, life_ticks=500)
obj[3].append(weapon) obj[3].append(weapon)
self.lastAttack = pg.time.get_ticks() self.lastAttack = pg.time.get_ticks()
@ -246,7 +262,7 @@ class MainCharacter(Fighter):
self.walk(keys, objects) self.walk(keys, objects)
if pg.mouse.get_pressed()[0]: if pg.mouse.get_pressed()[0]:
self.attack(objects, vec(mouse)) self.attack(objects, vec(mouse))
self.thinks.update(self) self.thinks.update(objects, self)
if self.health.health <= 0: if self.health.health <= 0:
return 'village' return 'village'
else: else:
@ -301,12 +317,17 @@ class Hearts():
class Level(Label): class Level(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color='#1e90ff', sprite='label.png') -> None: def __init__(self, x, y, width, height, level, 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) super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
self.level = level
def draw(self, screen):
self.text = f'will to live: {self.level}%'
super().draw(screen)
class Thinks(Label): class Thinks(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='thinks.png') -> None: def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='thinks.png') -> None:
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite) super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
self.scene = 0
def draw(self, screen, x, y): def draw(self, screen, x, y):
if self.hidden: if self.hidden:
@ -315,10 +336,22 @@ class Thinks(Label):
self.y = y self.y = y
super().draw(screen) super().draw(screen)
def update(self, main): def update(self, objects, main):
if not self.hidden: if not self.hidden:
if not main.freezing: if self.scene == 0 and not main.freezing:
self.scene = 1
self.hidden = True self.hidden = True
elif self.scene == 1 and main.talking:
self.scene = 2
self.hidden = True
if self.scene == 1:
touches = pg.sprite.spritecollideany(main, objects[2])
if touches is not None and isinstance(touches, NPC):
self.text = 'I should press \"f\"'
self.hidden = False
else:
self.hidden = False
self.text = 'the lady over there'
class Book(): class Book():
def __init__(self, x, y, spells, current_spell, current_shield) -> None: def __init__(self, x, y, spells, current_spell, current_shield) -> None:
@ -332,11 +365,12 @@ class Book():
self.sp_list = spells self.sp_list = spells
self.current_sp = current_spell self.current_sp = current_spell
self.text_left = ["Dear User, ", "in case you fell on the ground too hard,", "here is a quick reminder:", self.text_left = ["Dear User, ", "in case you fell on the ground too hard,", "here is a quick reminder:",
"You are a homeless person.","One cold day you went to the library to get warm.", "You are a homeless person. One cold day","you went to the library to warm up yourself.",
"There you saw and opened me out of boedom.", "This lead to you being thrown in this world.", "There you got bored and found and opened me.", "This lead to you being thrown into this world.",
"But you can find a way out of here again."] "But you can find a way out of here again."]
self.text_right = ["This book will help you to survive.", "Click on a picture to choose your spell.", self.text_right = ["This book will help you to survive.", "You can open and close me when pressing e.",
"Talk to fairies to unlock new spells!"] "Click on a picture to choose your spell.",
"Talk to fairies to unlock new spells!"]
self.buttons=[] self.buttons=[]
self.buttons_y = 400 self.buttons_y = 400
self.buttons_x = 800 self.buttons_x = 800
@ -410,6 +444,7 @@ class Mobs(Fighter):
def hurt(self, damage, objects): def hurt(self, damage, objects):
self.health -= damage self.health -= damage
if self.health <= 0: if self.health <= 0:
objects[0][0].killed.append(self.name)
self.hidden = True self.hidden = True
objects[1].remove(self) objects[1].remove(self)
@ -435,7 +470,17 @@ class Zombie(Mobs):
def attack(self, moveto, obj): def attack(self, moveto, obj):
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage)) obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter))
self.lastAttack = pg.time.get_ticks()
class Rat(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/rat.png', drops=0) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj):
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter))
self.lastAttack = pg.time.get_ticks() self.lastAttack = pg.time.get_ticks()
class Weapons(Objects): class Weapons(Objects):
@ -479,7 +524,7 @@ class Fireball(Spells):
self.die(objects, Mobs) self.die(objects, Mobs)
class Windslash(Spells): class Windslash(Spells):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=700) -> None: def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=1000) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
def update(self, objects): def update(self, objects):
@ -501,9 +546,10 @@ class Arrow(Weapons):
class Punch(Weapons): class Punch(Weapons):
def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/empty.png', life_ticks=100) -> None: def __init__(self, name, ms, x, y, moveto, damage, kills, sprite = 'weapons/empty.png', life_ticks=100) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
self.kills = kills
def update(self, objects): def update(self, objects):
self.move(objects) self.move(objects)
self.die(objects, MainCharacter) self.die(objects, self.kills)