I'm not sure that it is possible to use a Pdf this way.
But, even if it is possible, it feels so wrong.
Pdf has been created to provide a good way to bring your job to a print shop. And it's very good at this task.
The Pdf format has been expanded to support interactive forms. That was a big stretch and history has proven that it was not such a good idea. But it somehow works.
Creating educative games in Pdf, that goes in my eyes way too far (if you're not part of a collective experimenting with diverting technology!)
Have a look at Scratch, Qml, Appinventor, Mu-Editor / Py-Game Zero, ... or Vue.js.
... sadly, what i consider the best tool to create such programs has disappeared many years ago: Hypercard.
(and nobody could create a new modern alternative)