From d2ad045b82f67a2a69e2d0544a6d9f4eb9bd0b2a Mon Sep 17 00:00:00 2001 From: bbod Date: Tue, 21 Jan 2020 12:03:01 -0700 Subject: [PATCH] need to create a second snake --- HW1/.idea/.gitignore | 3 +++ HW1/.idea/HW1.iml | 13 ++++++++++++ .../inspectionProfiles/profiles_settings.xml | 5 +++++ HW1/.idea/misc.xml | 7 +++++++ HW1/.idea/modules.xml | 8 ++++++++ HW1/.idea/vcs.xml | 6 ++++++ HW1/wormy.py | 20 +++++++++++++++---- 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 HW1/.idea/.gitignore create mode 100644 HW1/.idea/HW1.iml create mode 100644 HW1/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 HW1/.idea/misc.xml create mode 100644 HW1/.idea/modules.xml create mode 100644 HW1/.idea/vcs.xml diff --git a/HW1/.idea/.gitignore b/HW1/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/HW1/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/HW1/.idea/HW1.iml b/HW1/.idea/HW1.iml new file mode 100644 index 0000000..fa80a76 --- /dev/null +++ b/HW1/.idea/HW1.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/HW1/.idea/inspectionProfiles/profiles_settings.xml b/HW1/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..0eefe32 --- /dev/null +++ b/HW1/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/HW1/.idea/misc.xml b/HW1/.idea/misc.xml new file mode 100644 index 0000000..8656114 --- /dev/null +++ b/HW1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/HW1/.idea/modules.xml b/HW1/.idea/modules.xml new file mode 100644 index 0000000..e304951 --- /dev/null +++ b/HW1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HW1/.idea/vcs.xml b/HW1/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/HW1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HW1/wormy.py b/HW1/wormy.py index 61b1f57..ae34431 100644 --- a/HW1/wormy.py +++ b/HW1/wormy.py @@ -40,7 +40,7 @@ def main(): FPSCLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) BASICFONT = pygame.font.Font('freesansbold.ttf', 18) - pygame.display.set_caption('Wormy') + pygame.display.set_caption('Snakes') showStartScreen() while True: @@ -55,10 +55,14 @@ def runGame(): wormCoords = [{'x': startx, 'y': starty}, {'x': startx - 1, 'y': starty}, {'x': startx - 2, 'y': starty}] + + direction = RIGHT # Start the apple in a random place. apple = getRandomLocation() + apple2 = getRandomLocation() + apple3 = getRandomLocation() while True: # main game loop for event in pygame.event.get(): # event handling loop @@ -87,8 +91,14 @@ def runGame(): if wormCoords[HEAD]['x'] == apple['x'] and wormCoords[HEAD]['y'] == apple['y']: # don't remove worm's tail segment apple = getRandomLocation() # set a new apple somewhere + elif wormCoords[HEAD]['x'] == apple2['x'] and wormCoords[HEAD]['y'] == apple2['y']: + # don't remove worm's tail segment + apple2 = getRandomLocation() # set a new apple somewhere + elif wormCoords[HEAD]['x'] == apple3['x'] and wormCoords[HEAD]['y'] == apple3['y']: + # don't remove worm's tail segment + apple3 = getRandomLocation() # set a new apple somewhere else: - del wormCoords[-1] # remove worm's tail segment + del wormCoords[-1] # remove worm's tail segment # move the worm by adding a segment in the direction it is moving if direction == UP: @@ -104,6 +114,8 @@ def runGame(): drawGrid() drawWorm(wormCoords) drawApple(apple) + drawApple(apple2) + drawApple(apple3) drawScore(len(wormCoords) - 3) pygame.display.update() FPSCLOCK.tick(FPS) @@ -129,8 +141,8 @@ def checkForKeyPress(): def showStartScreen(): titleFont = pygame.font.Font('freesansbold.ttf', 100) - titleSurf1 = titleFont.render('USU', True, WHITE, DARKGREEN) - titleSurf2 = titleFont.render('Agents', True, GREEN) + titleSurf1 = titleFont.render('Snakes', True, DARKGRAY, YELLOW) + titleSurf2 = titleFont.render('Snakes', True, WHITE) degrees1 = 0 degrees2 = 0