⬆️ 💎

* Support ES6
* Integrates jsfxr
This commit is contained in:
Indrajith K L
2018-08-12 17:52:54 +05:30
parent db47cb139e
commit 0193315dd5
7 changed files with 1301 additions and 196 deletions

13
.babelrc Normal file
View File

@@ -0,0 +1,13 @@
{
"presets": [
[
"env",
{
"modules": false
}
]
],
"plugins": [
"external-helpers"
]
}

View File

@@ -1,33 +1,44 @@
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var browserSync = require('browser-sync');
var uglify = require('gulp-uglify');
const zip = require('gulp-vinyl-zip').zip;
var zip = require('gulp-vinyl-zip').zip;
var size = require('gulp-size');
var runSequence = require('run-sequence');
let rollup = require('rollup-stream');
var source = require('vinyl-source-stream');
var libs = ['./node_modules/kontra/kontra.min.js', './node_modules/tinymusic/dist/TinyMusic.min.js'];
var devLibs = ['./node_modules/jsfxr/jsfxr.js'];
var libFolder = 'libs/';
var outputTemp = 'temp/';
gulp.task('serve', ['copylibs'], function () {
gulp.task('serve', ['copylibs', 'copylibsDev', 'uglyfy_copy'], function () {
browserSync.init({
server: './'
server: {
baseDir: "./"
}
});
gulp.watch("./**/*.js", { cwd: './' },function(){
gulp.run('uglyfy_copy')
}).on('change', browserSync.reload);;
gulp.watch("src/js/**/*.js", { cwd: './' }, ['uglyfy_copy', 'reload'])
gulp.watch("./**/*.html", { cwd: './' }).on('change', browserSync.reload);
browserSync.watch()
});
gulp.task('reload', function () {
browserSync.reload();
});
gulp.task('uglyfy_copy', function () {
return gulp.src('src/js/*.js')
.pipe(uglify())
return rollup({
"format": "iife",
input: './src/js/main.js'
})
.pipe(source('main.js'))
.pipe(gulp.dest('public/js'));
});
@@ -39,7 +50,14 @@ gulp.task('copylibs', function () {
.pipe(gulp.dest(libFolder))
});
gulp.task('zipFiles',['prepare_dist_folder'], function () {
gulp.task('copylibsDev', function () {
return gulp
.src(devLibs)
.pipe(uglify())
.pipe(gulp.dest(libFolder))
});
gulp.task('zipFiles', function () {
return gulp.src('temp/**/*.*')
.pipe(zip('archive.zip'))
.pipe(gulp.dest('dist'))
@@ -54,3 +72,7 @@ gulp.task('prepare_dist_folder', function () {
.src(['libs/*', 'public/**/*.*', 'index.html'], { base: './' })
.pipe(gulp.dest(outputTemp))
});
gulp.task('release', function () {
runSequence('copylibs', 'copylibsDev', 'uglyfy_copy', 'prepare_dist_folder', 'zipFiles');
});

View File

@@ -6,9 +6,10 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="./libs/kontra.min.js"></script>
<script src="./libs/TinyMusic.min.js"></script>
<script src="./libs/jsfxr.js"></script>
<title>js13kgames-template</title>
</head>
<body onload="Game()">
<body>
<canvas></canvas>
<script src="public/js/main.js"></script>
</body>

1316
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,19 +4,29 @@
"description": "A barebone template aimed for js13kgames",
"scripts": {
"start": "./node_modules/.bin/gulp serve",
"release": "./node_modules/.bin/gulp zipFiles"
"release": "./node_modules/.bin/gulp release"
},
"author": "Indrajith K L",
"license": "MIT",
"dependencies": {
"jsfxr": "0.0.1",
"kontra": "^4.0.0",
"tinymusic": "^1.0.0"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"browser-sync": "^2.24.6",
"gulp": "^3.9.1",
"gulp-rollup": "^2.16.2",
"gulp-size": "^3.0.0",
"gulp-uglify": "^3.0.1",
"gulp-vinyl-zip": "^2.1.0"
"gulp-vinyl-zip": "^2.1.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-stream": "^1.24.1",
"run-sequence": "^2.2.1",
"vinyl-source-stream": "^2.0.0"
}
}

56
src/js/Game.js Normal file
View File

@@ -0,0 +1,56 @@
export default class Game{
constructor(){
this.url = window.URL || window.webkitURL;
this.soundUrl = jsfxr([3,,0.3469,0.6652,0.2097,0.0671,,0.0916,,,,0.3062,0.8509,,,0.5633,0.0985,-0.0068,1,,,,,0.5]);
this.player = new Audio();
this.player.on
this.init();
}
init(){
kontra.init();
this.main();
}
main(){
let sprite = kontra.sprite({
x: 100, // starting x,y position of the sprite
y: 80,
color: 'blue', // fill color of the sprite rectangle
width: 20, // width and height of the sprite rectangle
height: 40,
dx: 2 // move the sprite 2px to the right every frame
});
let loop = kontra.gameLoop({ // create the main game loop
update: ()=> { // update the game state
sprite.update();
// wrap the sprites position when it reaches
// the edge of the screen
if (sprite.x > kontra.canvas.width) {
sprite.x = -sprite.width;
}
if(kontra.keys.pressed('space')){
this.player.addEventListener('error', (e)=> {
console.log("Error: " + player.error.code);
}, false);
this.player.addEventListener('ended', (e)=> {
this.url.revokeObjectURL(this.soundURL);
}, false);
this.player.pause();
this.player.src = this.soundUrl;
let play = this.player.play();
console.log(play)
}
},
render: ()=> { // render the game state
sprite.render();
}
});
loop.start();
}
}

View File

@@ -1,30 +1,3 @@
function Game(){
kontra.init();
var sprite = kontra.sprite({
x: 100, // starting x,y position of the sprite
y: 80,
color: 'blue', // fill color of the sprite rectangle
width: 20, // width and height of the sprite rectangle
height: 40,
dx: 2 // move the sprite 2px to the right every frame
});
import Game from './Game';
var loop = kontra.gameLoop({ // create the main game loop
update: function() { // update the game state
sprite.update();
// wrap the sprites position when it reaches
// the edge of the screen
if (sprite.x > kontra.canvas.width) {
sprite.x = -sprite.width;
}
},
render: function() { // render the game state
sprite.render();
}
});
loop.start(); // start the game
}
window.Game = Game;
let game = new Game();