]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
added weapon
authorSkullheadx <704277@pdsb.net>
Wed, 6 Jul 2022 23:29:06 +0000 (19:29 -0400)
committerSkullheadx <704277@pdsb.net>
Wed, 6 Jul 2022 23:29:06 +0000 (19:29 -0400)
Enemy.py
MainMenu.py
Setup.py
Weapon.py
main.py

index 6793cf95bab0adafec4cc1d04464927636a9bceb..4382fc17ac468f9642a8d28be462e94486967246 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -2,6 +2,7 @@ from argparse import Action
 from Setup import *
 from Player import Player
 from Actors import Actor
+from Weapon import Melee
 
 class Enemy(Actor):
     width, height = 25, 50
@@ -19,19 +20,27 @@ class Enemy(Actor):
         self.movable = True
         self.dizzy_time = 0
 
+        self.weapon = Melee(self.position, (-35,self.height/2 - 20),self.width,-1)
+
     def update(self, delta, target=None):
         super().update(delta)
         if target is not None and self.dizzy_time == 0:
-            self.follow_target(target)
+            self.follow_target(target,stop_dist=self.weapon.width + self.width + target.width)
         self.dizzy_time -= delta
         self.dizzy_time = max(0,self.dizzy_time)
 
         # Deals with collision and applying velocity
         self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta)
 
+        self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x))
+
     def knockout(self, node):
         self.dizzy_time = 5000
         self.health -= 10
         node.on_ground = True
         node.jump()
         # self.crouch(1000)
+
+    def draw(self, surf):
+        self.weapon.draw(surf)
+        super(Enemy, self).draw(surf)
index 21f00ccb0f2c7c44c0fe146109816dee856d6d01..5a4ccb1c3a84f41276b367547ed7511a937edf50 100644 (file)
@@ -27,7 +27,7 @@ class Menu:
 
                     if (x1 <= mouseX <= x2 and y1 <= mouseY <= y2):
                         self.menuFunctions(i)
-            return;
+            return
 
     def draw(self, surf):
         screen.fill((255, 255, 255))
@@ -41,4 +41,4 @@ class Menu:
             case 2:
                 print("Options")
             case 3:
-                pg.quit();
\ No newline at end of file
+                pg.quit();
index 40cfdc57da342b59eee03d853e01969acaf0c000..85c4d6b3c6332c76db3310b664de41cc2431de74 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -1,4 +1,5 @@
 import pygame as pg
+import math
 from Area import Area
 
 pg.init()
@@ -15,4 +16,3 @@ clock = pg.time.Clock()
 fps = 60
 
 screen = pg.display.set_mode(dimensions, pg.SCALED)
-
index 20a765e842ed85b0e45c8c2dcfb64f4c6d2ca3b4..a70c2f182341a0f819b4005c418b0e90735084d3 100644 (file)
--- a/Weapon.py
+++ b/Weapon.py
@@ -2,15 +2,27 @@ from Setup import *
 
 
 class Melee:
-    img = pg.image.load("Assets/SWORD.png")
+    img = pg.transform.smoothscale(pg.image.load("Assets/SWORD.png"), (40,40))
+    flipped_img = pg.transform.flip(img,True,False)
+    width,height = img.get_size()
     def __init__(self, pos, offset, width,direction):
         self.position = pg.Vector2(pos)
         self.offset = pg.Vector2(offset)
         self.holder_width = width
 
 
-    def update(self, delta):
-        pass
+    def update(self, delta, pos, direction):
+        self.position = pg.Vector2(pos)
+        self.direction = direction
+
+    def get_collision_rect(self):
+        if self.direction == -1:
+            return pg.Rect(self.position - pg.Vector2(self.width,0),(self.width, self.height))
+        elif self.direction == 1:
+            return pg.Rect(self.position + pg.Vector2(self.holder_width,0),(self.width, self.height))
 
     def draw(self, surf):
-        pass
+        if self.direction == -1:
+            surf.blit(self.img, self.get_collision_rect().topleft)
+        else:
+            surf.blit(self.flipped_img, self.get_collision_rect().topleft)
diff --git a/main.py b/main.py
index 6014e78614e24a2411d56210b6dc2ac91c104a48..2d49c26ecc7ce9512fb22d7d5ddc5381974a6387 100644 (file)
--- a/main.py
+++ b/main.py
@@ -5,18 +5,20 @@ from MainMenu import Menu
 delta = 1000//fps
 is_running = True
 
-level = 0
+level = 1
 old_level = level
-scene = Menu()
+# scene = Menu()
+
+scene = Game()
 
 while is_running:
     if pg.event.peek(pg.QUIT):
         is_running = False
 
-    if(level == 0):
+    if level == 0:
         level = scene.level
 
-    if(old_level != level):
+    if old_level != level:
         old_level = level
         match level:
             case 0:
@@ -30,4 +32,4 @@ while is_running:
     pg.display.update()
     delta = clock.tick(fps)
 
-pg.quit()
\ No newline at end of file
+pg.quit()