Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.*.sw[pon]
# Build and temporary files
build/
node_modules/
samples/brick_breaker_requires.js
*.log
samples/brickbreaker/levels/levels.js

# IDE files
.*.sw[pon]
*~
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Framework to create javascript games

## Samples:
### Brick Breaker
http://fco.github.io/JSGames
http://fco.github.io/JSGames/brickbreaker

## Test:
npm run brickbreaker
Expand Down
17 changes: 4 additions & 13 deletions element_factory.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
module.exports = ElementFactory;
require("./lives.js");
require("./score.js");
require("./aceleration.js");
require("./velocity.js");
require("./poligon.js");
require("./retangle.js");
require("./quad.js");
require("./border.js");
require("./arc.js");
require("./levels.js");
require('./elements/*.js', {mode: 'expand'});

var decamelize = require("decamelize");
var Velocity = require("./velocity.js");
var Point = require("./point.js");
var Velocity = require("./elements/velocity.js");
var Point = require("./elements/point.js");

function ElementFactory() { }
ElementFactory.prototype = {
createElement: function(type_class, params) {
var file = "./" + decamelize(type_class) + ".js";
var file = "./elements/" + decamelize(type_class) + ".js";
var Class = require(file);
var tmp_obj = new Class(params);
tmp_obj._class = type_class;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion levels.js → elements/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Levels.prototype = {
separator: ": ",
levels: null,
generic: function(){},
current_level: -1,
current_level: 0,
starter: function(){},

add_level: function(level) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var gulp = require('gulp');
var chug = require('gulp-chug');
var flatten = require('gulp-flatten');
var glob = require('glob');
var path = require('path');
var webserver = require('gulp-webserver');

gulp.task('default', ['watch'], function() {
gulp
.src("build/")
.pipe(webserver({
livereload: true,
open: true,
directoryListing: {
enable: true,
path: "build"
}
}))
;
});

gulp.task("build", function() {
gulp
.src( './samples/**/gulpfile.js', { read: false } )
.pipe( chug({tasks: ["build"]}) )
;

gulp
.src( './samples/**/build/*' )
.pipe( flatten({ includeParents: 1}) )
.pipe( gulp.dest('build') )
;
});

gulp.task("watch", ["build"], function() {
gulp.watch(["**.js", "**.json"], ['build']);
});

glob.sync("samples/*").forEach(function(filepath) {
var sample = path.basename(filepath);
gulp.task(sample, function() {
gulp
.src( filepath + '/gulpfile.js', { read: false } )
.pipe( chug() )
;
});
["build", "watch"].forEach(function(task) {
gulp.task(sample + ":" + task, function() {
gulp
.src( filepath + '/gulpfile.js', { read: false } )
.pipe( chug({tasks: [task]}) )
;
});
});
});
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Framework to create javascript games",
"main": "index.js",
"scripts": {
"build": "rm -rf build || true; mkdir -p build; cp samples/*.html build; for js in samples/*.js; do browserify $js > $(echo $js | perl -pe 's{^samples}{build}'); done",
"brickbreaker": "npm install; cd samples; budo brick_breaker.js --open --live --debug"
"build": "npm install && gulp build",
"brickbreaker": "npm install && gulp brickbreaker"
},
"repository": {
"type": "git",
Expand All @@ -19,10 +19,25 @@
"homepage": "https://github.com/FCO/JSGames",
"devDependencies": {
"browserify": "^13.0.0",
"budo": "^8.2.1"
"budo": "^8.2.1",
"glob": "^7.0.3",
"gulp": "^3.9.1",
"gulp-browserify2": "0.0.2",
"gulp-chug": "^0.5.1",
"gulp-concat": "^2.6.0",
"gulp-flatten": "^0.2.0",
"gulp-inject": "^4.0.0",
"gulp-insert": "^0.5.0",
"gulp-minify": "^0.0.10",
"gulp-replace": "^0.5.4",
"gulp-util": "^3.0.7",
"gulp-webserver": "^0.9.1",
"path": "^0.12.7"
},
"dependencies": {
"brfs": "^1.4.3",
"bulkify": "^1.2.0",
"decamelize": "^1.2.0"
"decamelize": "^1.2.0",
"require-globify": "^1.3.0"
}
}
20 changes: 20 additions & 0 deletions samples/brickbreaker/blocks/regular_block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exports.symbol = "###";
exports.type = "Poligon";
exports.transformation = function(data) {
var color = "#000000";
if(data && data.color) color = data.color;
this.draw_colision_area = false;
this.solid = true;
this.do_not_colide_with = ["Border"];
this.type = "Block";
this.color = color;
this.add_vertice(-13, 0);
this.add_vertice(12, 0);
this.add_vertice(12, 15);
this.add_vertice(-13, 15);
this.on_colide_with("ball", function(bola) {
this.score.add("block");
this.on_destroy();
this.randomPowerUp(bola.velocity);
});
};
6 changes: 6 additions & 0 deletions samples/brickbreaker/generate_levels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd levels
for level in *.lvl; do
COMMAND="exports.$(echo $level | cut -d. -f1) = require('fs').readFileSync('levels/$level');"
echo $COMMAND
done > levels.js
53 changes: 53 additions & 0 deletions samples/brickbreaker/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var replace = require('gulp-replace');
var browserify = require("gulp-browserify2");
var inject = require('gulp-inject');
var webserver = require('gulp-webserver');

gulp.task('levels', function() {
var levelsPath = 'levels/';
gulp.src(levelsPath + '*.lvl')
.pipe(replace("\n", "\\n"))
.pipe(insert.wrap('"', '"'))
.pipe(concat('levels.js', { newLine: ',' }))
.pipe(insert.wrap('module.exports = [', '];'))
.pipe(gulp.dest(levelsPath));
});

gulp.task('build', ["levels"], function() {
var js = gulp
.src("index.js")
.pipe(browserify({
fileName: "brickbreaker.js",
transform: [require("brfs"), require("require-globify")],
options: {
debug: true
}
}))
.pipe(gulp.dest("build"))
;

gulp
.src("*.html")
.pipe(gulp.dest("build"))
.pipe(inject(js, {relative: true}))
.pipe(gulp.dest("build"))
;
});

gulp.task("watch", ["build"], function() {
gulp.watch(["**.js", "**.lvl", "**.json"], ['build']);
});

gulp.task("default", ["watch"], function() {
gulp
.src("build/")
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true
}))
;
});
8 changes: 8 additions & 0 deletions samples/brickbreaker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
<!-- inject:js -->
<!-- endinject -->
</body>
</html>
Loading