MimsH.Wright
FreelanceSoftwareDeveloper
hallo@mims.berlin
@mimshwright
github.com/mimshwright/
Mimstris:
Building an arcade puzzle
game in React / Redux
Why?
How?
What?
ChoosingtomakeTetris
Challengesofcodingagameinreact
Takeawaysfromtheexperience
Why?
Thatsoundsfun

•Playwithmyson
•Makecrazyshapesandstuff
•Tryoutsomenewframeworks,etc.
JavaScript circa 2014
const game = () =>
NeedstobeES2017
cuzit’s2017,obvs.
Reductris
I’llcallit…
👈
Reductris
Reactris
I’llcallit…
Reductris
Reactris
Mimstris
I’llcallit…
How?
1.
2.
3.
Buildingthegame
Renderingtocanvas
TheReduxStore
1.
2.
3.
Buildingthegame
Renderingtocanvas
TheReduxStore
board = [
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 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 0, 0, 0 ],
]
“GameLoop”
init()
update()
draw()
every frame
•Timingofpiecemovement(timesincelastupdate)
•Respondingtouserinput(seepressedlater)
•Piecematrixpositionandrotation
•Collisiondetection(foreachsquare,iftheyarebothnon-zero)
•Clearinglines(Ifawholerowisnon-zero)
•Scorekeeping
•Configuration
Insideupdate()
PushMethod(event-driven)
PullMethod(polling)
Pressed.js
Ihadaproblem.
Isawtherewereseveralgoodsolutions.
Imademyownthatwassliiiightlydifferent.
pressed.js
Trackswhichkeysarecurrentlypressed
1.
2.
3.
Buildingthegame
Renderingtocanvas
TheReduxStore
init()
Before React
update()
draw()
init()
update()
react
draw()
every frame every frame
componentDidUpdate()
render()
React + Redux
init()
update()
redux
store
react
draw()
every frame
componentDidUpdate()
subscribe() / connect()
dispatch()
canvasRenderer.js
drawGame(board, piece)
clear()
drawMatrix(board)
drawBlock(x,y,color)
drawMatrix(piece)
drawBlock(x,y,color)
1.
2.
3.
Buildingthegame
Renderingtocanvas
TheReduxStore
What?
Takeaways…
• Babel / ES6
• React
• Redux (incl. reselect, redux-acitons, etc.)
• Ducks
• Lodash
• Writing an npm module
• Mocha, Chai, Tape, AVA
• Atom
ThingsItriedforthefirsttime…
😍ES6 😍
Configfiles!
•rendering
•matrixmaths
Usemodulestohandleisolatedfunctionality
Makesitmucheasiertorefactorlater
Weirdpiecesarefunbutthey’renotinthegameforareason.
•Actions
•ActionCreators
•Reducers
•Selectors
Ducksisaguidelineforcombining…
…intoasinglefile.
(Askmeabout boilerplate-reducer)
Ducks.
Stresssaver
justworks.
DrawingtothecanvasinReact
Unittestearly…foryoursanity
arobotwhois
clickingonthings
update()is
Memoize!
Make a thing for fun.
mimstris.surge.sh
github.com/mimshwright/mimstris
MimsH.Wright
FreelanceSoftwareDeveloper
hallo@mims.berlin
@mimshwright
github.com/mimshwright/

Mimstris: Building an arcade puzzle game in React / Redux