def isMouthOpen(facePoints): # determing if the mouthis open or not. # will calculate average distance between top and bottom poitns of mouth # if the ratio is closer to 0, then mouth is closed # if not, then mouth is open # print(facePoints) leftCorner = facePoints[60] rightCorner = facePoints[64] horizontalDistance = mat.distance(leftCorner[0], leftCorner[1], rightCorner[0], rightCorner[1]) # dictionary -- maps each point to point right across from it. # only looks at bottom part of upper lip pointsAcross = {61: 67, 62: 66, 63: 65} average = 0 for key, val in pointsAcross.items(): point1 = facePoints[key] # print("Val", val) point2 = facePoints[val] # calculates distance between 2 points distance = mat.distance(point1[0], point1[1], point2[0], point2[1]) average += distance average /= len(pointsAcross) ratio = average / horizontalDistance if ratio < MouthCircle.MOUTH_OPEN_MIN_RATIO: return False else: return True
def isFruitInMouth(facePoints, fruit, isMouthOpen): print("This method is at least being called") # sys.exit(0) # determines if a fruit has collided with the user's mouth # basically, i want to check if the center of the fruit is within the # bounding rectangle of the person's open mouth. But first and foremost # it needs to ensure that the mouth is open, so we will start with that. # isMouthOpen = MouthCircle.isMouthOpen(facePoints) # if the mouth is not open, then there are no collissions possible print("is mouth open", isMouthOpen) # time.sleep(0.01) if not isMouthOpen: return False else: # getting bounding box of open mouth region # starting point will be the point at the 61st index # ending point will the point at the 65th index # startX = facePoints[49][0] # startY = facePoints[49][1] # endX = facePoints[55][0] # endY = facePoints[55][1] # print("testing the starting and ending values", startX, startY, endX, endY); time.sleep(1) # rect = Rectangle(startX, startY, endX, endY) # # creates a rectangle # # if the point is in the rectangle, then return True # # otherwise, return false # if rect.pointInRectangle(fruit.x, fruit.y): # return True # else: # return False # going to create a circle around the mouth and hopefully that # will work # create a circle with diamter left most point to the right most point # top left corner is # y-value of 50, xvalue of 48, diamater of 48-54 print("GETING TO THE ELSE") # THIS PART IS WHERE IT F***S UP x = facePoints[48][ 0] * 4 # blowing it up by the scale factor! I think this will work... y = facePoints[50][1] * 4 # same deal print("x", x, "y", y) radius = mat.distance(facePoints[48][0] * 4, facePoints[48][1] * 4, facePoints[54][0] * 4, facePoints[54][1] * 4) / 2 centerX = x + radius - 30 centerY = y + radius - 50 print("radius", radius, "distance", mat.distance(fruit.x, fruit.y, centerX, centerY)) if mat.distance(fruit.x, fruit.y, centerX, centerY) <= radius * 1.5: return True else: return False
def test_distance_with_test_data(self, x1, y1, x2, y2, expected): dist = distance(x1, y1, x2, y2) assert isclose(dist, expected)
def playGameTimerFired(data): if data.gameMode == "classic": # with lives and shit classic game mode here if data.lives < 0: data.mode = "gameOver" pass elif data.gameMode == "timeTrial": data.timesFired += 1 # print(data.milliElapsed) if data.timesFired == 50: if data.timeLeft > 0: data.timeLeft -= 1 data.timesFired = 0 else: data.mode = "gameOver" # making items fall w/gravity for fruit in data.fruits: # updates the positions of all the fruits in the list dvy = data.g * data.dt fruit.vy += dvy dy = fruit.vy * data.dt dx = fruit.vx * data.dt # sys.exit(0) print("f**k me") # sys.exit(0) fruit.y += dy fruit.x += dx # sys.exit(0) # for now do the collission for fruitInd in range(len(data.fruits)): fruit if fruitInd in range(len(data.fruits)): fruit = data.fruits[fruitInd] if fruit.y > data.height and fruit.vy > 0: # dealing with separate cases if the fruit falls during time trial # and classic modes if data.gameMode == "timeTrial": data.score -= 3 elif data.gameMode == "classic": if (fruit.color != "green" and fruit.color != data.colors["green"] and fruit.color != "red" and fruit.color != data.colors["red"]): data.lives -= 1 if fruit in data.fruits: data.fruits.pop(data.fruits.index(fruit)) if fruit.x <= 0: # data.score -= 3 # data.fruits.pop(data.fruits.index(fruit)) fruit.vx = -fruit.vx if fruit.x + 2 * fruit.radius >= data.width: # data.score -= 3 # data.fruits.pop(data.fruits.index(fruit)) fruit.vx = -fruit.vx else: for i in range(fruitInd + 1, len(data.fruits)): fruit2 = data.fruits[i] if (mat.distance(fruit.x, fruit.y, fruit2.x, fruit2.y) <= fruit.radius * 2): doCollision(fruit, fruit2, data) # after this many milliseconds, create another fruit if data.timeBeforeNextFruit <= 0: # randomly picking a color and item data.fruits.append( Fruit("apple", color=data.colors[random.choice(list(data.colors))])) # randomly creates the next location of when it should go up data.timeBeforeNextFruit = random.randint( 0, data.levelFruitFrequency[data.level]) print("time before next fruit", data.timeBeforeNextFruit) data.timeBeforeNextFruit -= 10 getAndDrawCameraFeed(data) checkIfInMouth(data) # creating the text for the score print(data.fruits)
def test_distance_on_exceptions(self, x1, y1, x2, y2, error_type): with pytest.raises(error_type): distance(x1, y1, x2, y2)