Adesis
Desarrollador front-end
Aficionado a los videojuegos
bower.json
package.json
app
gulpfile.js
elements
fonts
images
index.html
main.css
elements.html
my-element
audio
images
my-element.html
styles.css
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MASTER GUN</title>
<link rel="stylesheet" type="text/css" href="main.css">
<!-- build:js lib.min.js -->
<script
src="./bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<!-- endbuild -->
<!-- will be replaced with elements/elements.vulcanized.html -->
<link rel="import" href="elements/elements.html">
<!-- endreplace-->
</head>
<body>
<mg-view></mg-view>
</body>
</html>
<link rel="import" href="mg-view/mg-view.html">
<link rel="import"
href="../../bower_components/polymer/polymer.html">
<dom-module id="mg-view">
<template>
<p>Plantilla del componente</p>
</template>
<style>
p {color: red;}
</style>
<script>
Polymer({
is: "mg-view"
});
</script>
</dom-module>
mg-view
mg-menu-bar
mg-apache
mg-cowboy
mg-girl
mg-slot
mg-charger-audio
mg-score
mg-scenario
mg-charger
mg-munition
mg-bullet
Revisemos el código
Revisemos el código
Revisemos el código
document.querySelector('mg-score')
Revisemos el código
<div class$="{{flashComputedClass}}"></div>shoots: {
type: Number,
value: 0,
notify: true,
observer: 'shootBullet'
},document.addEventListener('WebComponentsReady', (function(e) {
this.mgMunition = document.querySelector('mg-munition');
}).bind(this));this.fire('shoot-bullet-event');
Esto evita pasar la variable shoots al cargador y tener que vigilar su valor
Revisemos el código
Revisemos el código
Revisemos el código
<template is="dom-repeat" items="{{slots}}" index-as="i">
<mg-slot status="{{item.status}}" number$="{{i}}"></mg-slot>
</template>slots: {
type: Array,
value: function() {
return [
{status: 'full'}, {status: 'full'}, {status: 'full'},
{status: 'full'}, {status: 'full'}, {status: 'full'}
];
},
notify: true
}
...
this.notifyPath('slots.'+ index +'.status', 'empty');
Revisemos el código
Revisemos el código
Revisemos el código
pointer-events: none;
CSS
.charger {
transition: transform .2s ease;
}
CSS
.charger.move-0 {transform:rotate(0deg);}
.charger.move-1 {transform:rotate(-60deg);}
.charger.move-2 {transform:rotate(-120deg);}
.charger.move-3 {transform:rotate(-180deg);}
.charger.move-4 {transform:rotate(-240deg);}
.charger.move-5 {transform:rotate(-300deg);}CSS
if (this.mgScenario.getShoots() < 6) {
this.computedClass = 'charger move-' + this.mgScenario.getShoots();
}
La primera animación tiene lugar cuando un enemigo aparece en la pantalla
Si el jugador no ha disparado a este enemigo
.enemy-container {
position: relative;
height: 180px; /* double of 90px */
width: 70px;
overflow: hidden;
transition: z-index linear 0.4s;
}.enemy {
position: relative;
height: 100%;
width: 70px;
opacity: 0;
overflow: hidden;
background-size: 70px 90px;
background-repeat: no-repeat;
transform-style: preserve-3d;
}<div class$="{{computedContainer}}">
<div class$="{{computedEnemy}}" >
<div class="head" on-click="shootOnHead"></div>
<div class="body" on-click="shootOnBody"></div>
</div>
</div>CSS
CSS
@keyframes show-slide-animation {
0% {
opacity: 0;
top: 40px;
}
10% {
opacity: 1;
}
100% {
opacity: 1;
top: 0px;
}
}
@keyframes hide-slide-animation {
0% {
opacity: 1;
top: 0px;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
top: 70px;
}
}CSS
CSS
.enemy.show {
animation-name: show-slide-animation;
animation-timing-function: cubic-bezier(0,0.63,0.58,1);
animation-duration: 0.4s;
animation-fill-mode: forwards;
}
.enemy.hide {
animation-name: hide-slide-animation;
animation-timing-function: cubic-bezier(0,0.63,0.58,1);
animation-duration: 0.3s;
animation-fill-mode: forwards;
}CSS
Cuando un enemigo es disparado se reproduce una animación 3d
Vista frontal
Esquema lateral
70px
90px
.enemy-container {
position: relative;
height: 180px; /* double of 90px */
width: 70px;
overflow: hidden;
transition: z-index linear 0.4s;
}.enemy {
position: relative;
height: 100%;
width: 70px;
opacity: 0;
overflow: hidden;
background-size: 70px 90px;
background-repeat: no-repeat;
transform-style: preserve-3d;
}<div class$="{{computedContainer}}">
<div class$="{{computedEnemy}}" >
<div class="head" on-click="shootOnHead"></div>
<div class="body" on-click="shootOnBody"></div>
</div>
</div>CSS
CSS
@keyframes kill-flip-animation {
0% {
opacity: 1;
transform: rotateX(0deg);
}
15% {
transform: rotateX(0deg);
}
95% {
opacity: 1;
}
100% {
opacity: 0;
transform: rotateX(90deg);
}
}CSS
.enemy.kill {
animation-name: kill-flip-animation;
animation-timing-function: cubic-bezier(0.57, 1.88, 0.21, 0.57);
animation-duration: 0.6s;
animation-fill-mode: forwards;
}CSS
El objetivo es conseguir un solo HTML con todos los elementos de Polymer
gulp.task('vulcanize', function() {
return gulp.src('./app/elements/elements.html')
.pipe(vulcanize({
inlineScripts: true,
inlineCss: true,
stripExcludes: false
}))
.pipe(minifyInline())
.pipe(rename('elements/elements.vulcanized.html'))
.pipe(gulp.dest('./dist'));
});