Initial commit

This commit is contained in:
Sam Perry
2016-10-15 14:52:10 +01:00
commit 3d114b8a63
5 changed files with 291 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python
import subprocess
import os
import pdb
import fnmatch
import sys
def main():
p = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
out = out.strip('\n')
track_filepath = os.path.join(out, ".gittrack")
p = subprocess.Popen(["git", "ls-files", out, "--exclude-standard", "--others"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
out = out.splitlines()
try:
with open(track_filepath) as f:
content = f.read().splitlines()
except IOError:
return 0
untracked = []
for filepath in out:
for name in content:
if fnmatch.fnmatch(filepath, name):
untracked.append(filepath)
if untracked:
print "The following files are not tracked: "
for i in untracked:
print i
print "Please either stage these files for the commit or add them to the project's .gitignore to disregard them."
return 1
else:
return 0
if __name__ == "__main__":
exit(main())
+37
View File
@@ -0,0 +1,37 @@
.DS_Store
bin/
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Log files
*.log
external/
CMakeFiles/
+1
View File
@@ -0,0 +1 @@
*.pde
+41
View File
@@ -0,0 +1,41 @@
# Use this file to configure the Overcommit hooks you wish to use. This will
# extend the default configuration defined in:
# https://github.com/brigade/overcommit/blob/master/config/default.yml
#
# At the topmost level of this YAML file is a key representing type of hook
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
# customize each hook, such as whether to only run it on certain files (via
# `include`), whether to only display output if it fails (via `quiet`), etc.
#
# For a complete list of hooks, see:
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
#
# For a complete list of options that you can use to customize hooks, see:
# https://github.com/brigade/overcommit#configuration
#
# Uncomment the following lines to make the configuration take effect.
#PreCommit:
# RuboCop:
# enabled: true
# on_warn: fail # Treat all warnings as failures
#
# TrailingWhitespace:
# enabled: true
# exclude:
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
#
#PostCheckout:
# ALL: # Special hook name that customizes all hooks of this type
# quiet: true # Change all post-checkout hooks to only display output on failure
#
# IndexTags:
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
PreCommit:
CheckUntracked:
enabled: true
quiet: false
description: 'Check for files that should be tracked or ignored.'
required_executable: './.git-hooks/pre-commit/check_untracked.py'
+165
View File
@@ -0,0 +1,165 @@
/*
* IDMT Mini-Assignment 2
*
* Tank Wars: a simple game of throwing projectiles
* This is a skeleton with a few basic pieces filled
* in. You will need to fill in the rest to make the
* game work.
*/
// Basic information on the terrain and the tanks
float[] groundLevel; // Y coordinate of the ground for each X coordinate
float tank1X, tank1Y, tank2X, tank2Y; // Positions of the two tanks
float tankDiameter = 30; // Diameter of the tanks
float cannonLength = 20; // How long the cannon on each tank extends
float gravity = 0.05; // Strength of gravity
// Current state of the game
int playerHasWon = 0; // 1 if player 1 wins, 2 if player 2 wins, 0 if game in progress
boolean player1Turn = true; // true if it's player 1's turn; false otherwise
float tank1CannonAngle = PI/2, tank2CannonAngle = PI/2; // Direction the tank cannons are pointing
float tank1CannonStrength = 3, tank2CannonStrength = 3; // Strength of intended projectile launch
// Location of the projectile
boolean projectileInMotion = false;
float projectilePositionX, projectilePositionY;
float projectileVelocityX, projectileVelocityY;
void setup() {
size(960, 480); // Set the screen size
// Initialize the ground level
groundLevel = new float[width];
float player1Height = random(height/2, height-5);
float player2Height = random(height/2, height-5);
for(float i = 0; i < width * 0.2; i++) {
groundLevel[(int)i] = player1Height;
}
for(float i = width * 0.2; i < width * 0.8; i++) {
groundLevel[(int)i] = player1Height + (player2Height - player1Height) * (i - width*0.2)/(width*0.6);
}
for(float i = width * 0.8; i < width; i++) {
groundLevel[(int)i] = player2Height;
}
// Set the location of the two tanks so they rest on the ground at opposite sides
tank1X = width * 0.1;
tank1Y = player1Height;
tank2X = width * 0.9;
tank2Y = player2Height;
}
void draw() {
// Main draw loop. Farm out the individual tasks to other functions
// for clarity (though it could be equivalently implemented entirely in this function.)
background(200);
drawGround();
drawTanks();
drawProjectile();
drawStatus();
updateProjectilePositionAndCheckCollision();
}
// Draw the terrain under the tanks
void drawGround() {
/* TO IMPLEMENT IN STEP 1 */
beginShape();
int idx = 0;
for (Iterator<float> it = groundLevel.iterator(); it.hasNext(); idx++) {
float level = it.next();
vertex(idx, level)
}
// See the groundLevel[] variable to know where to draw the ground
// Ground should be drawn in a dark gray
}
// Draw the two tanks (including cannons)
void drawTanks() {
/* TO IMPLEMENT IN STEP 1 */
// Draw the two tanks as semicircles using the positions and sizes at the top of the file
// Tanks should be different colours
// Also be sure to draw the cannons, using the angles given at the top of the file
}
// Draw the projectile, if one is currently in motion
void drawProjectile() {
if(!projectileInMotion) // Don't draw anything if there's no projectile in motion
return;
noStroke();
fill(255, 255, 0);
ellipse(projectilePositionX, projectilePositionY, 8, 8);
}
// Draw the status text on the top of the screen
void drawStatus() {
textSize(24);
textAlign(LEFT);
fill(0);
if(playerHasWon == 1)
text("Player 1 Wins!", 10, 30);
else if(playerHasWon == 2)
text("Player 2 Wins!", 10, 30);
else if(player1Turn) { // player1Turn == true means it's player 1's turn
text("Player 1's turn", 10, 30);
textAlign(RIGHT);
text("Angle: " + tank1CannonAngle + " Strength: " + tank1CannonStrength, width - 10, 30);
}
else { // player1Turn == false
text("Player 2's turn", 10, 30);
textAlign(RIGHT);
text("Angle: " + tank2CannonAngle + " Strength: " + tank2CannonStrength, width - 10, 30);
}
}
// Move the projectile and check for a collision
void updateProjectilePositionAndCheckCollision() {
if(!projectileInMotion)
return;
/* TO IMPLEMENT IN STEP 3: UPDATE POSITION */
// Tasks: increment the position according to the velocity
// For later: the velocity according to gravity (and optionally wind)
/* TO IMPLEMENT IN STEP 4: GRAVITY */
// Update the velocity of the projectile according to the value of gravity at the top of the file
/* TO IMPLEMENT IN STEP 5: COLLISION DETECTION */
// Compare the location of the projectile to the ground and to the two tanks
// When the projectile hits something, it stops moving (change projectileInMotion)
// When the projectile hits the ground, it's the next player's turn
// When the projectile hits a tank, the other player wins
}
// Advance the turn to the next player
void nextPlayersTurn() {
player1Turn = !player1Turn;
}
// Handle a key press: update the status of the current player's tank
void keyPressed() {
if(playerHasWon != 0) // Stop the game when someone has won
return;
if(projectileInMotion) // No keys respond while the projectile is firing
return;
/* TO IMPLEMENT IN STEP 2 */
// Use the key variable to check which key was pressed.
// Arrow keys don't have a printable character, so they show up as CODED
// Use the left and right arrows to adjust the angle, the up and down arrows
// to adjust strength.
// Space bar fires the projectile. Initially in step 2, just have it switch
// to the next player.
}