From 31a9742a9c1484b7095bd3e46f16d7ab585fbaa0 Mon Sep 17 00:00:00 2001 From: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:50:09 +0100 Subject: [PATCH 1/2] attack now with left mouse click emter conversaton now with f no change to leave conversation Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> --- viecher.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/viecher.py b/viecher.py index fdebe16..a85a026 100644 --- a/viecher.py +++ b/viecher.py @@ -162,7 +162,7 @@ class MainCharacter(Fighter): self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) return elif isinstance(touches, NPC): - if keys[pg.K_SPACE]: + if keys[pg.K_f]: touches.talk(objects) return else: @@ -188,7 +188,7 @@ class MainCharacter(Fighter): def attack(self, obj, mouse): if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): - moveto = mouse- vec(self.x, self.y) + moveto = mouse - vec(self.x, self.y) if self.book.current_sp == 'fireball': weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5) elif self.book.current_sp == 'windslash': @@ -201,7 +201,7 @@ class MainCharacter(Fighter): def update(self, keys, mouse, objects): if not self.talking: self.walk(keys, objects) - if keys[pg.K_f]: + if pg.mouse.get_pressed()[0]: self.attack(objects, vec(mouse)) self.speech.update(self) if self.health.health <= 0: From bd5ff8b3fe2c527c29f12e7a16e28971fad61af2 Mon Sep 17 00:00:00 2001 From: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> Date: Fri, 8 Mar 2024 08:36:13 +0100 Subject: [PATCH 2/2] fixed wall colision added object collision for mobs Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> --- classes.py | 4 ++-- viecher.py | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/classes.py b/classes.py index bc89d1e..6e1c8ea 100644 --- a/classes.py +++ b/classes.py @@ -243,8 +243,8 @@ class Room(GameObjects): self.locked = True else: self.locked = False - [self.objects[3].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] - + [self.objects[4].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] + def genWalls(self, WIDTH, HEIGHT): walls = [] walls.append(Obstacle('wall_l', 'wall', None, True, 32, 32, True, WIDTH=4, HEIGHT=HEIGHT)) diff --git a/viecher.py b/viecher.py index a85a026..5d11e6c 100644 --- a/viecher.py +++ b/viecher.py @@ -150,6 +150,7 @@ class MainCharacter(Fighter): if touches is not None and not isinstance(touches, Weapons): if isinstance(touches, Obstacle): if not touches.collision: + print(touches.name) return if touches.type == 'wall': if touches.name == 'wall_l': @@ -169,11 +170,11 @@ class MainCharacter(Fighter): return 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)) + elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x - touches.rect.width * 0.66)) #if self.y <= touches.y: pass #elif self.y > touches.y: pass - self.x -= moveto[0] * 2 / fps - self.y -= moveto[1] * 2 / fps + #self.x -= moveto[0] * 2 / fps + #self.y -= moveto[1] * 2 / fps """ if self.x <= 32: @@ -317,6 +318,7 @@ class Book(): def update(self): pass + class Mobs(Fighter): def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None: super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) @@ -330,6 +332,23 @@ class Mobs(Fighter): moveto.scale_to_length(self.speed) self.x += moveto[0] / fps self.y += moveto[1] / fps + touches = pg.sprite.spritecollideany(self, obj[4]) + if touches is not None and not isinstance(touches, Weapons): + if isinstance(touches, Obstacle): + if not touches.collision: + return + if touches.type == 'wall': + if touches.name == 'wall_l': + self.x += (2 + (self.x - touches.rect.x)) + elif touches.name == 'wall_r': + self.x -= (2 + self.rect.width - (touches.rect.x - self.x)) + if touches.name == 'wall_t': + self.y += (2 + (self.y - touches.rect.y)) + elif touches.name == 'wall_b': + self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) + + 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)) else: self.attack(moveto, obj)