Python Forum
Designing a "game" loop api - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Designing a "game" loop api (/thread-27454.html)



Designing a "game" loop api - pitosalas - Jun-07-2020

I would like to create a structure sort of like "Processing" in Java, where someone writes a short python script with the following structure:

import mygamelib

def setup():
  ... do stuff that happens once

def loop():
  ... do stuff that happens repeatedly in a loop
And the contents of mygamelib - which I am writing - causes the setup function to be called once, and the loop function to be called over and over again. And I would like it to look exactly as above. I know that if I allow the adding of more variables, or change it into a while loop I can achieve functionally the same but my design requirement is that it is as simple as above.

How close can I get to that goal?


RE: Designing a "game" loop api - deanhystad - Jun-07-2020

I don't see any reason why your design cannot be implemented in Python. You may want to make it a class so things you make in setup are visible in loop.


RE: Designing a "game" loop api - pitosalas - Jun-07-2020

Let me clarify. mygamelib is a package I am writing, to make it easy to write simple games. It is built on top of pygame. It will be much more limited than pygame. My goal is that the "game designer" (probably someone new to programming) write the simple most script. My goal therefore, modeled after the arduino and after "processing" is that the "game designer" write a script that looks just like what I had in my OP. No classes or definitions and only two pre-defined methods.

In the setup they function they might have access to some built in functions like boardsize(30,30) and boardcolor(blue).

And in their loop function they might have calls to print("it's your turn!") etc.

Does that help?