Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thursday July 30, 2015 #1

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
34f36af
basic html for layout
cbotwell Jul 30, 2015
6a80979
added basic scss imports and updated Brocfile
cbotwell Jul 30, 2015
68481b4
started basic styles
cbotwell Jul 30, 2015
82823b1
started constructors, added characters and template
cbotwell Jul 31, 2015
b51ec54
got templates for game screens set up and calling the battle screen
cbotwell Jul 31, 2015
3f33988
got start screen populating cages and changed to battle screen
cbotwell Jul 31, 2015
574d233
got currentEnemy and currentHero showing on battle screen
cbotwell Aug 2, 2015
04248fb
got health bar showing up, working on making health update
cbotwell Aug 2, 2015
d46026d
attacking updates health, working on turns
cbotwell Aug 2, 2015
0720a19
trying to make turns and get gameover screen
cbotwell Aug 2, 2015
7a070c2
passed game object to newBattle to remove extra variables
cbotwell Aug 2, 2015
b38362e
passing game object to battle template
cbotwell Aug 3, 2015
0493fbc
game goes to end screen when a character dies
cbotwell Aug 3, 2015
7894255
added play again button, not reseting health
cbotwell Aug 3, 2015
c2e278c
added notes
cbotwell Aug 3, 2015
29cdfc6
git healthbar for enemy working
cbotwell Aug 3, 2015
c20375c
added castor picture
cbotwell Aug 3, 2015
fb270cf
deploying
cbotwell Aug 3, 2015
bdb2184
added artwork
cbotwell Aug 3, 2015
c39b30d
artwork
cbotwell Aug 3, 2015
5e68d9c
fixed benjamin gates pic
cbotwell Aug 3, 2015
a4c3bad
fixed bg
cbotwell Aug 3, 2015
dbbab90
got enemy selecting randomly with _.sample
cbotwell Aug 3, 2015
b1a58f1
random enemy
cbotwell Aug 3, 2015
a1e9994
got AI attacking, but not on odd turns, hero health bar updates
cbotwell Aug 3, 2015
f4c40b0
AI attacks
cbotwell Aug 3, 2015
5aa38b3
moved renderBattle and renderHealth to game object
cbotwell Aug 4, 2015
2a9b8da
changed name to renderHealth
cbotwell Aug 4, 2015
c3e89c7
moved render health under render battle to simplify new battle
cbotwell Aug 4, 2015
0e678f2
updates
cbotwell Aug 4, 2015
0166f52
woking on game prototypes
cbotwell Aug 4, 2015
49b4d35
added comment for trigger
cbotwell Aug 4, 2015
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
10 changes: 9 additions & 1 deletion Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var appJs = concat(templatesAndScripts, {outputFile: 'app.js', inputFiles: [
'js/cagematch.js'
]});

var compiledSass = sass(['assets/scss', 'bower_components/reset-css'], 'cagematch.scss', 'app.css');
var includePaths = [
'assets/scss',
'bower_components/reset-css',
'bower_components/bourbon/app/assets/stylesheets',
'bower_components/fontawesome/scss',
'bower_components/neat/app/assets/stylesheets'
];

var compiledSass = sass(includePaths, 'cagematch.scss', 'app.css');

module.exports = mergeTrees(['public', appJs, compiledSass, bowerStuff]);
84 changes: 84 additions & 0 deletions assets/js/cagematch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
castorTroy = new Character({name: 'Castor Troy', weapons: {dualGoldenGuns: 40}, weaponName: 'Dual Golden Guns', hitPoints: 100, imgUrl: 'nic.png'});
memphisRaines = new Character({name: 'Memphis Raines', weapons: {eleanor: 60}, weaponName: 'Eleanor', hitPoints: 100, imgUrl: 'nic.png'});
benjaminGates = new Character({name: 'Benjamin Gates', weapons: {declarationOfIndependence: 50}, weaponName: 'Declaration of Independence', hitPoints: 100, imgUrl: 'nic.png'});
johhnyBlaze = new Character({name: 'Johnny Blaze', weapons: {chain: 30}, weaponName: 'Chain', hitPoints: 100, imgUrl: 'nic.png'});

var heros = [castorTroy, memphisRaines, benjaminGates, johhnyBlaze];

$('.game-target').html(AppTemplates.start(heros));

function Game(hero) {
this.hero = hero;
this.enemy = johhnyBlaze;
this.turnNumber = 0;
this.gameOver = false;
}

var selectCharacterEl = $('.select-character');

var heroTargetEl = [];
var enemyTargetEl = [];

var renderHero = function(hero) {
heroTargetEl.html(AppTemplates.character(hero));
};

var renderEnemy = function(enemy) {
enemyTargetEl.html(AppTemplates.character(enemy));
};

var attackButtonEl = [];

var healthBar = [];

var newBattle = function() {
$('.game-target').html(AppTemplates.battle());

heroTargetEl = $('.hero-target');
enemyTargetEl = $('.enemy-target');
renderHero(currentHero);
renderEnemy(currentEnemy);

healthBar = $('.hpbar');
healthBar.width(currentHero.getHealth + '%');

attackButtonEl = $('.attack');
attackButtonEl.html(currentHero.weaponName);

attackButtonEl.on('click', function() {
currentHero.attack(currentEnemy, 'dualGoldenGuns');
renderHero(currentHero);
renderEnemy(currentEnemy);

healthBar.width(currentEnemy.getHealth + '%');
turn++;
});

if (turn % 2 === 1) {
currentEnemy.attack(currentHero, 'chain');
renderHero(currentHero);
renderEnemy(currentEnemy);

healthBar.width(currentEnemy.getHealth + '%');
turn++;
}

if (currentHero.getHealth <= 0 || currentEnemy.getHealth <= 0) {
$('.game-target').html(AppTemplates.gameover());
}
};

var currentHero = {};
var currentEnemy = {};
var turn = 0;

selectCharacterEl.on('click', function() {
var indexSelected = $(this).data('index');
var hero = heros[indexSelected];
var game = new Game(hero);
currentHero = game.hero;
currentEnemy = game.enemy;
turn = game.turnNumber;

newBattle();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of having a game object is so that it stores and manages your hero, enemy, turn number, etc.

Try to pass your game as an argument to the newBattle function and this will clear up the currentHero, currentEnemy variables everywhere.

});
33 changes: 33 additions & 0 deletions assets/js/character.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function Character(options) {
options = options || {};
var hitPoints = options.hitPoints || 100;
this.weapons = options.weapons || {};
this.weaponName = options.weaponName;
this.name = options.name;
this.imgUrl = options.imgUrl;

this.takeDamage = function(damage) { hitPoints -= damage; };

this.getAttackStrength = function(weaponName) {
if (this.weapons[weaponName]) {
return this.weapons[weaponName];
}

return 5;
};

this.on('attacked', function(amount) {
this.takeDamage(amount);
});

this.getHealth = function() {return hitPoints;};
}

Character.prototype = _.extend({
constructor: Character,

attack: function(hostile, weapon) {
hostile.trigger('attacked', this.getAttackStrength(weapon));
}

}, Backbone.Events);
126 changes: 126 additions & 0 deletions assets/scss/cagematch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// imported and box sizing

@import 'reset';

$fa-font-path: "//netdna.bootstrapcdn.com/font-awesome/4.3.0/fonts";
@import 'font-awesome';
@import url(http://fonts.googleapis.com/css?family=Press+Start+2P);

@import 'bourbon';
@import 'neat';

html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}

// variables

$font-defaults: Helvetica, Arial, sans-serif;
$video-game-font: 'Press Start 2P', cursive;
$main-color: ;
$alt-color: ;
$main-border: 3px solid black;

// starting styles
body {
font-family: $video-game-font;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);

@include outer-container;
width: 980px;
}
.start {
h1 {
font-size: 3em;
text-align: center;
margin-bottom: 30px;
}
button {
font-family: inherit;
padding: 10px;
}
.characters {
@include outer-container;
}
.character {
@include span-columns(3);
@include omega(4n);
text-align: center;
p {
margin: 20px 0;
}
img {
width: 100%;
}
}

}
.battle {
.hero-target, .enemy-target {
@include span-columns(6 of 12);
text-align: center;
padding: 10px;
img {
width: 75%;
}
.hp {
margin: 10px;
}
.hpborder {
margin: 10px;
border: $main-border;
@include span-columns(10);
@include shift(1);
height: 10px;
}
.hpbar {
background: red;
height: 5px;
}
}
.messages {
@include span-columns(12);

border-radius: 5px;
border: $main-border;
padding: 1px;
.fight {
border-radius: 5px;
border: $main-border;
padding: 10px;
min-height: 100px;
position: relative;
}
.fa-play {
position: absolute;
top: 50%;
left: 30px;
transform: translateY(-50%);
}
button {
font-family: inherit;
padding: 10px;
position: absolute;
top: 50%;
left: 50px;
transform: translateY(-50%);
border: none;
background: none;
}
}
}
.gameover {
text-align: center;
h1 {
font-size: 3em;
margin-bottom: 20px;
}
}
14 changes: 14 additions & 0 deletions assets/templates/battle.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="center">
<div class="battle">
<div class="characters">
<div class="hero-target"></div>
<div class="enemy-target"></div>
</div>
<div class="messages">
<div class="fight">
<i class="fa fa-play"></i>
<button class="attack">Attack</button>
</div>
</div>
</div>
</div>
8 changes: 8 additions & 0 deletions assets/templates/character.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<img src="{{ imgUrl }}" alt="{{ name }}">
<p>{{ name }}</p>
<div class="hp">
<p>HP: {{ getHealth }}</p>
<div class="hpborder">
<div class="hpbar"></div>
</div>
</div>
8 changes: 8 additions & 0 deletions assets/templates/gameover.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="center">
<div class="gameover">
<h1>CAGE WINS!</h1>
<p>
"I don't think movies are the reason why this violence exists, I think it's going to happen whether movies are there or not." - Nicolas Cage
</p>
</div>
</div>
14 changes: 14 additions & 0 deletions assets/templates/start.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="center">
<div class="start">
<h1>CAGE MATCH</h1>
<div class="characters">
{{#each this as |cage|}}
<div class="character">
<img src="{{ cage.imgUrl }}" alt="{{ cage.name }}">
<p>{{ cage.name }}</p>
<button class="select-character" data-index="{{@index}}"> Select</button>
</div>
{{/each}}
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</head>
<body>

<div class="game-target"></div>

<script src="vendor.js"></script>
<script src="app.js"></script>
</body>
Expand Down
Binary file added public/nic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.