Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8782484
made some files
sammyers Mar 3, 2016
631474e
made grid, square snake
sammyers Mar 3, 2016
0f801b0
cleaned up
sammyers Mar 3, 2016
d093040
snake moves now
sammyers Mar 6, 2016
2bf0583
changed food
sammyers Mar 6, 2016
9cf31db
2D Snake now operational
sammyers Mar 6, 2016
b05fde2
minor tweaks
sammyers Mar 6, 2016
83c4399
making sure this is up to date
sammyers Mar 7, 2016
d06f65e
End game splash. Resized window to display score, implement two types…
MatthewBeaudouinLafon Mar 8, 2016
27d21a4
Modified Score to display as a percentage of the screen. R and Q map …
MatthewBeaudouinLafon Mar 9, 2016
df07f06
Added 'Play again' and 'Quit' indicators on death screen
MatthewBeaudouinLafon Mar 10, 2016
c88fa7c
3D working (basically)
sammyers Mar 10, 2016
dd84498
Merge branch 'master' into Matt-EndGameScreen
sammyers Mar 10, 2016
e8a4e4a
merged
sammyers Mar 10, 2016
c298f1a
merged
sammyers Mar 10, 2016
8e471c0
Merge pull request #1 from sammyers/Matt-EndGameScreen
sammyers Mar 10, 2016
59c20d0
Added basic wall generation. Parameters unclear to properly populate …
MatthewBeaudouinLafon Mar 10, 2016
f1e0394
working on overlay
sammyers Mar 10, 2016
dd29c2c
Merge branch 'master' of https://github.com/sammyers/InteractiveProgr…
sammyers Mar 10, 2016
ae84e28
Added various levels of wall generation (blob is probably the best). …
MatthewBeaudouinLafon Mar 10, 2016
d03790e
did some documentation
sammyers Mar 10, 2016
aa063e5
Merge branch 'master' of https://github.com/sammyers/InteractiveProgr…
sammyers Mar 10, 2016
f57a0f1
merged documentation
sammyers Mar 10, 2016
143ff1d
split files
sammyers Mar 10, 2016
d05114e
fixed 3D wall collision
MatthewBeaudouinLafon Mar 10, 2016
df1a141
Merge branch 'master' of https://github.com/sammyers/InteractiveProgr…
MatthewBeaudouinLafon Mar 10, 2016
8b4c8c7
made generic block object
sammyers Mar 10, 2016
6526f1b
added writeup
sammyers Mar 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .game.py.swo
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*.swp
Binary file added InteractiveProgrammingWriteup.pdf
Binary file not shown.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# InteractiveProgramming
This is the base repo for the interactive programming project for Software Design, Spring 2016 at Olin College.
# SNAK3D
by Sam Myers and Matthew Beaudouin-Lafon for Software Design Spring 2016

To run this game, you need NumPy and PyGame installed.
Then just run game.py.

Use the arrow keys to move the snake around, and WASD to rotate the orientation of the cube.
53 changes: 53 additions & 0 deletions controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pygame
import numpy as np

class GameController(object):
"""
Manipulates the model according to user input.

Actions:
* Change direction of the snake
* Change orientation of the axes
* Quit or restart game after death
"""
def __init__(self, model):
self.model = model

def handle_event(self, event):
"""Respond to key presses, return boolean for whether to continue running the program"""
if event.type == pygame.QUIT:
return False

if event.type != pygame.KEYDOWN:
return True

if self.model.snake.dead:
if event.key == pygame.K_q:
# Quit
return False
elif event.key == pygame.K_r:
# Restart the game.
self.model.restart()
return True

old_direction = self.model.snake.direction

directions = ['up', 'left', 'down', 'right']

direction_keys = [pygame.K_UP, pygame.K_LEFT, pygame.K_DOWN, pygame.K_RIGHT]
control_dict = {key: value for key, value in zip(direction_keys, directions)}

orientation_keys = [pygame.K_w, pygame.K_a, pygame.K_s, pygame.K_d]
orient_dict = {key: value for key, value in zip(orientation_keys, directions)}

if event.key in direction_keys: #Change direction of the snake, decrease score by 1
self.model.snake.change_direction(control_dict[event.key])
if old_direction is not None and old_direction != self.model.snake.direction:
self.model.score2 -= 1

if event.key in orientation_keys: #Change orientation of the model, decrease score by 1
self.model.change_orientation(orient_dict[event.key])
if old_direction is not None:
self.model.score2 -= 1
return True

37 changes: 37 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pygame
from model import GameModel
from view import GameView
from controller import GameController
import time

square_width = 10 # pixels
grid_width = 51
pixels_wide = square_width * grid_width
ms_per_block = 2 # screen refreshes per move
score_font_size = 14

if __name__ == '__main__':
pygame.init()
size = (pixels_wide, int(pixels_wide*1.08) )# + score_font_size + 14)
screen = pygame.display.set_mode(size)

model = GameModel(grid_width)
view = GameView(model, screen, square_width)
controller = GameController(model)

running = True
count = 0
while running:
view.draw()
for event in pygame.event.get():
# if event.type == pygame.QUIT:
# running = False
running = controller.handle_event(event)
count += 1
if count == ms_per_block:
model.update_snake()
model.check_collision()
count = 0

time.sleep(.001)
pygame.QUIT
8 changes: 8 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def vector_add(*args):
i = sum([arg[0] for arg in args])
j = sum([arg[1] for arg in args])
k = sum([arg[2] for arg in args])
return (i, j, k)

def vector_multiply(scalar, vector):
return tuple([scalar * component for component in vector])
75 changes: 75 additions & 0 deletions linkedlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class Node(object):
def __init__(self, data=None, next_node=None):
self.data = data
self.next_node = next_node

def get_data(self):
return self.data

def get_next(self):
return self.next_node

def set_next(self, new_next):
self.next_node = new_next

class LinkedList(object):
def __init__(self, head=None):
self.head = head

def insert(self, data, index=0):
new_node = Node(data)
current = self.head
count = 0
while count < index:
count += 1
current = current.get_next()
new_node.set_next(current)
if index == 0:
self.head = new_node

def size(self):
current = self.head
count = 0
while current:
count += 1
current = current.get_next()
return count

def search(self, data):
current = self.head
found = False
while current and found is False:
if current.get_data() == data:
found = True
else:
current = current.get_next()
if current is None:
raise ValueError('Data not in list')
return current

def delete(self, data=None):
"""Deletes the node with specified data from the list.
If no data is specified, deletes the last element in the list"""
current = self.head
previous = None
found = False
while current and found is False:
if data is not None and current.get_data() == data:
found = True
elif data is None and current.get_next() is None:
found = True
else:
previous = current
current = current.get_next()
if current is None:
raise ValueError('Data not in list')
else:
previous.set_next(current.get_next())

def get_list(self):
current = self.head
unlinked = []
while current:
unlinked.append(current.data)
current = current.get_next()
return unlinked
Loading