Commit c77df3f4 authored by Tomás Teijeiro Campo's avatar Tomás Teijeiro Campo

Included the javascript project in the same repository

parent bda6087f
# Created by https://www.gitignore.io/api/intellij,linux
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
.idea/
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
\ No newline at end of file
var invadersApp = {};
invadersApp.Boot = function (game) {
};
invadersApp.Boot.prototype = {
init: function () {
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
this.input.maxPointers = 1;
// Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:
this.stage.disableVisibilityChange = true;
if (this.game.device.desktop)
{
// If you have any desktop specific settings, they can go in here
this.scale.pageAlignHorizontally = true;
//this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
var scale = (window.innerWidth/960) * 0.8;
this.scale.setUserScale(scale, scale);
this.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
}
else
{
// Same goes for mobile settings.
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.setMinMax(480, 260, 1024, 768);
this.scale.forceLandscape = true;
this.scale.pageAlignHorizontally = true;
}
// Pixelized!
this.game.antialias = false;
this.game.stage.smoothed = false;
},
preload: function () {
this.load.image('preloaderBackground', 'assets/background.png');
this.load.image('retroFont', 'assets/fonts/font3.png');
this.load.image('preloaderBar', 'assets/preload.png');
},
create: function () {
// By this point the preloader assets have loaded to the cache, we've set the game settings
// So now let's start the real preloader going
this.state.start('Preloader');
}
};
// Game global config vars [MOVE TO SETTINGS]
var WALL_MARGIN = 80;
var DIR_CHANGE_MIN_TIME = 0;
var SHOOT_DELAY = 100;
var MIN_INVADERS = 4;
var INITIAL_INVADERS = 6;
var MIN_GENERATION_TIME = Phaser.Timer.SECOND * 2;
var BLUE = 0x15AFF0;
var ORANGE = 0xEF7D10;
invadersApp.GameState = {
PAUSED : 0,
RUNNING : 1,
GAME_OVER : 2
};
invadersApp.Game = function (game) {
// Auto-injected properties
this.game; // a reference to the currently running game (Phaser.Game)
this.add; // used to add sprites, text, groups, etc (Phaser.GameObjectFactory)
this.camera; // a reference to the game camera (Phaser.Camera)
this.cache; // the game cache (Phaser.Cache)
this.input; // the global input manager. You can access this.input.keyboard, this.input.mouse, as well from it. (Phaser.Input)
this.load; // for preloading assets (Phaser.Loader)
this.math; // lots of useful common math operations (Phaser.Math)
this.sound; // the sound manager - add a sound, play one, set-up markers, etc (Phaser.SoundManager)
this.stage; // the game stage (Phaser.Stage)
this.time; // the clock (Phaser.Time)
this.tweens; // the tween manager (Phaser.TweenManager)
this.state; // the state manager (Phaser.StateManager)
this.world; // the game world (Phaser.World)
this.particles; // the particle manager (Phaser.Particles)
this.physics; // the physics manager (Phaser.Physics)
this.rnd; // the repeatable random number generator (Phaser.RandomDataGenerator)
// Stores the reference to game elements
this.objects = {};
this.settings;
this.player;
this.bullets;
this.cursors;
this.fireButton;
this.gameState = invadersApp.GameState.PAUSED;
this.animationDelay = Phaser.Timer.SECOND;
};
invadersApp.Game.prototype = {
create: function () {
var that = this;
this.currentGenerationTime = Phaser.Timer.SECOND * 5;
this.currentGeneration = 0;
// Load game config
this.settings = this.game.cache.getJSON('settings');
// Initialize basic physics
this.game.physics.startSystem(Phaser.Physics.ARCADE);
// Load mainMusic assets
this.gameOverMusic = this.add.audio('gameOverMusic');
// FX sounds (from ...)
this.fx = this.game.add.audio('sfx');
this.fx.allowMultiple = true;
this.fx.addMarker('alien_death', 1, 1.0);
this.fx.addMarker('hit', 3, 0.5);
this.fx.addMarker('escape', 4, 3.2);
this.fx.addMarker('meow', 8, 0.5);
this.fx.addMarker('numkey', 9, 0.1);
this.fx.addMarker('ping', 10, 1.0);
this.fx.addMarker('death', 12, 4.2);
this.fx.addMarker('shot', 17, 1.0);
this.fx.addMarker('squit', 19, 0.3);
// Group of invaders
this.objects.invaders = this.add.group();
this.objects.invaders.enableBody = true;
this.objects.invaders.physicsBodyType = Phaser.Physics.ARCADE;
for (var i = 0; i < INITIAL_INVADERS; i++) {
this.objects.invaders.add(new invadersApp.Invader(this, null, this.game.world.width/2, this.game.world.height/2));
}
// Add HUDs (before the invaders group to appear over them)
this.scoreText = invadersApp.utils.addText(this, 60, 20, 'SCORE:', 2);
this.scoreHud = invadersApp.utils.addText(this, this.scoreText.img.x + this.scoreText.img.width / 2 + 30, 20, invadersApp.utils.pad(0, 3), 2);
this.invadersText = invadersApp.utils.addText(this, this.scoreHud.img.x + this.scoreHud.img.width + 80, 20, 'INVADERS:', 2);
this.invadersHud = invadersApp.utils.addText(this, this.invadersText.img.x + this.invadersText.img.width / 2 + 30, 20, invadersApp.utils.pad(0, 3), 2);
// Create and add the main player
this.player = new invadersApp.Player(this);
this.game.add.existing(this.player);
// Create a white, immovable wall with physics enabled
this.createWall();
// A PIXI graphics for drawing lines
this.bgraphics = this.game.add.graphics(0, 0);
this.cursors = this.game.input.keyboard.createCursorKeys();
this.fireButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
// Start the game paused with the message READY!
var readyText = invadersApp.utils.addText(this, this.game.width / 2, this.game.height / 2, 'READY!', 5);
this.game.input.keyboard.onDownCallback = function () {
if (readyText.img.visible){
that.game.paused = false;
readyText.img.kill();
that.lastGenerationTime = that.game.time.now;
that.gameState = invadersApp.GameState.RUNNING;
}
};
this.updateCounter();
this.game.paused = true;
},
update: function () {
var that = this;
// If physics are paused, skip all
if (this.game.physics.arcade.isPaused) return;
// Detect collisions with the wall and with the bullets
this.game.physics.arcade.collide(this.wall, this.objects.invaders);
this.game.physics.arcade.overlap(this.player.bullets, this.objects.invaders, function (bullet, invader) {
if (bullet.alive) {
bullet.kill();
var living = that.objects.invaders.countLiving();
if (living > MIN_INVADERS) {
invader.destroy();
that.fx.play('alien_death');
that.updateCounter();
}
if (living == MIN_INVADERS + 1) {
that.objects.invaders.forEachAlive(function (invader) {
invader.drawShield(BLUE);
}, that);
}
}
}, null, this);
// Evolutionary cycle
this.updateEvolution();
},
quitGame: function (pointer) {
// TODO: Stop mainMusic, delete sprites, purge caches, free resources...
// Then let's go back to the main menu.
this.state.start('MainMenu');
},
pauseGame: function () {
this.game.physics.arcade.isPaused = true;
this.gameState = invadersApp.GameState.PAUSED;
},
resumeGame: function () {
this.game.physics.arcade.isPaused = false;
this.gameState = invadersApp.GameState.RUNNING;
},
gameOver: function () {
invadersApp.utils.addText(this, this.game.width / 2, this.game.height / 2, 'GAME OVER!', 5);
this.gameState = invadersApp.GameState.GAME_OVER;
//invadersApp.MainMenu.mainMusic.stop();
this.gameOverMusic.play('', 0, 1, true, true);
},
updateEvolution: function () {
var that = this;
if (this.gameState == invadersApp.GameState.RUNNING &&
(this.game.time.now > this.lastGenerationTime + this.currentGenerationTime)) {
// Pause the game during the animation
this.pauseGame();
var evolutionText;
if (this.animationDelay > 500) {
evolutionText = invadersApp.utils.addText(this, this.game.width / 2, this.game.height / 2, 'EVOLUTION TIME', 5);
}
// The number of invaders
var alive = this.objects.invaders.countLiving();
var aliveInvaders = this.objects.invaders.filter(function(child, index, children) {
return child.alive;
}, true);
aliveInvaders.callAll('increaseFitness');
// The number of new individuals is determined by a box-cox
// transformation with lambda=0.6.
var numPairs = Math.floor((Math.pow(alive, 0.6) - 1) / 0.6);
var pool = invadersApp.evolution.pool(aliveInvaders.list, numPairs);
var offspring = invadersApp.evolution.evolve(pool, this.settings.genes);
// A timer for playing animations during the reproduction phase
this.animationTimer = this.game.time.create(true);
var childIndex = 0;
this.animationTimer.repeat(this.animationDelay, offspring.length + 1, function () {
if (childIndex == offspring.length) return;
if (evolutionText != undefined){
evolutionText.img.destroy();
evolutionText = null;
}
// Disable shields for all the invaders
aliveInvaders.callAll('hideShield');
var p = offspring[childIndex++];
var x = (p[0].x + p[1].x)/2;
var y = (p[0].y + p[1].y)/2;
that.objects.invaders.add(new invadersApp.Invader(that, p[2], x, y));
// Draw lines
this.bgraphics.clear();
this.bgraphics.lineStyle(1, ORANGE);
this.bgraphics.moveTo(p[0].x, p[0].y);
this.bgraphics.lineTo(p[1].x, p[1].y);
// Draw shields
p[0].drawShield(ORANGE);
p[1].drawShield(ORANGE);
// Count the new children added to the game
this.updateCounter();
}, this);
this.animationTimer.onComplete.add(function () {
// Hide any visible shield
aliveInvaders.callAll('hideShield');
this.currentGeneration++;
// Decrease next generation time
if (this.currentGenerationTime > MIN_GENERATION_TIME) {
this.currentGenerationTime -= 150;
}
// Decrease the animation time
if (this.animationDelay > 50){
this.animationDelay -= 150;
}
if (evolutionText != undefined){
evolutionText.img.destroy();
evolutionText = null;
}
this.updateScore();
// Clear all lines
this.bgraphics.clear();
this.resumeGame();
if (this.objects.invaders.countLiving() >= 100){
this.gameOver();
}
// Update the last generation time after completion
this.lastGenerationTime = this.game.time.now;
}, this);
this.animationTimer.start();
}
},
createWall: function () {
// create a new bitmap data object
var wallBmp = this.game.add.bitmapData(this.game.width, 3);
// draw the wall
wallBmp.ctx.beginPath();
wallBmp.ctx.rect(0,0,this.game.width,3);
wallBmp.ctx.fillStyle = '#ffffff';
wallBmp.ctx.fill();
// use the bitmap data as the texture for the sprite
this.wall = this.add.sprite(0, this.game.height - WALL_MARGIN, wallBmp);
this.game.physics.enable(this.wall, Phaser.Physics.ARCADE);
this.wall.body.immovable = true;
},
updateScore: function () {
this.scoreHud.font.text = invadersApp.utils.pad(this.currentGeneration, 3);
},
updateCounter: function () {
this.living = this.objects.invaders.countLiving();
this.invadersHud.font.text = invadersApp.utils.pad(this.living, 3);
}
};
invadersApp.MainMenu = function (game) {
this.mainMusic = null;
this.playButton = null;
};
invadersApp.MainMenu.prototype = {
create: function () {
this.mainMusic = this.add.audio('mainMusic');
var textTop = invadersApp.utils.addText(this, this.game.width / 2, 50, 'CITIUS PROUDLY PRESENTS:' , 2);
textTop.alpha = 0;
var titleYPos = this.game.height / 3;
var title = this.add.sprite(this.game.width / 2, -100, 'title');
title.anchor.setTo(0.5, 0.5);
var logo = this.add.sprite(this.game.width / 2, this.game.height - 60, 'logo');
logo.anchor.setTo(0.5, 0.5);
logo.scale.setTo(0.6, 0.6);
logo.visible = false;
var textIES = invadersApp.utils.addText(this, this.game.width / 2, titleYPos + 50, 'A GAME FOR IES ROSALIA DE CASTRO', 1);
textIES.img.visible = false;
var textPressStart = invadersApp.utils.addText(this, this.game.width / 2, titleYPos + 200, 'PRESS ENTER', 2);
textPressStart.img.visible = false;
var textCopyright = invadersApp.utils.addText(this, this.game.width / 2, logo.y + 40, 'CENTRO SINGULAR DE INVESTIGACION EN TECNOLOXIAS DA INFORMACION', 1);
textCopyright.img.visible = false;
var tweenPresents = this.game.add.tween(textTop).to( { alpha: 1 }, 800, Phaser.Easing.Linear.None, false, 200);
var tweenTitle = this.game.add.tween(title).to( { y: this.game.height / 3 }, 1200, Phaser.Easing.Bounce.Out, false);
tweenPresents.chain(tweenTitle);
tweenPresents.onComplete.add(function () {
// Play mainMusic
this.mainMusic.play('', 0, 1, true, true);
}, this);
tweenTitle.onComplete.add(function () {
// Show bottom info
logo.visible = true;
textCopyright.img.visible = true;
textPressStart.img.visible = true;
textIES.img.visible = true;
// Start blinking event for 'PRESS START'
this.game.time.events.loop(Phaser.Timer.HALF, function () {
textPressStart.img.visible = !textPressStart.img.visible;
}, this);
}, this);
// Start animated chain
tweenPresents.start();
this.game.input.keyboard.addKey(Phaser.Keyboard.ENTER).onDown.add(function () {
this.startGame();
}, this);
},
update: function () {
},
startGame: function (pointer) {
this.mainMusic.stop();
this.state.start('Game');
}
};
invadersApp.Preloader = function (game) {
this.background = null;
this.preloadBar = null;
this.ready = false;
};
invadersApp.Preloader.prototype = {
preload: function () {
var loadingText = invadersApp.utils.addText(this, this.game.width / 2, this.game.height / 2 - 60, 'Loading...', 3);
this.preloadBar = this.add.sprite(this.game.width / 2, loadingText.img.y + 40, 'preloaderBar');
this.preloadBar.anchor.setTo(0.5, 0.5);
// This sets the preloadBar sprite as a loader sprite.
// What that does is automatically crop the sprite from 0 to full-width
// as the files below are loaded in.
this.load.setPreloadSprite(this.preloadBar);
// Here we load the rest of the assets our game needs.
// As this is just a Project Template I've not provided these assets, swap them for your own.
this.load.image('titlepage', 'assets/title.png');
this.load.audio('titleMusic', ['assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']);
this.load.audio('gameOverMusic', ['assets/audio/invaders_gameover.ogg']);
this.load.audio('mainMusic', ['assets/audio/invaders_mainloop.ogg']);
this.load.audio('sfx', 'assets/audio/fx_mixdown.ogg');
// + lots of other required assets here
this.load.image('nao', 'assets/nao.png');
this.load.image('invader', 'assets/invader.png');
this.load.image('bullet', 'assets/player_bullet.png');
this.load.image('title', 'assets/title-3.png');
this.load.image('logo', 'assets/citius-logo-8bit.png');
// Read game settings
this.load.json('settings', 'settings.json');
},
create: function () {
// Once the load has finished we disable the crop because we're going to sit in the update loop for a short while as the mainMusic decodes
this.preloadBar.cropEnabled = false;
},
update: function () {
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
{
this.ready = true;
this.state.start('MainMenu');
}
}
};
<font>
<info face="minecraftia" size="64" bold="0" italic="0" chasrset="" unicode="0" stretchH="100" smooth="1" aa="1" padding="0,0,0,0" spacing="2,2"/>
<common lineHeight="96" base="80" scaleW="512" scaleH="512" pages="1" packed="0"/>
<pages>
<page id="0" file="minecraftia.png"/>
</pages>
<chars count="95">
<char id="106" x="2" y="3" width="44" height="68" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="j"/>
<char id="64" x="48" y="3" width="52" height="60" xoffset="0" yoffset="23" xadvance="56" page="0" chnl="0" letter="@"/>
<char id="36" x="102" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="$"/>
<char id="81" x="148" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="Q"/>
<char id="37" x="194" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="%"/>
<char id="79" x="240" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="O"/>
<char id="71" x="286" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="G"/>
<char id="67" x="332" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="C"/>
<char id="38" x="378" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="&amp;"/>
<char id="83" x="424" y="3" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="S"/>
<char id="85" x="2" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="U"/>
<char id="35" x="48" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="#"/>
<char id="54" x="94" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="6"/>
<char id="56" x="140" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="8"/>
<char id="57" x="186" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="9"/>
<char id="98" x="232" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="b"/>
<char id="100" x="278" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="d"/>
<char id="51" x="324" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="3"/>
<char id="48" x="370" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="0"/>
<char id="63" x="416" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="?"/>
<char id="74" x="462" y="73" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="J"/>
<char id="47" x="2" y="135" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="/"/>
<char id="92" x="48" y="135" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="\"/>
<char id="87" x="94" y="135" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="W"/>
<char id="77" x="140" y="135" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="M"/>
<char id="65" x="186" y="135" width="44" height="60" xoffset="0" yoffset="23" xadvance="48" page="0" chnl="0" letter="A"/>