Lessons learned
Que piensa la gente cuando piensa en videojuegos
(uncharted, battlefield)
Sudden realization: sé programar
// ...
mounted () {
eventBus.$on('gameStatusChange', this.handleGameStatusChange)
this.startGameLoop()
},
beforeDestroy () {
this.resetGameLoop()
},
methods: {
startGameLoop () {
// to be overwritten by component
},
resetGameLoop () {
clearTimeout(this.loop)
this.loop = null
},
handleGameStatusChange (isPaused) {
if (isPaused) {
this.resetGameLoop()
} else {
this.startGameLoop()
}
}
}
SetTimeout y SetInterval
// Stats.vue
methods: {
...mapMutations(['decrease']),
startGameLoop () {
this.decreaseStats()
},
decreaseStats () {
const decreaseInterval = 12 * 1000
this.loop = setTimeout(() => {
if (this.isActive) {
// decrease all stats
this.decreaseStats()
}
}, decreaseInterval)
}
}
// DaysCounter.vue
methods: {
...mapMutations(['increaseDayCount']),
startGameLoop () {
this.startDayTimer()
},
startDayTimer () {
const day = 1000 * 60
this.loop = setTimeout(() => {
if (this.isActive) {
this.increaseDayCount()
this.startDayTimer()
}
}, day)
}
}
No son 100% precisas
The time, in milliseconds (thousandths of a second), the timer should wait before the specified function or code is executed. [...] The actual delay may be longer than intended.
...
12
12
12
12
12
55
Days
Days
Por turnos
Todo en el store!
(o casi)
Form elements
Cosas que me gustan
Cosas aprendidas
Cosas por aprender
Aventura gráfica con aspectos de survival
WIP