Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Designing a "game" loop api
#1
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?
Reply
#2
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.
Reply
#3
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  While loop not ending (Best of 10 dice game) K3nidi 3 1,485 Jul-09-2022, 09:53 AM
Last Post: K3nidi
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,231 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  loop adventure game ilikedofs 1 1,699 May-26-2021, 12:43 AM
Last Post: bowlofred
  Help in designing a timestamp finder for chapter-less TV shows Daring_T 1 1,850 Oct-26-2020, 09:30 PM
Last Post: Daring_T
  Designing Hangman game spacetimeguy 2 5,116 Feb-02-2018, 08:55 PM
Last Post: spacetimeguy
  Need help designing a multi-threaded solver 4Dummies 8 6,051 Jun-18-2017, 08:39 PM
Last Post: 4Dummies
  loop doesn't advance-py3 text game foxtreat 2 3,564 Jun-08-2017, 06:41 AM
Last Post: foxtreat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020