need to create a second snake
This commit is contained in:
3
HW1/.idea/.gitignore
generated
vendored
Normal file
3
HW1/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
||||||
13
HW1/.idea/HW1.iml
generated
Normal file
13
HW1/.idea/HW1.iml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
<component name="TestRunnerService">
|
||||||
|
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
5
HW1/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
5
HW1/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="PROJECT_PROFILE" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
HW1/.idea/misc.xml
generated
Normal file
7
HW1/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
HW1/.idea/modules.xml
generated
Normal file
8
HW1/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/HW1.iml" filepath="$PROJECT_DIR$/.idea/HW1.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
HW1/.idea/vcs.xml
generated
Normal file
6
HW1/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
18
HW1/wormy.py
18
HW1/wormy.py
@@ -40,7 +40,7 @@ def main():
|
|||||||
FPSCLOCK = pygame.time.Clock()
|
FPSCLOCK = pygame.time.Clock()
|
||||||
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
|
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
|
||||||
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
|
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
|
||||||
pygame.display.set_caption('Wormy')
|
pygame.display.set_caption('Snakes')
|
||||||
|
|
||||||
showStartScreen()
|
showStartScreen()
|
||||||
while True:
|
while True:
|
||||||
@@ -55,10 +55,14 @@ def runGame():
|
|||||||
wormCoords = [{'x': startx, 'y': starty},
|
wormCoords = [{'x': startx, 'y': starty},
|
||||||
{'x': startx - 1, 'y': starty},
|
{'x': startx - 1, 'y': starty},
|
||||||
{'x': startx - 2, 'y': starty}]
|
{'x': startx - 2, 'y': starty}]
|
||||||
|
|
||||||
|
|
||||||
direction = RIGHT
|
direction = RIGHT
|
||||||
|
|
||||||
# Start the apple in a random place.
|
# Start the apple in a random place.
|
||||||
apple = getRandomLocation()
|
apple = getRandomLocation()
|
||||||
|
apple2 = getRandomLocation()
|
||||||
|
apple3 = getRandomLocation()
|
||||||
|
|
||||||
while True: # main game loop
|
while True: # main game loop
|
||||||
for event in pygame.event.get(): # event handling loop
|
for event in pygame.event.get(): # event handling loop
|
||||||
@@ -87,6 +91,12 @@ def runGame():
|
|||||||
if wormCoords[HEAD]['x'] == apple['x'] and wormCoords[HEAD]['y'] == apple['y']:
|
if wormCoords[HEAD]['x'] == apple['x'] and wormCoords[HEAD]['y'] == apple['y']:
|
||||||
# don't remove worm's tail segment
|
# don't remove worm's tail segment
|
||||||
apple = getRandomLocation() # set a new apple somewhere
|
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:
|
else:
|
||||||
del wormCoords[-1] # remove worm's tail segment
|
del wormCoords[-1] # remove worm's tail segment
|
||||||
|
|
||||||
@@ -104,6 +114,8 @@ def runGame():
|
|||||||
drawGrid()
|
drawGrid()
|
||||||
drawWorm(wormCoords)
|
drawWorm(wormCoords)
|
||||||
drawApple(apple)
|
drawApple(apple)
|
||||||
|
drawApple(apple2)
|
||||||
|
drawApple(apple3)
|
||||||
drawScore(len(wormCoords) - 3)
|
drawScore(len(wormCoords) - 3)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
FPSCLOCK.tick(FPS)
|
FPSCLOCK.tick(FPS)
|
||||||
@@ -129,8 +141,8 @@ def checkForKeyPress():
|
|||||||
|
|
||||||
def showStartScreen():
|
def showStartScreen():
|
||||||
titleFont = pygame.font.Font('freesansbold.ttf', 100)
|
titleFont = pygame.font.Font('freesansbold.ttf', 100)
|
||||||
titleSurf1 = titleFont.render('USU', True, WHITE, DARKGREEN)
|
titleSurf1 = titleFont.render('Snakes', True, DARKGRAY, YELLOW)
|
||||||
titleSurf2 = titleFont.render('Agents', True, GREEN)
|
titleSurf2 = titleFont.render('Snakes', True, WHITE)
|
||||||
|
|
||||||
degrees1 = 0
|
degrees1 = 0
|
||||||
degrees2 = 0
|
degrees2 = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user