Skip to content

Commit 3b04924

Browse files
author
Zsolt Meszaros
committed
Initial commit
0 parents  commit 3b04924

25 files changed

+1074
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.log
2+
3+
.DS_Store
4+
.DS_Store?
5+
._*
6+
.Trashes
7+
ehthumbs.db
8+
Thumbs.db
9+
10+
.idea
11+
node_modules/
12+
.sass-cache
13+
*.css.map
14+
dist/
15+
16+
CNAME

gulpfile.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
var gulp = require('gulp');
2+
var del = require('del');
3+
var rename = require('gulp-rename');
4+
var babel = require('gulp-babel');
5+
var uglify = require('gulp-uglify');
6+
var sass = require('gulp-sass');
7+
var sassLint = require('gulp-sass-lint');
8+
var autoprefixer = require('gulp-autoprefixer');
9+
var cleanCSS = require('gulp-clean-css');
10+
var jade = require('gulp-jade');
11+
var browserSync = require('browser-sync');
12+
var reload = browserSync.reload;
13+
var plumber = require('gulp-plumber');
14+
15+
var options = {
16+
src: {
17+
jade: ['./src/jade/**/*.jade', '!src/jade/**/layout.jade'],
18+
js: './src/js/**/*.js',
19+
sass: ['./src/sass/**/*.s+(a|c)ss', '!src/sass/vendors/**/*']
20+
},
21+
dest: {
22+
html: './dist/',
23+
js: './dist/js',
24+
css: './dist/css'
25+
},
26+
filesToCopy: [
27+
{
28+
src: './src/images/**/*.*',
29+
dest: './dist/images'
30+
},
31+
{
32+
src: './src/fonts/**/*.*',
33+
dest: './dist/fonts'
34+
}
35+
],
36+
autoprefixer: 'last 2 versions'
37+
};
38+
39+
var cleanFolders = [ 'dist' ];
40+
41+
gulp.task('clean', function () {
42+
return del(cleanFolders);
43+
});
44+
45+
gulp.task('build:html', function() {
46+
return gulp.src(options.src.jade)
47+
.pipe(plumber())
48+
.pipe(jade({pretty: true}))
49+
.pipe(gulp.dest(options.dest.html))
50+
.pipe(reload({stream: true}));
51+
});
52+
53+
gulp.task('build:html:min', function() {
54+
return gulp.src(options.src.jade)
55+
.pipe(jade())
56+
.pipe(gulp.dest(options.dest.html))
57+
.pipe(reload({stream: true}));
58+
});
59+
60+
gulp.task('build:js', function() {
61+
return gulp.src(options.src.js)
62+
.pipe(plumber())
63+
.pipe(babel())
64+
.pipe(gulp.dest(options.dest.js))
65+
.pipe(reload({stream: true}));
66+
});
67+
68+
gulp.task('build:js:min', function() {
69+
return gulp.src(options.src.js)
70+
.pipe(babel())
71+
.pipe(rename({suffix: '.min'}))
72+
.pipe(uglify())
73+
.pipe(gulp.dest(options.dest.js))
74+
.pipe(reload({stream: true}));
75+
});
76+
77+
gulp.task('build:css', function() {
78+
return gulp.src(options.src.sass)
79+
.pipe(plumber())
80+
.pipe(sassLint())
81+
.pipe(sassLint.format())
82+
.pipe(sassLint.failOnError())
83+
.pipe(sass({outputStyle: 'expanded'})
84+
.on('error', sass.logError))
85+
.pipe(autoprefixer(options.autoprefixer))
86+
.pipe(gulp.dest(options.dest.css))
87+
.pipe(reload({stream: true}));
88+
});
89+
90+
gulp.task('build:css:min', function() {
91+
return gulp.src(options.src.sass)
92+
.pipe(sassLint())
93+
.pipe(sassLint.format())
94+
.pipe(sassLint.failOnError())
95+
.pipe(sass({outputStyle: 'compressed'})
96+
.on('error', sass.logError))
97+
.pipe(autoprefixer(options.autoprefixer))
98+
.pipe(rename({suffix: '.min'}))
99+
.pipe(cleanCSS({debug: true}, function(details) {
100+
console.log(details.name + ': ' + details.stats.originalSize);
101+
console.log(details.name, ': ', details.stats.minifiedSize);
102+
}))
103+
.pipe(gulp.dest(options.dest.css))
104+
.pipe(reload({stream: true}));
105+
});
106+
107+
gulp.task('copy', function() {
108+
options.filesToCopy.forEach(function(file) {
109+
gulp.src(file.src)
110+
.pipe(gulp.dest(file.dest));
111+
});
112+
});
113+
114+
gulp.task('browser-sync', function() {
115+
browserSync.init({
116+
server: {
117+
baseDir: options.dest.html
118+
}
119+
});
120+
});
121+
122+
gulp.task('watch', function() {
123+
gulp.watch(options.src.js, ['build:js']);
124+
gulp.watch(options.src.sass, ['build:css']);
125+
gulp.watch(options.src.jade, ['build:html']);
126+
});
127+
128+
gulp.task('default', ['copy', 'build:html', 'build:js', 'build:css', 'browser-sync', 'watch']);
129+
gulp.task('build', ['copy', 'build:html', 'build:js', 'build:css']);
130+
gulp.task('build:min', ['copy', 'build:html:min', 'build:js:min', 'build:css:min']);
131+
gulp.task('build:clean', ['clean', 'default']);
132+
// @todo: add Mocha tests
133+
// gulp.task('build:test', ['test', 'default']);

package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "snake-game",
3+
"version": "0.1.0",
4+
"description": "Day 16 of my 3 weeks game challenge",
5+
"main": "gulpfile.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"start": "gulp",
11+
"test": "tape ./test/*.js | tap-spec"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/zsoltime/snake-game.git"
16+
},
17+
"keywords": [
18+
"game",
19+
"challenge"
20+
],
21+
"author": "Zsolt Meszaros",
22+
"license": "MIT",
23+
"dependencies": {},
24+
"devDependencies": {
25+
"babel-preset-es2015": "^6.18.0",
26+
"browser-sync": "^2.17.5",
27+
"del": "^2.2.2",
28+
"gulp": "^3.9.1",
29+
"gulp-autoprefixer": "^3.1.1",
30+
"gulp-babel": "^6.1.2",
31+
"gulp-clean-css": "^2.0.13",
32+
"gulp-jade": "^1.1.0",
33+
"gulp-plumber": "^1.1.0",
34+
"gulp-rename": "^1.2.2",
35+
"gulp-sass": "^2.3.2",
36+
"gulp-sass-lint": "^1.2.0",
37+
"gulp-uglify": "^2.0.0"
38+
},
39+
"bugs": {
40+
"url": "https://github.com/zsoltime/snake-game/issues"
41+
},
42+
"homepage": "https://github.com/zsoltime/snake-game#readme"
43+
}

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Day 15 of My 3 Weeks Game Challenge
2+
3+
Classic snake game using P5.js
4+
5+
## User Stories
6+
7+
- [x] The snake never stops moving
8+
- [x] I can control the snake with my arrow keys
9+
- [x] I can see a randomly placed food
10+
- [x] If the snake eats this food, it gets longer
11+
- [x] If the snake hits the edge, it dies
12+
- [x] If the snake bites itself, it dies
13+
- [x] I can see the number of foods I collected
14+
15+
## Next Steps
16+
17+
I definitely need to add a splash screen on start and a game over screen with the final score and an option to restart the game.
18+
19+
It would be also great to make it mobile friendly and you could swipe to control the snake.

src/jade/index.jade

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends layout
2+
block title
3+
title (16) Snake
4+
block content
5+
h1 Snake
6+
.game#game

src/jade/layout.jade

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
doctype html
2+
html(lang='en')
3+
head
4+
meta(charset='UTF-8')
5+
meta(name='viewport', content='width=device-width, initial-scale=1')
6+
block title
7+
link(href='https://fonts.googleapis.com/css?family=Open+Sans:300,400',
8+
rel='stylesheet', type='text/css')
9+
link(href='css/style.css', rel='stylesheet', type='text/css')
10+
body
11+
block content
12+
script(src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/p5.min.js')
13+
script(src='js/game.js')

0 commit comments

Comments
 (0)