diff --git a/README.md b/README.md
index 825cba1..48cbf97 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,33 @@
-# InteractiveProgramming
+# Interactive Programming
-This is the base repo for the interactive programming project for Software Design at Olin College.
+Software Design MP4
+Hand-Tracking Fruit Ninja
+
+In this immersive gaming experience, Fruit Ninja moves off of your phone screen and into 3D! Swipe your hand through space and slice the fruit on the screen in real time. The game is infinite, and so is the fun.
+
+## Getting Started:
+
+### Installing Packages
+This game makes use of OpenCV and Pygame libraries. For everything you need, run the following.
+
+pip install cv2, pygame, numpy, imutils, argparse
+
+### Downloading Files
+Download the following files, as well as all fruit images, from the repository:
+
+ninja.py: main game file
+all_fruits.py: holds fruit class and apple, banana, strawberry subclasses
+Scoring.py: holds scoreboard class
+
+### Usage
+To run the game, run ninja.py with Python 3.
+
+### Calibration
+The game requires a still image from the webcam to begin hand detection. A camera display will pop up when you run ninja.py, in which the captured frame is contained within the blue rectangle. Make sure your hand is not in this area! Click on the webcam screen and press "b" on the keyboard when you're ready to take a picture.
+
+When the image has been taken, you're ready to play! Navigate to the game screen and slice the fruit by gesturing. Try to keep the rest of the background as static as possible for the best results (i.e., don't move your computer, have people walking behind you, etc.)
+
+Enjoy!
+
+## Links:
+[Project Reflection](Reflection.pdf)
diff --git a/Reflection.pdf b/Reflection.pdf
new file mode 100644
index 0000000..b5ed03a
Binary files /dev/null and b/Reflection.pdf differ
diff --git a/Scoring.py b/Scoring.py
new file mode 100644
index 0000000..7a44ab6
--- /dev/null
+++ b/Scoring.py
@@ -0,0 +1,34 @@
+import random, pygame, sys, pygame.font
+from pygame.locals import *
+
+navyblue = (60,60,100)
+white = (255,255,255)
+
+class Scoreboard(pygame.sprite.Sprite):
+ def __init__(self, screen):
+ pygame.sprite.Sprite.__init__(self)
+ self.fruit_sliced = 0
+ self.fruit_missed = 0
+ self.screen = screen
+
+ self.sb_height, self.sb_width = 50, self.screen.get_width()
+ self.rect = pygame.Rect(0,0, self.sb_width, self.sb_height)
+ self.bg_color = navyblue
+ self.text_color = white
+ self.font = pygame.font.SysFont('Arial', 18)
+
+ self.x_sliced_position, self.y_sliced_position = 20.0, 10.0
+ self.x_missed_position, self.y_missed_position = self.screen.get_width()-100, 10.0
+
+ def prep_scores(self):
+ self.sliced_string = "Sliced: " + str(self.fruit_sliced)
+ self.sliced_image = self.font.render(self.sliced_string, True, self.text_color)
+
+ self.missed_string = "Missed: " + str(self.fruit_missed)
+ self.missed_image = self.font.render(self.missed_string, True, self.text_color)
+
+ def show(self):
+ self.prep_scores()
+ self.screen.fill(self.bg_color, self.rect)
+ self.screen.blit(self.sliced_image, (self.x_sliced_position, self.y_sliced_position))
+ self.screen.blit(self.missed_image, (self.x_missed_position, self.y_missed_position))
diff --git a/all_fruits.py b/all_fruits.py
new file mode 100644
index 0000000..f7f9973
--- /dev/null
+++ b/all_fruits.py
@@ -0,0 +1,163 @@
+import random, pygame, sys, math
+from pygame.locals import *
+
+white = (255, 255, 255)
+green = (0, 255, 0)
+
+class Fruit(pygame.sprite.Sprite):
+ def __init__(self, screen, image_name):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.speed = .3
+ self.screen = screen
+ self.total_time = 0
+ self.time = 0
+
+ self.image = pygame.image.load(image_name).convert_alpha()
+ self.image.set_colorkey(white)
+ self.image.convert_alpha()
+ self.rect = self.image.get_rect()
+
+ self.x = random.randint(0, self.screen.get_width()-int(self.image.get_width()/2))
+ self.y = self.screen.get_height()+self.image.get_width()
+
+ self.rect.centerx = self.x + (self.image.get_width()/2)
+ self.rect.centery = self.y + (self.image.get_height()/2)
+
+ #figure out direction to fruit to move based on spawn position (left or right)
+ border = screen.get_width()/2
+ #if starts to the left, move over right
+ if (self.x < border):
+ self.direction = 1
+ #if starts over on the right, move left
+ else:
+ self.direction = -1
+
+ #determine realistic trajectory angle that will clear minimum height and not exceed maximum
+ min_height = .6*screen.get_height()
+ max_height = .9*screen.get_height()
+
+ start_distance_from_border = abs(self.x - border)
+ distance_from_border = random.randint(0, int(start_distance_from_border))
+
+ try:
+ min_angle = math.atan(min_height/distance_from_border)
+ max_angle = math.atan(max_height/distance_from_border)
+
+ self.angle = random.randint(int(min_angle), int(max_angle))
+ except:
+ self.angle = math.pi/2
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x + (self.image.get_width()/2)
+ self.rect.centery = y + (self.image.get_height()/2)
+
+ def toss(self, time_passed):
+ #self.y -= self.speed*time_passed
+ self.total_time = self.total_time+time_passed
+ self.time = self.total_time/800
+
+ x_speed = random.randint(0,25)
+ add_x = math.sin(self.time) * x_speed
+ self.x += self.direction*add_x
+
+ y_speed = random.randint(30,43)
+ add_y = math.cos(self.time) *y_speed
+ self.y -= add_y
+
+ def draw(self):
+ self.screen.blit(self.image, (self.x, self.y))
+
+ def checkCollision(self, other):
+ # returns True or False if apple has collided with other object
+ col = pygame.sprite.collide_rect(self, other)
+ return col
+
+ def fall(self, time_passed):
+ add_x = .15*time_passed
+ self.x += self.direction*add_x
+
+ add_y = .7*time_passed
+ self.y += add_y
+
+class Apple(Fruit):
+ def __init__(self, screen):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'apple.png')
+
+class Banana(Fruit):
+ def __init__(self, screen):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'banana.png')
+
+class Strawberry(Fruit):
+ def __init__(self, screen):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'strawberry.png')
+
+class Half_Apple1(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'apple_half1.png')
+ self.x = start_x
+ self.y = start_y
+
+class Half_Apple2(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'apple_half2.png')
+ self.x = start_x
+ self.y = start_y
+
+class Half_Banana1(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'ban2.png')
+ self.x = start_x
+ self.y = start_y
+
+class Half_Banana2(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'ban1.png')
+ self.x = start_x
+ self.y = start_y
+
+class Half_Strawberry1(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'straw1.png')
+ self.x = start_x
+ self.y = start_y
+
+class Half_Strawberry2(Fruit):
+ def __init__(self, screen, start_x, start_y):
+ # Call the parent class (Fruit) constructor
+ super().__init__(screen, 'straw2.png')
+ self.x = start_x
+ self.y = start_y
+
+class Sword(pygame.sprite.Sprite):
+ def __init__(self, x, y, screen):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.x = x
+ self.y = y
+ self.screen = screen
+
+ self.image = pygame.image.load("sword.png")
+ self.rect = self.image.get_rect()
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x
+ self.rect.centery = y
+
+ def draw(self):
+ self.screen.blit(self.image, self.rect)
+
+ def printrect(self):
+ print(self.rect.centerx, ", ", self.rect.centery)
diff --git a/apple.png b/apple.png
new file mode 100644
index 0000000..50178f7
Binary files /dev/null and b/apple.png differ
diff --git a/apple_half1.png b/apple_half1.png
new file mode 100644
index 0000000..3b889aa
Binary files /dev/null and b/apple_half1.png differ
diff --git a/apple_half2.png b/apple_half2.png
new file mode 100644
index 0000000..c0a4967
Binary files /dev/null and b/apple_half2.png differ
diff --git a/ban1.png b/ban1.png
new file mode 100644
index 0000000..1425ca4
Binary files /dev/null and b/ban1.png differ
diff --git a/ban2.png b/ban2.png
new file mode 100644
index 0000000..65245b3
Binary files /dev/null and b/ban2.png differ
diff --git a/banana.png b/banana.png
new file mode 100644
index 0000000..899106c
Binary files /dev/null and b/banana.png differ
diff --git a/fruits.py b/fruits.py
new file mode 100644
index 0000000..23001ae
--- /dev/null
+++ b/fruits.py
@@ -0,0 +1,246 @@
+import random, pygame, sys, math
+from pygame.locals import *
+
+white = (255, 255, 255)
+green = (0, 255, 0)
+
+class Apple(pygame.sprite.Sprite):
+ def __init__(self, screen):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.speed = .3
+ self.screen = screen
+ self.total_time = 0
+ self.time = 0
+
+ self.image = pygame.image.load("apple.png").convert_alpha()
+ self.image.set_colorkey(white)
+ self.image.convert_alpha()
+ self.rect = self.image.get_rect()
+
+ self.x = random.randint(0, self.screen.get_width()-int(self.image.get_width()/2))
+ self.y = self.screen.get_height()+self.image.get_width()
+
+ self.rect.centerx = self.x + (self.image.get_width()/2)
+ self.rect.centery = self.y + (self.image.get_height()/2)
+
+ #figure out direction to fruit to move based on spawn position (left or right)
+ border = screen.get_width()/2
+ #if starts to the left, move over right
+ if (self.x < border):
+ self.direction = 1
+ #if starts over on the right, move left
+ else:
+ self.direction = -1
+
+ #determine realistic trajectory angle that will clear minimum height and not exceed maximum
+ min_height = .6*screen.get_height()
+ max_height = .9*screen.get_height()
+
+ start_distance_from_border = abs(self.x - border)
+ distance_from_border = random.randint(0, int(start_distance_from_border))
+
+ try:
+ min_angle = math.atan(min_height/distance_from_border)
+ max_angle = math.atan(max_height/distance_from_border)
+
+ self.angle = random.randint(int(min_angle), int(max_angle))
+ except:
+ self.angle = math.pi/2
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x + (self.image.get_width()/2)
+ self.rect.centery = y + (self.image.get_height()/2)
+
+ def fall(self, time_passed):
+ #self.y -= self.speed*time_passed
+ self.total_time = self.total_time+time_passed
+ self.time = self.total_time/300
+
+ x_speed = random.randint(0,25)
+ add_x = math.sin(self.time) * x_speed
+ self.x += self.direction*add_x
+
+ y_speed = random.randint(120,170)
+ add_y = math.cos(self.time) * self.speed*y_speed
+ self.y -= add_y
+
+
+ def draw(self):
+ self.screen.blit(self.image, (self.x, self.y))
+
+ def checkCollision(self, other):
+ # returns True or False if apple has collided with other object
+ col = pygame.sprite.collide_rect(self, other)
+ return col
+
+class Banana(pygame.sprite.Sprite):
+ def __init__(self, screen):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.speed = .3
+ self.screen = screen
+ self.total_time = 0
+ self.time = 0
+
+ self.image = pygame.image.load("banana.png").convert_alpha()
+ self.image.set_colorkey(white)
+ self.image.convert_alpha()
+ self.rect = self.image.get_rect()
+
+ self.x = random.randint(0, self.screen.get_width()-int(self.image.get_width()/2))
+ self.y = self.screen.get_height()+self.image.get_width()
+
+ self.rect.centerx = self.x + (self.image.get_width()/2)
+ self.rect.centery = self.y + (self.image.get_height()/2)
+
+ #figure out direction to fruit to move based on spawn position (left or right)
+ border = screen.get_width()/2
+ #if starts to the left, move over right
+ if (self.x < border):
+ self.direction = 1
+ #if starts over on the right, move left
+ else:
+ self.direction = -1
+
+ #determine realistic trajectory angle that will clear minimum height and not exceed maximum
+ min_height = .6*screen.get_height()
+ max_height = .9*screen.get_height()
+
+ start_distance_from_border = abs(self.x - border)
+ distance_from_border = random.randint(0, int(start_distance_from_border))
+
+ try:
+ min_angle = math.atan(min_height/distance_from_border)
+ max_angle = math.atan(max_height/distance_from_border)
+
+ self.angle = random.randint(int(min_angle), int(max_angle))
+ except:
+ self.angle = math.pi/2
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x + (self.image.get_width()/2)
+ self.rect.centery = y + (self.image.get_height()/2)
+
+ def fall(self, time_passed):
+ #self.y -= time_passed * self.speed
+ self.total_time = self.total_time+time_passed
+ self.time = self.total_time/300
+
+ x_speed = random.randint(0,25)
+ add_x = math.sin(self.time) * x_speed
+ self.x += self.direction*add_x
+
+ y_speed = random.randint(120,170)
+ add_y = math.cos(self.time) * self.speed*y_speed
+ self.y -= add_y
+
+ def draw(self):
+ # draw circle on Sprite surface
+ #draw_pos = self.rect.move(self.x-self.screen.get_width(), self.y - self.screen.get_height())
+ self.screen.blit(self.image, (self.x, self.y))
+ #self.screen.fill(green, self.rect)
+ #pygame.draw.circle(self.screen, self.color, (self.x, self.y), self.r)
+
+ def checkCollision(self, other):
+ # returns True or False if apple has collided with other object
+ col = pygame.sprite.collide_rect(self, other)
+ return col
+
+class Strawberry(pygame.sprite.Sprite):
+ def __init__(self, screen):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.speed = .3
+ self.screen = screen
+ self.total_time = 0
+ self.time = 0
+
+ self.image = pygame.image.load("strawberry.png").convert_alpha()
+ self.image.set_colorkey(white)
+ self.image.convert_alpha()
+ self.rect = self.image.get_rect()
+
+ self.x = random.randint(0, self.screen.get_width()-int(self.image.get_width()/2))
+ self.y = self.screen.get_height()+self.image.get_width()
+
+ self.rect.centerx = self.x + (self.image.get_width()/2)
+ self.rect.centery = self.y + (self.image.get_height()/2)
+
+ #figure out direction to fruit to move based on spawn position (left or right)
+ border = screen.get_width()/2
+ #if starts to the left, move over right
+ if (self.x < border):
+ self.direction = 1
+ #if starts over on the right, move left
+ else:
+ self.direction = -1
+
+ #determine realistic trajectory angle that will clear minimum height and not exceed maximum
+ min_height = .6*screen.get_height()
+ max_height = .9*screen.get_height()
+
+ start_distance_from_border = abs(self.x - border)
+ distance_from_border = random.randint(0, int(start_distance_from_border))
+
+ try:
+ min_angle = math.atan(min_height/distance_from_border)
+ max_angle = math.atan(max_height/distance_from_border)
+
+ self.angle = random.randint(int(min_angle), int(max_angle))
+ except:
+ self.angle = math.pi/2
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x + (self.image.get_width()/2)
+ self.rect.centery = y + (self.image.get_height()/2)
+
+ def fall(self, time_passed):
+ #self.y -= time_passed * self.speed
+ self.total_time = self.total_time+time_passed
+ self.time = self.total_time/300
+
+ x_speed = random.randint(0,25)
+ add_x = math.sin(self.time) * x_speed
+ self.x += self.direction*add_x
+
+ y_speed = random.randint(120,170)
+ add_y = math.cos(self.time) * self.speed*y_speed
+ self.y -= add_y
+
+ def draw(self):
+ self.screen.blit(self.image, (self.x, self.y))
+
+ def checkCollision(self, other):
+ # returns True or False if apple has collided with other object
+ col = pygame.sprite.collide_rect(self, other)
+ return col
+
+class Sword(pygame.sprite.Sprite):
+ def __init__(self, x, y, screen):
+ # Call the parent class (Sprite) constructor
+ pygame.sprite.Sprite.__init__(self)
+ self.x = x
+ self.y = y
+ self.screen = screen
+
+ self.image = pygame.image.load("sword.png")
+ self.rect = self.image.get_rect()
+
+ def move(self, x, y):
+ self.x = x
+ self.y = y
+ self.rect.centerx = x
+ self.rect.centery = y
+
+ def draw(self):
+ self.screen.blit(self.image, self.rect)
+
+ def printrect(self):
+ print(self.rect.centerx, ", ", self.rect.centery)
diff --git a/ninja.py b/ninja.py
new file mode 100644
index 0000000..f51ca57
--- /dev/null
+++ b/ninja.py
@@ -0,0 +1,231 @@
+# FRUIT NINJA #
+# MP4: INTERACTIVE PROGRAMMING #
+# AVA LAKMAZAHERI AND EMMA WESTERHOFF #
+# SOFTWARE DESIGN FALL 2017 #
+
+import random, pygame, sys, argparse, imutils, cv2, copy, math
+import numpy as np
+import inspect
+from pygame.locals import *
+from all_fruits import *
+from Scoring import *
+
+# Hand Tracking Parameters
+threshold = 60 # BINARY threshold
+blurValue = 41 # GaussianBlur parameter
+bgSubThreshold = 50 # Background subtraction threshold
+cap_region_x_begin=0.3 # Background region limit
+cap_region_y_end=0.9 # Background region limit
+isBgCaptured = 0 # Boolean: whether the background has been captured
+center = (0,0) # Default position for sword object
+OBJMOTION = pygame.USEREVENT+1 # User event when object detected
+
+# Game Interface Parameters
+black = (0, 0, 0) # Define background color
+screen_width = 800 # Define game screen size
+screen_height = 500 # Define game screen size
+
+
+def generate_fruit(screen):
+ """
+ Returns Apple, Banana, or Straberry object
+ Fruit choice occurs randomly for maximum novelty in game experience
+ """
+
+ n = random.randint(1,3)
+ if n == 1:
+ return Apple(screen)
+ elif n == 2:
+ return Banana(screen)
+ else:
+ return Strawberry(screen)
+
+def half_fruit(screen, fruit):
+ """
+ Returns two fruit halves based on classification of fruit object input
+ """
+ halves = []
+
+ if isinstance(fruit, Apple):
+ halves = [Half_Apple1(screen, fruit.x, fruit.y), Half_Apple2(screen, fruit.x, fruit.y)]
+ elif isinstance(fruit, Banana):
+ halves = [Half_Banana1(screen, fruit.x, fruit.y), Half_Banana2(screen, fruit.x, fruit.y)]
+ elif isinstance(fruit, Strawberry):
+ halves = [Half_Strawberry1(screen, fruit.x, fruit.y), Half_Strawberry2(screen, fruit.x, fruit.y)]
+ return halves
+
+def printThreshold(thr):
+ """
+ Helper function for background removal/object detection
+ """
+ print("Changed threshold to " + str(thr))
+
+def removeBG(frame, bgModel):
+ """
+ Subtracts background model (defined by user-keyed screen capture) from current frame
+ Returns resulting frame
+ """
+ fgmask = bgModel.apply(frame)
+ kernel = np.ones((3, 3), np.uint8)
+ fgmask = cv2.erode(fgmask, kernel, iterations=1)
+ res = cv2.bitwise_and(frame, frame, mask=fgmask)
+ return res
+
+
+def obj_tracker(frame, bgModel):
+ """
+ Perform background removal and object detection in current frame
+ """
+
+ img = removeBG(frame, bgModel) # Remove background from current scaled frame
+ img = img[0:int(cap_region_y_end * frame.shape[0]), int(cap_region_x_begin*
+ frame.shape[1]):frame.shape[1]]
+
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Convert image to binary
+ blur = cv2.GaussianBlur(gray, (blurValue, blurValue), 0) # Apply Gaussian Blur
+ #cv2.imshow('Blur', blur)
+ ret, thresh = cv2.threshold(blur, threshold, 255, cv2.THRESH_BINARY)
+ #cv2.imshow('Original', thresh)
+
+ thresh1 = copy.deepcopy(thresh) # Get contours
+ _, contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE,
+ cv2.CHAIN_APPROX_SIMPLE)
+
+ length = len(contours)
+ maxArea = -1
+ if length > 0: # If any contours were found:
+ for i in range(length): # Find the largest area contour
+ temp = contours[i] # Isolate one contour
+ area = cv2.contourArea(temp) # Find area
+ if area > maxArea: # If greater than max (-1 originally)
+ maxArea = area # Update max area
+ ci = i # Store index
+ res = contours[ci] # Isolate contour at index
+
+ hull = cv2.convexHull(res) # Find region that encloses contour
+ drawing = np.zeros(img.shape, np.uint8)
+ cv2.drawContours(drawing, [res], 0, (0, 255, 0), 2) # Draw contour
+ cv2.drawContours(drawing, [hull], 0, (0, 0, 255), 3) # Draw enclosing region
+
+ M = cv2.moments(res) # Find image moments (spatial distribution of object)
+ try:
+ center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])) # Center of mass of detected object
+ except: # Reset sword position if moment m00 is returned as 0s
+ center = (0, 0)
+ print("Can't divide by 0!")
+
+ cv2.circle(drawing, center, 8, [100, 100, 100], -1) # Draw center of object -- sword location
+ my_event = pygame.event.Event(OBJMOTION, message="Object detected!", # Create object detection event with sword location parameter
+ center = center)
+ pygame.event.post(my_event) # Post event
+
+ cv2.imshow('Object Detection', drawing) # Show drawing of contour, hull, and center
+
+def get_background():
+ """
+ Before Fruit Ninja begins, the system must be calibrated to the player's webcam background.
+ This function displays the user's background and waits for them to press 'b' to set calibration
+ """
+ camera = cv2.VideoCapture(0) # Start video capture with webcam
+ camera.set(10,200)
+
+ while True:
+ (grabbed, frame) = camera.read()
+ frame = imutils.resize(frame, width=1000) # Resize frame
+ frame = cv2.bilateralFilter(frame, 5, 50, 100) # Apply smoothing filter
+ frame = cv2.flip(frame, 1) # Flip frame horizontally for intuitive motion
+ cv2.rectangle(frame, (int(cap_region_x_begin * frame.shape[1]), 0),
+ (frame.shape[1], int(cap_region_y_end * frame.shape[0])), (255, 0, 0), 2)
+ cv2.imshow('Webcam', frame) # Display background area for user
+
+ k = cv2.waitKey(1) & 0xFF
+ if k == 27: # Press ESC key to exit
+ sys.exit()
+ if k == ord('b'): # Press 'b' to capture background
+ bgModel = cv2.createBackgroundSubtractorMOG2(0, bgSubThreshold) # Generate background model from current frame
+ print('Background Captured')
+ break
+
+ return camera, bgModel
+
+
+def main():
+ pygame.init()
+ screen = pygame.display.set_mode((screen_width, screen_height)) # Set up PyGame screen
+
+ scoreboard = Scoreboard(screen)
+ pygame.display.set_caption('Fruit Ninja')
+ pygame.mouse.set_visible(False)
+
+ clock = pygame.time.Clock()
+ camera, bgModel = get_background() # Wait for user to calibrate background
+
+ fruits = [generate_fruit(screen)] # Generate fruit and sword objects
+ fruit_parts = []
+ sword = Sword(0,0,screen)
+ x = y = 0
+
+ while True:
+ time_passed = clock.tick(30)
+ screen.fill(black)
+
+ (grabbed, frame) = camera.read() # Read from camera
+ frame = imutils.resize(frame, width=1000)
+ frame = cv2.bilateralFilter(frame, 5, 50, 100) # Apply smoothing filter
+ frame = cv2.flip(frame, 1) # Flip the frame horizontally
+ obj_tracker(frame, bgModel) # Live object detection!
+
+ for event in pygame.event.get(): # Check for events
+ if event.type == QUIT: # Allow the user to end the game at any time
+ pygame.quit()
+ sys.exit()
+ elif event.type == OBJMOTION: # Get hand position from object detection
+ pygame.event.clear()
+ x,y = event.center
+
+ sword.move(x,y) # Move sword to hand position
+ sword.draw() # Draw sword on screen
+
+ if len(fruits) == 0: # Make sure there is always fruit on the screen!
+ fruits.append(generate_fruit(screen))
+
+ for a in fruits:
+ a.toss(time_passed) # Launch fruit into projectile motion
+ a.move(a.x, a.y) # Update fruit position for collisions
+ a.draw() # Draw fruit in updated position
+
+ # COLLISION DETECTION
+ # If fruit position and sword position (centroid of hand object) are in the same location, we have hit fruit
+ if a.checkCollision(sword):
+ print("COLLIDE")
+ scoreboard.fruit_sliced +=1 # Add to scoreboard
+ halves = half_fruit(screen, a) # Split fruit --> generate halved objects
+ for half in halves:
+ fruit_parts.append(half)
+ #print(fruit_parts)
+ fruits.remove(a) # Remove original fruit
+ elif a.y > (screen_height+a.image.get_width()): # If the fruit fell off screen without being hit...
+ print('Missed')
+ #print(scoreboard.fruit_missed)
+ scoreboard.fruit_missed +=1 # Count as missed object
+ fruits.remove(a)
+
+ for h in fruit_parts: # Have all split fruit fall down screen
+ h.fall(time_passed)
+ h.move(h.x, h.y)
+ h.draw()
+ if h.y > (screen_height+h.image.get_width()):
+ fruit_parts.remove(h)
+
+ scoreboard.show()
+ pygame.display.update() # Update screen display
+
+ k = cv2.waitKey(1) & 0xFF
+ if k == 27: # ESC key to exit
+ sys.exit()
+ camera.release() # End/close webcam display
+ cv2.destroyAllWindows()
+ break
+
+if __name__ == "__main__":
+ main()
diff --git a/straw1.png b/straw1.png
new file mode 100644
index 0000000..41d28d0
Binary files /dev/null and b/straw1.png differ
diff --git a/straw2.png b/straw2.png
new file mode 100644
index 0000000..a105018
Binary files /dev/null and b/straw2.png differ
diff --git a/strawberry.png b/strawberry.png
new file mode 100644
index 0000000..1a59fc4
Binary files /dev/null and b/strawberry.png differ
diff --git a/sword.png b/sword.png
new file mode 100644
index 0000000..52907bc
Binary files /dev/null and b/sword.png differ
diff --git a/tests/balloon.jpg b/tests/balloon.jpg
new file mode 100644
index 0000000..8860fb3
Binary files /dev/null and b/tests/balloon.jpg differ
diff --git a/tests/balltracking.py b/tests/balltracking.py
new file mode 100644
index 0000000..d47ea7c
--- /dev/null
+++ b/tests/balltracking.py
@@ -0,0 +1,99 @@
+# import the necessary packages
+from collections import deque
+import numpy as np
+import argparse
+import imutils
+import cv2
+import pygame
+
+pygame.init()
+ap = argparse.ArgumentParser()
+ap.add_argument("-b", "--buffer", type=int, default=64, help="max buffer size")
+args = vars(ap.parse_args())
+
+# define the lower and upper boundaries of the target color, then initialize the
+# list of tracked points
+#color_lowbound = (124, 58, 65)
+#r: (0, 77, 141) #y: (0, 148, 0)
+#color_upbound = (255, 189, 255) #(210, 199, 255) # (86, 255, 255)
+color_lowbound = (14, 56, 26) #(9, 129, 126)
+color_upbound = (245, 255, 231) #(28, 255, 182)
+
+pts = deque(maxlen=args["buffer"])
+
+camera = cv2.VideoCapture(0)
+
+while True:
+ # handling it
+ # for event in pygame.event.get():
+ # if event.type == OBJMOTION:
+ # #print(event.message)
+ # print(event.center)
+ # print(event.radius)
+ # else:
+ # pass
+ # grab the current frame
+ (grabbed, frame) = camera.read()
+ frame = imutils.resize(frame, width=600)
+ # blurred = cv2.GaussianBlur(frame, (11, 11), 0)
+
+ # construct a mask for the color, then perform a series of dilations and erosions
+ # to remove any small blobs left in the mask
+ mask = cv2.inRange(frame, color_lowbound, color_upbound)
+ mask = cv2.erode(mask, None, iterations=2)
+ mask = cv2.dilate(mask, None, iterations=2)
+
+ # find contours in the mask and initialize the current
+ # (x, y) center of the ball
+ cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
+ cv2.CHAIN_APPROX_SIMPLE)[-2]
+ center = None
+
+ # only proceed if at least one contour was found
+ if len(cnts) > 0:
+ # find the largest contour in the mask, then use
+ # it to compute the minimum enclosing circle and
+ # centroid
+ c = max(cnts, key=cv2.contourArea)
+ ((x, y), radius) = cv2.minEnclosingCircle(c)
+ M = cv2.moments(c)
+ center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
+
+ # only proceed if the radius meets a minimum size
+ if radius > 10 and radius < 150:
+ # draw the circle and centroid on the frame,
+ # then update the list of tracked points
+ print(radius)
+ cv2.circle(frame, (int(x), int(y)), int(radius),
+ (0, 255, 255), 2)
+ cv2.circle(frame, center, 5, (0, 0, 255), -1)
+ OBJMOTION = pygame.USEREVENT+1
+ my_event = pygame.event.Event(OBJMOTION, message="Object detected!", center = center, radius = radius)
+ pygame.event.post(my_event)
+
+
+ # update the points queue
+ pts.appendleft(center)
+
+ # loop over the set of tracked points
+ for i in range(1, len(pts)):
+ # if either of the tracked points are None, ignore them
+ if pts[i - 1] is None or pts[i] is None:
+ continue
+
+ # otherwise, compute the thickness of the line and
+ # draw the connecting lines
+ #thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5)
+ #cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
+
+ # show the frame to our screen
+ cv2.imshow("Frame", frame)
+ key = cv2.waitKey(1) & 0xFF
+
+ # if the 'q' key is pressed, stop the loop
+ if key == ord("q"):
+ break
+
+# cleanup the camera and close any open windows
+camera.release()
+cv2.destroyAllWindows()
diff --git a/tests/collisiontest.py b/tests/collisiontest.py
new file mode 100644
index 0000000..73b057c
--- /dev/null
+++ b/tests/collisiontest.py
@@ -0,0 +1,30 @@
+import pygame
+
+x = y = 0
+running = 1
+screen = pygame.display.set_mode((600, 400))
+pygame.mouse.set_visible(False)
+
+fox_image = pygame.image.load("sword.png")
+tree_image = pygame.image.load("balloon.jpg")
+
+while True:
+ screen.fill((0,0,0))
+
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ running = 0
+ elif event.type == pygame.MOUSEMOTION:
+ x, y = event.pos
+
+ fox_rect = pygame.Rect(x, y, 100, 200)
+ tree_rect = pygame.Rect(300, 200, 100, 100)
+
+ screen.blit(fox_image, fox_rect)
+ screen.blit(tree_image, tree_rect)
+ pygame.display.flip()
+
+
+
+ if fox_rect.colliderect(tree_rect):
+ print("COLLIDE")
diff --git a/tests/colorpicker.py b/tests/colorpicker.py
new file mode 100644
index 0000000..00fce9a
--- /dev/null
+++ b/tests/colorpicker.py
@@ -0,0 +1,66 @@
+import cv2, imutils
+import numpy as np
+from matplotlib import pyplot as plt
+
+def nothing():
+ pass
+def main():
+
+ window_name='color range parameter'
+ cv2.namedWindow(window_name)
+ # Create a black image, a window
+ #im = cv2.imread('carmex2.PNG')
+ #hsv = cv2.cvtColor(im,cv2.COLOR_BGR2HSV)
+
+ print ('lower_color = np.array([a1,a2,a3])')
+ print ('upper_color = np.array([b1,b2,b3])')
+
+
+ # create trackbars for color change
+ cv2.createTrackbar('a1',window_name,0,255,nothing)
+ cv2.createTrackbar('a2',window_name,0,255,nothing)
+ cv2.createTrackbar('a3',window_name,0,255,nothing)
+
+ cv2.createTrackbar('b1',window_name,150,255,nothing)
+ cv2.createTrackbar('b2',window_name,150,255,nothing)
+ cv2.createTrackbar('b3',window_name,150,255,nothing)
+
+ while(1):
+ (t, im) = cv2.VideoCapture(0).read()
+ im = imutils.resize(im, width=600)
+ hsv = cv2.cvtColor(im,cv2.COLOR_BGR2HSV)
+
+
+ a1 = cv2.getTrackbarPos('a1',window_name)
+ a2 = cv2.getTrackbarPos('a2',window_name)
+ a3 = cv2.getTrackbarPos('a3',window_name)
+
+ b1 = cv2.getTrackbarPos('b1',window_name)
+ b2 = cv2.getTrackbarPos('b2',window_name)
+ b3 = cv2.getTrackbarPos('b3',window_name)
+
+ # hsv hue sat value
+ lower_color = np.array([a1,a2,a3])
+ upper_color = np.array([b1,b2,b3])
+ mask = cv2.inRange(hsv, lower_color, upper_color)
+ res = cv2.bitwise_and(im, im, mask = mask)
+
+ cv2.imshow('mask',mask)
+ cv2.imshow('res',res)
+ cv2.imshow('im',im)
+
+ k = cv2.waitKey(1) & 0xFF
+ if k == 27: # wait for ESC key to exit
+ break
+ elif k == ord('s'): # wait for 's' key to save and exit
+ cv2.imwrite('Img_screen_mask.jpg',mask)
+ cv2.imwrite('Img_screen_res.jpg',res)
+ break
+
+
+ cv2.destroyAllWindows()
+
+
+#Run Main
+if __name__ == "__main__" :
+ main()
diff --git a/tests/fullgame.py b/tests/fullgame.py
new file mode 100644
index 0000000..14e9dfc
--- /dev/null
+++ b/tests/fullgame.py
@@ -0,0 +1,77 @@
+import random, pygame, sys
+from pygame.locals import *
+from fruits import Apple, Sword
+
+# R G B
+gray = (100, 100, 100)
+navyblue = ( 60, 60, 100)
+white = (255, 255, 255)
+red = (255, 0, 0)
+green = ( 0, 255, 0)
+blue = ( 0, 0, 255)
+yellow = (255, 255, 0)
+orange = (255, 128, 0)
+purple = (255, 0, 255)
+cyan = ( 0, 255, 255)
+black = ( 0, 0, 0)
+
+def main():
+ pygame.init()
+ screen = pygame.display.set_mode((400, 400))
+ pygame.display.set_caption('Fruit Ninja')
+ fruits = generate_fruit(screen, 3)
+ pygame.mouse.set_visible(False)
+ sword = Sword(0,0,screen)
+
+ while True:
+ screen.fill(black)
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()
+ elif event.type == pygame.MOUSEMOTION:
+ x, y = event.pos
+
+ # move sword to mouse position
+ sword.move(x,y)
+ sword.draw()
+
+ for a in fruits:
+ a.draw()
+ if a.checkCollision(sword):
+ print("COLLIDE")
+ fruits.remove(a)
+
+ pygame.display.update()
+
+def generate_fruit(screen, n):
+ positions = []
+ radii = []
+ colors = []
+ fruits = []
+
+ start_x = random.sample(range(20, 370), n)
+ start_y = random.sample(range(20, 370), n)
+
+ for b in range(0, n):
+ positions.append((start_x[b], start_y[b]))
+
+ for i in range(0, n):
+ radii.append(random.randint(8, 20))
+
+ set_colors = [red, green, gray]
+ for j in range(0,n):
+ c = random.choice(set_colors)
+ colors.append(c)
+
+ for a in range(0,n):
+ temp_apple = Apple(radii[a], 1, positions[a], screen, colors[a])
+ print(radii[a])
+ print(positions[a])
+ print(colors[a])
+ fruits.append(temp_apple)
+
+ return fruits
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/handtracking.py b/tests/handtracking.py
new file mode 100644
index 0000000..6ad78fe
--- /dev/null
+++ b/tests/handtracking.py
@@ -0,0 +1,141 @@
+import cv2
+import numpy as np
+import copy
+import math
+import imutils
+#from appscript import app
+
+# parameters
+cap_region_x_begin=0.3 # start point/total width
+cap_region_y_end=0.9 # start point/total width
+threshold = 60 # BINARY threshold
+blurValue = 41 # GaussianBlur parameter
+bgSubThreshold = 50
+
+# variables
+isBgCaptured = 0 # bool, whether the background captured
+triggerSwitch = False # if true, keyborad simulator works
+
+def printThreshold(thr):
+ print("! Changed threshold to "+str(thr))
+
+
+def removeBG(frame):
+ fgmask = bgModel.apply(frame)
+ # kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
+ # res = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)
+
+ kernel = np.ones((3, 3), np.uint8)
+ fgmask = cv2.erode(fgmask, kernel, iterations=1)
+ res = cv2.bitwise_and(frame, frame, mask=fgmask)
+ return res
+
+
+# def calculateFingers(res,drawing): # -> finished bool, cnt: finger count
+# # convexity defect
+# hull = cv2.convexHull(res, returnPoints=False)
+# if len(hull) > 3:
+# defects = cv2.convexityDefects(res, hull)
+# if type(defects) != type(None): # avoid crashing. (BUG not found)
+#
+# cnt = 0
+# for i in range(defects.shape[0]): # calculate the angle
+# s, e, f, d = defects[i][0]
+# start = tuple(res[s][0])
+# end = tuple(res[e][0])
+# far = tuple(res[f][0])
+# a = math.sqrt((end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2)
+# b = math.sqrt((far[0] - start[0]) ** 2 + (far[1] - start[1]) ** 2)
+# c = math.sqrt((end[0] - far[0]) ** 2 + (end[1] - far[1]) ** 2)
+# angle = math.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)) # cosine theorem
+# if angle <= math.pi / 2: # angle less than 90 degree, treat as fingers
+# cnt += 1
+# cv2.circle(drawing, far, 8, [211, 84, 0], -1)
+# return True, cnt
+# return False, 0
+
+
+# Camera
+camera = cv2.VideoCapture(0)
+camera.set(10,200)
+cv2.namedWindow('trackbar')
+cv2.createTrackbar('trh1', 'trackbar', threshold, 100, printThreshold)
+
+
+while camera.isOpened():
+ ret, frame = camera.read()
+ frame = imutils.resize(frame, width=1000)
+ threshold = cv2.getTrackbarPos('trh1', 'trackbar')
+ frame = cv2.bilateralFilter(frame, 5, 50, 100) # smoothing filter
+ frame = cv2.flip(frame, 1) # flip the frame horizontally
+ cv2.rectangle(frame, (int(cap_region_x_begin * frame.shape[1]), 0),
+ (frame.shape[1], int(cap_region_y_end * frame.shape[0])), (255, 0, 0), 2)
+ cv2.imshow('original', frame)
+
+ # Main operation
+ if isBgCaptured == 1: # this part wont run until background captured
+ img = removeBG(frame)
+ img = img[0:int(cap_region_y_end * frame.shape[0]),
+ int(cap_region_x_begin * frame.shape[1]):frame.shape[1]] # clip the ROI
+ #cv2.imshow('mask', img)
+
+ # convert the image into binary image
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+ blur = cv2.GaussianBlur(gray, (blurValue, blurValue), 0)
+ #cv2.imshow('blur', blur)
+ ret, thresh = cv2.threshold(blur, threshold, 255, cv2.THRESH_BINARY)
+ cv2.imshow('ori', thresh)
+
+
+ # get the coutours
+ thresh1 = copy.deepcopy(thresh)
+ _, contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
+ length = len(contours)
+ maxArea = -1
+ if length > 0:
+ for i in range(length): # find the biggest contour (according to area)
+ temp = contours[i]
+ area = cv2.contourArea(temp)
+ if area > maxArea:
+ maxArea = area
+ ci = i
+
+ res = contours[ci]
+ hull = cv2.convexHull(res)
+ drawing = np.zeros(img.shape, np.uint8)
+ #cv2.drawContours(drawing, [res], 0, (0, 255, 0), 2)
+ #cv2.drawContours(drawing, [hull], 0, (0, 0, 255), 3)
+
+ M = cv2.moments(res)
+ center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
+ cv2.circle(drawing, center, 8, [100, 100, 100], -1)
+
+ #isFinishCal,cnt = calculateFingers(res,drawing)
+
+ cv2.imshow('output', drawing)
+
+ # Keyboard OP
+ k = cv2.waitKey(10)
+ if k == 27: # press ESC to exit
+ break
+
+
+ elif k == ord('b'): # press 'b' to capture the background
+ bgModel = cv2.createBackgroundSubtractorMOG2(0, bgSubThreshold)
+ isBgCaptured = 1
+ print('!!!Background Captured!!!')
+ elif k == ord('r'): # press 'r' to reset the background
+ bgModel = None
+ triggerSwitch = False
+ isBgCaptured = 0
+ print('!!!Reset BackGround!!!')
+ elif k == ord('n'):
+ triggerSwitch = True
+ print('!!!Trigger On!!!')
+
+ k = cv2.waitKey(10)
+ if k == 27: # press ESC to exit
+ break
+
+camera.release()
+cv2.destroyAllWindows()
diff --git a/tests/mouse_tracker.py b/tests/mouse_tracker.py
new file mode 100644
index 0000000..e4ef97a
--- /dev/null
+++ b/tests/mouse_tracker.py
@@ -0,0 +1,15 @@
+import pygame
+
+x = y = 0
+running = 1
+screen = pygame.display.set_mode((640, 400))
+
+while running:
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ running = 0
+ elif event.type == pygame.MOUSEMOTION:
+ print ("mouse at (%d, %d)" % event.pos)
+
+ screen.fill((0, 0, 0))
+ pygame.display.flip()
diff --git a/tests/ninja_oldv.py b/tests/ninja_oldv.py
new file mode 100644
index 0000000..c886559
--- /dev/null
+++ b/tests/ninja_oldv.py
@@ -0,0 +1,105 @@
+# FRUIT NINJA #
+# AVA LAKMAZAHERI AND EMMA WESTERHOFF #
+# SOFTWARE DESIGN FALL 2017 #
+
+import random, pygame, sys
+from pygame.locals import *
+#from fruits import *
+from all_fruits import *
+from Scoring import *
+import inspect
+
+# R G B
+gray = (100, 100, 100)
+black = ( 0, 0, 0)
+navyblue = ( 60, 60, 100)
+white = (255, 255, 255)
+red = (255, 0, 0)
+green = ( 0, 255, 0)
+blue = ( 0, 0, 255)
+yellow = (255, 255, 0)
+orange = (255, 128, 0)
+purple = (255, 0, 255)
+cyan = ( 0, 255, 255)
+
+def main():
+ pygame.init()
+ screen_width = 800
+ screen_height = 500
+ screen = pygame.display.set_mode((screen_width, screen_height))
+ clock = pygame.time.Clock()
+ scoreboard = Scoreboard(screen)
+ pygame.display.set_caption('Fruit Ninja')
+ fruits = [generate_fruit(screen)]
+ fruit_parts = []
+ pygame.mouse.set_visible(False)
+ sword = Sword(0,0,screen)
+
+ while True:
+ time_passed = clock.tick(30)
+ screen.fill(black)
+
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()
+ elif event.type == pygame.MOUSEMOTION:
+ x,y = event.pos
+
+ sword.move(x,y)
+ sword.draw()
+
+ if len(fruits) == 0:
+ fruits.append(generate_fruit(screen))
+
+ for a in fruits:
+ a.toss(time_passed)
+ #a.projectile(time_passed)
+ a.move(a.x, a.y)
+ a.draw()
+ if a.checkCollision(sword):
+ print("COLLIDE")
+ scoreboard.fruit_sliced +=1
+ halves = half_fruit(screen, a)
+ for half in halves:
+ fruit_parts.append(half)
+ print(fruit_parts)
+ fruits.remove(a)
+ elif a.y > (screen_height+a.image.get_width()):
+ print('missed')
+ print(scoreboard.fruit_missed)
+ scoreboard.fruit_missed +=1
+ fruits.remove(a)
+
+ for h in fruit_parts:
+ h.fall(time_passed)
+ h.move(h.x, h.y)
+ h.draw()
+ if h.y > (screen_height+h.image.get_width()):
+ fruit_parts.remove(h)
+
+ scoreboard.show()
+ pygame.display.update()
+
+def generate_fruit(screen):
+ n = random.randint(1,3)
+ if n == 1:
+ return Apple(screen)
+ if n == 2:
+ return Banana(screen)
+ else:
+ return Strawberry(screen)
+
+def half_fruit(screen, fruit):
+ halves = []
+
+ if isinstance(fruit, Apple):
+ halves = [Half_Apple1(screen, fruit.x, fruit.y), Half_Apple2(screen, fruit.x, fruit.y)]
+ elif isinstance(fruit, Banana):
+ halves = [Half_Banana1(screen, fruit.x, fruit.y), Half_Banana2(screen, fruit.x, fruit.y)]
+ elif isinstance(fruit, Strawberry):
+ halves = [Half_Strawberry1(screen, fruit.x, fruit.y), Half_Strawberry2(screen, fruit.x, fruit.y)]
+ return halves
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/sprite_exp1 b/tests/sprite_exp1
new file mode 100644
index 0000000..73b057c
--- /dev/null
+++ b/tests/sprite_exp1
@@ -0,0 +1,30 @@
+import pygame
+
+x = y = 0
+running = 1
+screen = pygame.display.set_mode((600, 400))
+pygame.mouse.set_visible(False)
+
+fox_image = pygame.image.load("sword.png")
+tree_image = pygame.image.load("balloon.jpg")
+
+while True:
+ screen.fill((0,0,0))
+
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ running = 0
+ elif event.type == pygame.MOUSEMOTION:
+ x, y = event.pos
+
+ fox_rect = pygame.Rect(x, y, 100, 200)
+ tree_rect = pygame.Rect(300, 200, 100, 100)
+
+ screen.blit(fox_image, fox_rect)
+ screen.blit(tree_image, tree_rect)
+ pygame.display.flip()
+
+
+
+ if fox_rect.colliderect(tree_rect):
+ print("COLLIDE")
diff --git a/tests/sprite_exp1.py b/tests/sprite_exp1.py
new file mode 100644
index 0000000..75d9c45
--- /dev/null
+++ b/tests/sprite_exp1.py
@@ -0,0 +1,29 @@
+import pygame, sys
+from fruits import Apple, Sword
+
+bgcolor = 255, 255, 255
+running = 1
+x = y = 0
+screen = pygame.display.set_mode((600, 400))
+pygame.mouse.set_visible(False)
+
+sword = Sword(x,y,screen)
+myfruit = Apple(25, 0, (300, 200), screen, (255,0,0))
+
+while True:
+ screen.fill((0,0,0))
+
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ sys.exit()
+ elif event.type == pygame.MOUSEMOTION:
+ x, y = event.pos
+
+ sword.move(x,y)
+ sword.draw()
+ myfruit.draw()
+
+ if myfruit.checkCollision(sword):
+ myfruit.remove()
+ print("COLLIDE")
+ pygame.display.flip()
diff --git a/tests/spritetest.py b/tests/spritetest.py
new file mode 100644
index 0000000..47a5bff
--- /dev/null
+++ b/tests/spritetest.py
@@ -0,0 +1,30 @@
+
+import os
+import sys
+import math
+import pygame
+import pygame.mixer
+from pygame.locals import *
+
+class Balloon(pygame.sprite.Sprite):
+ def __init__(self):
+ pygame.sprite.Sprite.__init__(self) #call Sprite initializer
+ self.image = pygame.image.load("balloon.jpg")
+ self.rect = self.image.get_rect()
+ self.mask = pygame.mask.from_surface(self.image)
+
+width = 500
+height = 300
+pygame.init()
+pygame.display.set_mode((width, height))
+
+b1 = Balloon()
+b2 = Balloon()
+
+
+while True:
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ running = 0
+ elif pygame.sprite.spritecollide(b1, b2, False, pygame.sprite.collide_mask):
+ print("sprites have collided!")
diff --git a/tests/test.py b/tests/test.py
new file mode 100644
index 0000000..19a1e99
--- /dev/null
+++ b/tests/test.py
@@ -0,0 +1,22 @@
+import os
+import sys
+import math
+import pygame
+import pygame.mixer
+from pygame.locals import *
+
+width = 500
+height = 300
+pygame.init()
+pygame.display.set_mode((width, height))
+
+
+while True:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ sys.exit()
+ if event.type == pygame.MOUSEBUTTONDOWN:
+ # Set the x, y postions of the mouse click
+ x, y = event.pos
+ if ball.get_rect().collidepoint(x, y):
+ print("bam")
diff --git a/tests/test2.py b/tests/test2.py
new file mode 100644
index 0000000..50ce686
--- /dev/null
+++ b/tests/test2.py
@@ -0,0 +1,30 @@
+import pygame
+
+linecolor = 0, 0, 0
+bgcolor = 255, 255, 255
+x = y = 0
+running = 1
+screen = pygame.display.set_mode((600, 400))
+pygame.mouse.set_visible(False)
+
+sword = pygame.image.load("sword.png")
+#sword2 = pygame.transform.scale(screen, (100, 200))
+
+
+while running:
+ screen.fill(bgcolor)
+
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT:
+ running = 0
+ elif event.type == pygame.MOUSEMOTION:
+ x, y = event.pos
+ #sword = pygame.draw.rect(screen, linecolor, [[x, y], [x+100, y],[x, y+10]], 2)
+ #
+ fruit = pygame.draw.circle(screen, (255,0,0), (320, 200), 10, 5)
+ print(x, ", " , y)
+ if sword.get_rect().collidepoint(320,200):
+ print("bam")
+
+ screen.blit(sword, (x,y))
+ pygame.display.flip()
diff --git a/uml_diagram.png b/uml_diagram.png
new file mode 100644
index 0000000..0890641
Binary files /dev/null and b/uml_diagram.png differ