aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2023-07-30 12:00:21 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2023-07-30 12:00:21 +0530
commit14854093230eb5fd54bf8f64381696e4d7e1308a (patch)
treeae20413c5e79c7634d597510b6160f4155415c81
add files
-rw-r--r--README.md14
-rw-r--r--TODO.md10
-rw-r--r--cockroach0
-rw-r--r--cockroach_game.py62
-rw-r--r--game.py57
-rw-r--r--game1.py121
-rw-r--r--res/DALL·E 2023-07-30 11.40.55 - astronaut helmet.pngbin0 -> 929068 bytes
-rw-r--r--res/DALL·E 2023-07-30 11.43.08 - blood around the cockroach such that it is squashed.pngbin0 -> 1510208 bytes
-rw-r--r--res/DALL·E 2023-07-30 11.43.10 - blood around the cockroach such that it is squashed.pngbin0 -> 1475428 bytes
-rw-r--r--res/DALL·E 2023-07-30 11.43.12 - blood around the cockroach such that it is squashed.pngbin0 -> 1373625 bytes
-rw-r--r--res/floor.jpegbin0 -> 130837 bytes
11 files changed, 264 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3ce8135
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+# TODO
+
+* Draw cockroach
+* Detect foot movement (RAGHU)
+* Animation of cockroach dying
+* Movement of cockroach
+* Colli ection between foot and cockroach
+* Cockroach spawning in optimal locations (far from each other)
+* Add 0.5 second disability after killing one
+
+
+# LORE
+
+YOu cant see the cockroaches without the app \ No newline at end of file
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..1b7e02b
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,10 @@
+# TODO
+
+* Draw cockroach
+* Detect foot movement
+* Animation of cockroach dying
+* Movement of cockroach
+* Collision detection between foot and cockroach
+* Cockroach spawning in optimal locations (far from each other)
+* Add 0.5 second disability after killing one
+* \ No newline at end of file
diff --git a/cockroach b/cockroach
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cockroach
diff --git a/cockroach_game.py b/cockroach_game.py
new file mode 100644
index 0000000..23e8265
--- /dev/null
+++ b/cockroach_game.py
@@ -0,0 +1,62 @@
+import pygame
+import random
+
+# Initialize Pygame
+pygame.init()
+
+# Define screen dimensions
+SCREEN_WIDTH = 800
+SCREEN_HEIGHT = 600
+
+# Load cockroach image
+cockroach_image = pygame.image.load('res/cockroach.png')
+
+class Cockroach:
+ def __init__(self):
+ self.x = SCREEN_WIDTH
+ self.y = random.randint(0, SCREEN_HEIGHT - 40)
+ self.speed_x = random.randint(1, 5)
+
+ def move(self):
+ self.x -= self.speed_x
+
+ def draw(self, screen):
+ screen.blit(cockroach_image, (self.x, self.y))
+
+def main():
+ # Create the game screen
+ screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
+ pygame.display.set_caption('Cockroach Spawning and Movement')
+
+ # Create a list to hold cockroaches
+ cockroaches = []
+
+ # Game loop
+ running = True
+ while running:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ running = False
+
+ # Spawn a new cockroach randomly
+ if len(cockroaches) < 5 and random.random() < 0.02:
+ cockroaches.append(Cockroach())
+
+ # Move cockroaches and remove off-screen ones
+ for cockroach in cockroaches:
+ cockroach.move()
+ if cockroach.x <= -40:
+ cockroaches.remove(cockroach)
+
+ # Draw everything on the screen
+
+ for cockroach in cockroaches:
+ cockroach.draw(screen)
+
+ # Update the display
+ pygame.display.flip()
+
+ pygame.quit()
+
+if __name__ == "__main__":
+ main()
diff --git a/game.py b/game.py
new file mode 100644
index 0000000..5d6462b
--- /dev/null
+++ b/game.py
@@ -0,0 +1,57 @@
+import cv2
+
+import numpy as np
+
+class Game:
+ def __init__(self) -> None:
+ # Open the webcame (0 is usually the default)
+ self.cap = cv2.VideoCapture(0)
+
+ def loop(self) -> None:
+ while True:
+ # Read frame
+ ret, frame = self.cap.read()
+
+ # If frame is not returned, break
+ if not ret:
+ break
+
+ # Convert frame from RGB to HSV, and define frame used for detection
+ det_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
+
+ # Define lower green and upper green
+ lower_green = np.array([60, 100, 100])
+ upper_green = np.array([100, 255, 255])
+
+ # Define green mask
+ green_mask = cv2.inRange(det_frame, lower_green, upper_green)
+
+ # Detect contours
+ contours, _ = cv2.findContours(green_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
+
+ # Find largest contour
+ largest_contour = max(contours, key=cv2.contourArea) if contours else None
+
+ # If largest contour is present, draw a green rectangle
+ if largest_contour is not None:
+ x, y, w, h = cv2.boundingRect(largest_contour)
+ cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
+
+ # Show frame
+ cv2.imshow('Foot Tracking', frame)
+
+ # Quit if 'q' is pressed
+ if cv2.waitKey(1) & 0xFF == ord('q'):
+ self.stop()
+
+ def stop(self) -> None:
+ # Release captured webcam
+ self.cap.release()
+
+ # Destroy all CV2 Windows
+ cv2.destroyAllWindows()
+
+if __name__ == '__main__':
+ game = Game()
+
+ game.loop() \ No newline at end of file
diff --git a/game1.py b/game1.py
new file mode 100644
index 0000000..b22d903
--- /dev/null
+++ b/game1.py
@@ -0,0 +1,121 @@
+import cv2
+import numpy as np
+import pygame
+import random
+import threading
+
+# Initialize Pygame
+pygame.init()
+
+# Define screen dimensions
+SCREEN_WIDTH = 800
+SCREEN_HEIGHT = 600
+
+# Load cockroach image
+cockroach_image = pygame.image.load('res/cockroach.png')
+
+class Cockroach:
+ def __init__(self):
+ self.x = SCREEN_WIDTH
+ self.y = random.randint(0, SCREEN_HEIGHT - 40)
+ self.speed_x = random.randint(1, 5)
+
+ def move(self):
+ self.x -= self.speed_x
+
+ def draw(self, screen):
+ screen.blit(cockroach_image, (self.x, self.y))
+
+def run_cockroach_game():
+ # Create the game screen
+ screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
+ pygame.display.set_caption('Cockroach Spawning and Movement')
+
+ # Create a list to hold cockroaches
+ cockroaches = []
+
+ # Game loop
+ running = True
+ while running:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ running = False
+
+ # Spawn a new cockroach randomly
+ if len(cockroaches) < 5 and random.random() < 0.02:
+ cockroaches.append(Cockroach())
+
+ # Move cockroaches and remove off-screen ones
+ for cockroach in cockroaches:
+ cockroach.move()
+ if cockroach.x <= -40:
+ cockroaches.remove(cockroach)
+
+ # Draw everything on the screen
+ screen.fill((255, 255, 255)) # Fill the screen with white
+ for cockroach in cockroaches:
+ cockroach.draw(screen)
+
+ # Update the display
+ pygame.display.flip()
+
+ pygame.quit()
+
+class Game:
+ def __init__(self) -> None:
+ # Open the webcam (0 is usually the default)
+ self.cap = cv2.VideoCapture(0)
+
+ def loop(self) -> None:
+ while True:
+ # Read frame
+ ret, frame = self.cap.read()
+
+ # If frame is not returned, break
+ if not ret:
+ break
+
+ # Convert frame from RGB to HSV and define frame used for detection
+ det_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
+
+ # Define lower green and upper green
+ lower_green = np.array([60, 100, 100])
+ upper_green = np.array([100, 255, 255])
+
+ # Define green mask
+ green_mask = cv2.inRange(det_frame, lower_green, upper_green)
+
+ # Detect contours
+ contours, _ = cv2.findContours(green_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
+
+ # Find the largest contour
+ largest_contour = max(contours, key=cv2.contourArea) if contours else None
+
+ # If the largest contour is present, draw a green rectangle
+ if largest_contour is not None:
+ x, y, w, h = cv2.boundingRect(largest_contour)
+ cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
+
+ # Show the frame
+ cv2.imshow('Foot Tracking', frame)
+
+ # Quit if 'q' is pressed
+ if cv2.waitKey(1) & 0xFF == ord('q'):
+ self.stop()
+
+ def stop(self) -> None:
+ # Release the captured webcam
+ self.cap.release()
+
+ # Destroy all CV2 Windows
+ cv2.destroyAllWindows()
+
+if __name__ == '__main__':
+ game = Game()
+
+ # Start the cockroach game in a separate thread
+ cockroach_thread = threading.Thread(target=run_cockroach_game)
+ cockroach_thread.start()
+
+ # Start the webcam feed and foot tracking loop
+ game.loop() \ No newline at end of file
diff --git a/res/DALL·E 2023-07-30 11.40.55 - astronaut helmet.png b/res/DALL·E 2023-07-30 11.40.55 - astronaut helmet.png
new file mode 100644
index 0000000..acd6987
--- /dev/null
+++ b/res/DALL·E 2023-07-30 11.40.55 - astronaut helmet.png
Binary files differ
diff --git a/res/DALL·E 2023-07-30 11.43.08 - blood around the cockroach such that it is squashed.png b/res/DALL·E 2023-07-30 11.43.08 - blood around the cockroach such that it is squashed.png
new file mode 100644
index 0000000..63631d1
--- /dev/null
+++ b/res/DALL·E 2023-07-30 11.43.08 - blood around the cockroach such that it is squashed.png
Binary files differ
diff --git a/res/DALL·E 2023-07-30 11.43.10 - blood around the cockroach such that it is squashed.png b/res/DALL·E 2023-07-30 11.43.10 - blood around the cockroach such that it is squashed.png
new file mode 100644
index 0000000..f52d241
--- /dev/null
+++ b/res/DALL·E 2023-07-30 11.43.10 - blood around the cockroach such that it is squashed.png
Binary files differ
diff --git a/res/DALL·E 2023-07-30 11.43.12 - blood around the cockroach such that it is squashed.png b/res/DALL·E 2023-07-30 11.43.12 - blood around the cockroach such that it is squashed.png
new file mode 100644
index 0000000..86fa7f8
--- /dev/null
+++ b/res/DALL·E 2023-07-30 11.43.12 - blood around the cockroach such that it is squashed.png
Binary files differ
diff --git a/res/floor.jpeg b/res/floor.jpeg
new file mode 100644
index 0000000..83a1069
--- /dev/null
+++ b/res/floor.jpeg
Binary files differ