Skip to content

Instantly share code, notes, and snippets.

View happyDemon's full-sized avatar

Kerstens Maxim happyDemon

  • Shyfter
  • Belgium
View GitHub Profile
@happyDemon
happyDemon / pokemon-template.html
Created March 5, 2017 08:05
Vue.js explained through Pokemon
<transition-attack>
<div v-if="attackEffect" class="battle-effectiveness">
{{attackEffect}}
</div>
</transition-attack>
@happyDemon
happyDemon / main.js
Created March 5, 2017 07:59
Vue.js explained through Pokemon #5
import Vue from 'vue'
window.Vue = Vue;
window.Vuemit = require('vuemit');
// Import Velocity & its base animations
import 'velocity-animate'
import 'velocity-animate/velocity.ui'
// Import our custom transitions
@happyDemon
happyDemon / animations.js
Last active March 5, 2017 07:53
Vue.js explained through pokemon
export default {
animations: [
{
// call this transition with <transistion-attack>HTML TO TRANSITION</transition-attack>
tag: 'transition-attack',
// We don't want to trigger the transition on initial render
onAppear: false,
// Ignore CSS animations that happen to have the same name
css: false,
// Define the animation hooks
@happyDemon
happyDemon / pokemon-style.css
Created March 4, 2017 09:02
Vue.js explained through Pokemon #5
.box-top-right .battle-effectiveness {
position: absolute;
z-index: 1;
left: 26px;
width: 200px;
text-align: center;
top: -50px;
font-family: monospace;
font-size: 1.2em;
font-weight: bold;
@happyDemon
happyDemon / pokemon-template.html
Created March 4, 2017 08:58
Vue.js explained through Pokemon #5
<div v-if="attackEffect" class="battle-effectiveness">
{{attackEffect}}
</div>
@happyDemon
happyDemon / Damage-calculateCritical.js
Created March 4, 2017 08:39
Vue.js explained through Pokemon #5
calculateCritical(otherPokemonType) {
const random = Math.floor(Math.random() * 255);
const probability = (this.attack.type == 'normal') ? this.attacking.stats.speed / 512 : this.attacking.stats.speed / 256;
// Seems like we've got a critical hit
if (random < probability) {
Vuemit.fire(otherPokemonType+'.attack.effective', 'Critical hit!');
// Lower leveled pokemon will have a smaller percentage of bonus
return ((this.attacking.stats.level * 2) + 5) / (this.attacking.stats.level + 5);
}
@happyDemon
happyDemon / Damage-calculateTypeEffect.js
Created March 4, 2017 08:37
Vue.js explained through Pokemon #5
// Consult the type chart and build a multiplier
calculateTypeEffect(otherPokemonType) {
// If we haven't defined the type in the typeChart return normal damage
if (typeof this.typeChart[this.attack.type] == 'undefined')
return 1;
// Here we'll build the multiplier in
let effectTotal = 1;
// In case of immune we'll just set this to true
@happyDemon
happyDemon / Damage-power.js
Created March 4, 2017 08:34
Vue.js explained through Pokemon #5
power(otherPokemonType) {
return Math.floor(this.calculateStatsPower() * this.calculateStab() * this.calculateTypeEffect(otherPokemonType) * this.calculateCritical(otherPokemonType) * this.calculateOther() * this.getRandomFactor())
}
@happyDemon
happyDemon / pokemon-methods.js
Created March 4, 2017 08:33
Vue.js explained through Pokemon #5
calculateDamage(attackName) {
const attack = this.local.pokemon.attacks[attackName];
const damage = new Damage(attack, this.local.pokemon, this.opponent.pokemon);
return damage.power(this.otherPokemon);
},
@happyDemon
happyDemon / pokemon-mounted.js
Created March 4, 2017 08:14
Vue.js explained through Pokemon #5
mounted(){
Vuemit.listen(this.type+'.attack.effective', (effect) => {
this.showAttackEffect(effect);
});
},