Re: Games with Python
Re: Games with Python Rummaging around in some of my previous posts, [here] is one demonstrating a simple menu with Pygame and sounds:import pygame from pygame import mixer import sys class main(object): def __init__(self): #initialize pygame pygame.init() #initialize sound mixer mixer.init() #create display self.window = pygame.display.set_mode([640,480]) #current menu state self.state = 'title' #list of menu/game classes self.menus = {'title':titlescreen(), 'game':game()} #primary update loop while True: #check for key press events for event in pygame.event.get(): if event.type == pygame.KEYDOWN: key = event else: key = None #update and pass key presses and menu state to active menu self.state = self.menus[self.state].update(key,self.state) #update window pygame.display.update() #titlescreen menu class class titlescreen(object): def __init__(self): #load sound self.click = mixer.Sound('sound.wav') #load sound self.enter = mixer.Sound('enter.wav') #load music self.music = mixer.Sound('music.wav') #menu option self.option = 0 #select channel's for better playback control self.channel0 = pygame.mixer.Channel(0) self.channel1 = pygame.mixer.Channel(1) #play background music self.channel0.queue(self.music) def update(self,event,state): #if titlescreen is active and not playing, play if self.channel0.get_busy == False: self.channel0.play(self.music) #queue the music to keep it playing if self.channel0.get_queue() == None: self.channel0.queue(self.music) #if a key has been pressed if event != None: #move up in the menu and play tone if event.key == pygame.K_UP: if self.option > 0: self.option -= 1 self.channel1.play(self.click) #move down in the menu and play tone elif event.key == pygame.K_DOWN: if self.option < 1: self.option += 1 self.channel1.play(self.click) #select a menu option elif event.key == pygame.K_RETURN: #if option is 0 return game state and play tone if self.option == 0: self.channel1.play(self.enter) return 'game' #quit game elif self.option == 1: self.channel1.play(self.enter) pygame.quit() sys.exit(0) #return current state if no changes return state #main game class class game(object): def __init__(self): pass #DEMO: return to titlescreen def update(self,key,state): return 'title' a = main()And [here] is one with a basic client/server model in twisted and pyglet:from twisted.internet.endpoints import TCP4ServerEndpoint from twisted.internet.protocol import Protocol from twisted.internet.protocol import Factory from twisted.internet.protocol import ClientFactory from twisted.internet import reactor from twisted.internet import task import pickle import zlib import random pyglet.options['debug_gl'] = False #primary window/game class class Prototype(pyglet.window.Window): def __init__(self): super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test") self.clear() #server side connected user variable, when someone connects the Echo Class will add itself into it. #then just call self.user.sendData to transmit to the connected user or check self.user.inbox to get data. self.user = [] self.server = None self.client = None #since the Reactor is in control, to properly run the main game loop you have to manually call the clock. #this variable is to keep track of the last time the clock was ticked. self.old_dt = clock.tick() self.fps_display = pyglet.clock.ClockDisplay() #shutdown program gracefully def shutdown(self, result): reactor.stop() #system error shutdown def bailout(self, reason): reason.printTraceback() reactor.stop() #main game loop def update(self): while not self.has_exit: #manually dispatch window events (since twisted reactor is in control) self.dispatch_events() #Make sure events are timed properly while coiterating with network layer. That and tick clock events like the fps counter and game pacing. dt = clock.tick() self.old_dt = self.old_dt + dt #if enough time has passed, update game state if self.old_dt >= 0.025: self.old_dt = 0 self.clear()
Re: Games with Python
Re: Games with Python @magurp244,I'll be glad if you can share some menu and net examples. URL: https://forum.audiogames.net/post/518639/#p518639 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python @6I mean: it's not off topic, entirely.Build a dict like this:keys = { "up arrow": { "on_down": "forward_start", "on_up": "forward_stop" }, # more entries here }Then, once you work out what the key is:event_def = keys[key.name] handler = event_def["on_down"] if key.down else event_def["on_up"] handler = getattr(player, handler) handler(key.down)You pass whether the key is pressed or released to the event handler so you can use the same function for both, then, in the player:class Player: # stuff... def forward_start(self, is_down): # walking forward. def forward_stop(self, is_down): # not walking forwardWith the following obvious extensions, depending on your needs:1. You can use the same function for both, recording whether the key was last down or up on the player.2. You can add a shortcut key to the dict which takes precedence over the start/stop keys, which stands for both, and not have to write them out explicitly.3. You can include modifier state to the function.4. You can make the keys of the dict collections.namedtuple instead of strings, which lets you include modifiers in the trigger patterns.5. You can store/load a file containing this.6. You can wrap the entire thing in a convenience class which has helper methods for all this.7. You can move to a more complex variant that uses a list instead of a dict, so that if you have 3 or 4 actions on the same key where only the modifiers are different, you can stop at the first one and do some additional tracking to deal with conflicts better (but then no audiogame really needs this one).8. You can write some helper decorators that let classes advertise configurable key things they want to expose, with defaults, so that if the player object ever changes to something the player can control like a turret, you can have turret specific keys.9. You can write a parser that handles strings like "ctrl + alt + a" and converts them to the dict, thn give the playere nice editable config files.Obviously this varies depending on your library since how your library represents keys will be different from pygame to pyglet to wx to whatever. So don't expect to copy/paste this and have it work. But the above approach works in any dynamically typed language, and with some preprocessor magic and creativity you can do something similar in C/C++ if you want. URL: https://forum.audiogames.net/post/518390/#p518390 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python @5I mean: it's not off topic, entirely.Build a dict like this:keys = { "up arrow": { "on_down": "forward_start", "on_up": "forward_stop" }, # more entries here }Then, once you work out what the key is:event_def = keys[key.name] handler = event_def["on_down"] if key.down else event_def["on_up"] handler = getattr(player, handler) handler(key.down)You pass whether the key is pressed or released to the event handler so you can use the same function for both, then, in the player:class Player: # stuff... def forward_start(self, is_down): # walking forward. def forward_stop(self, is_down): # not walking forwardWith the following obvious extensions, depending on your needs:1. You can use the same function for both, recording whether the key was last down or up on the player.2. You can add a shortcut key to the dict which takes precedence over the start/stop keys, which stands for both, and not have to write them out explicitly.3. You can include modifier state to the function.4. You can make the keys of the dict collections.namedtuple instead of strings, which lets you include modifiers in the trigger patterns.5. You can store/load a file containing this.6. You can wrap the entire thing in a convenience class which has helper methods for all this.7. You can move to a more complex variant that uses a list instead of a dict, so that if you have 3 or 4 actions on the same key where only the modifiers are different, you can stop at the first one and do some additional tracking to deal with conflicts better (but then no audiogame really needs this one).8. You can write some helper decorators that let classes advertise configurable key things they want to expose, with defaults, so that if the player object ever changes to something the player can control like a turret, you can have turret specific keys.9. You can write a parser that handles strings like "ctrl + alt + a" and converts them to the dict, thn give the playere nice editable config files.Obviously this varies depending on your library since how your library represents keys will be different from pygame to pyglet to wx to whatever. So don't expect to copy/paste this and have it work. But the above approach works in any dynamically typed language, and with some preprocessor magic and creativity you can do something similar in C/C++ if you want. URL: https://forum.audiogames.net/post/518390/#p518390 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python Sorry to go off topic but...@4, would you mind expanding more on avoiding if / else if with handling keystrokes? As in, what other options are there? I wouldn't mind reading more on this topic since if / elif to handle keys in Python was always off for me in terms of cleanliness. URL: https://forum.audiogames.net/post/518386/#p518386 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python Pyglet handles 3D better, but recent work on it also expanded its 3D positional Audio support. It still doesn't take full advantage of OpenAL's abilities though, like HRTF, EFX, etc. For that your better off going with a more audio dedicated library. Pygame is fairly dependable, but has historically been used for 2D projects. You could also check out PySFML as a third option.Menu development depends on how you want to handle it. One way is to keep track of the current menu in your main class, and swap between different menu classes as needed in your update cycle. If you like I can provide examples of this, or other things. Online play, otherwise known as network development, can vary. You can use Python Twisted, of which I have a few examples, or go with Sockets like Asyncio, I think theres a few other libraries around somewhere... If your just starting out, you should know that I would classify Network Programming to be an advanced concept, and that you should have a better understanding of existing concepts of development before attempting it. This isn't necessarily because the individual parts of network programming are hard to understand, but because in order to get the best results you have to be able to write very efficient code which can scale, handle desynchronization, latency, packet loss, authentication, failure states, and malicious handling, etc. URL: https://forum.audiogames.net/post/518383/#p518383 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python Pyglet is Pygame minus a bunch of stuff, but plus a bunch of stuff if you care about OpenGL.@3 is right: Pygame code can look good depending on the professionalism of the developer. Also, if you find yourself in the position of importing pygame into every file and having giant if blocks that handle keystrokes, that's a you problem, not a pygame problem. Even with Pyglet you end up figuring out how to route key events to game objects anyway. URL: https://forum.audiogames.net/post/518270/#p518270 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python @kianoosh,Although in general, your code looks more sorted in pyglet rather than pygame.No. It depends on the professionalism of the developer. URL: https://forum.audiogames.net/post/518183/#p518183 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Games with Python
Re: Games with Python 1: I would personally go with pygame. I used pyglet, and I experienced latency issues and found no fix for that. Although in general, your code looks more sorted in pyglet rather than pygame.2. It really depends. Menues are lists after all. Now what matters is the way you want to handle them. The thing is, that many of the functions that pygame, pyglet and other such modules provide are not suitable for audio game development as they're usually inaccessible to the end user.3: I personally found podSixNet to my liking. It's really interesting to use, gives you enough info to get a good grip of your game, and is pretty much lightweight and more importantly, podSixNet is designed to play its roll in multiplayer games so that could be what you're looking for as a game developer. There are other choices like twisted too but not as lightweight.Last but not least you can try frameworks that make your life easier in audio game development, something like lucia which has pretty much all you need except for complete network handling.Check out this topic:https://forum.audiogames.net/topic/3107 … in-python/ URL: https://forum.audiogames.net/post/518174/#p518174 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Games with Python
Games with Python Hello.I saw topics here about choosing a programming language. But I think so. will not try, will not know.My main programming language that I use is Python. I have seen SoundRTS and other games, and have not very good impressions about it. But I should try.Dear Python developers, I'd like to receive your recomends on developing games with Python.1) What libraries to use? Pygame, Pyglet or another? What is the difference between Pygame and Pyglet?2) Can you share some examples? How do you make menus and other things?3) Online games. What libraries do you use for network?Thanks. URL: https://forum.audiogames.net/post/518152/#p518152 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Programming incremental offline games using Python
Re: Programming incremental offline games using Python Sure, it's possible. As for doing it, you do it just like anything else. Create classes, figure out numbers (The difficult part), come up with the content... I feel like for those types of games more goes into balancing them and less goes into coding. URL: https://forum.audiogames.net/post/432029/#p432029 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Programming incremental offline games using Python
Re: Programming incremental offline games using Python Someone released a cookie clicker game in BGT.I'm not sure where it is, but I think it's the same developer who released your adventure. URL: https://forum.audiogames.net/post/431993/#p431993 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Programming incremental offline games using Python
Re: Programming incremental offline games using Python Yeah, it is possible in virtually every language, even the shitty BGT URL: https://forum.audiogames.net/post/431945/#p431945 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Programming incremental offline games using Python
Re: Programming incremental offline games using Python Incremental games are known, as clicker games, or iddle games. URL: https://forum.audiogames.net/post/431938/#p431938 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Programming incremental offline games using Python
Re: Programming incremental offline games using Python What do you mean by incremental? Its perfectly possible to write offline games, and to gradually work on them, though without an online update system it would involve people downloading the latest version, which still a thing in a number of places. URL: https://forum.audiogames.net/post/431936/#p431936 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Programming incremental offline games using Python
Programming incremental offline games using Python Hi!I have a question. Can We programm an incremental games using Python, or not?How can We do that?Thank You.Marco URL: https://forum.audiogames.net/post/431931/#p431931 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python Hi Mohammed.I forgot if you have the latest version of python 2 or are using python 3, you can install these libraries using pip (python installs packages). It makes things ten times easier. If the libraries are on PyPi they will install no problem.Hth. URL: http://forum.audiogames.net/post/402746/#p402746 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: learning to code games with python
Re: learning to code games with python thanks guys! you got me going on learning!i really like a bite of python URL: http://forum.audiogames.net/post/402194/#p402194 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: learning to code games with python
Re: learning to code games with python Hi.Yes books like think python are good, and they are free besides. You just need to grab a code editor, notepad2, notepad++, EdSharp, to name a few. Pick which ever one suits you. You could use visual studio too, but if you are only planning on learning python for now I wouldn't recommend doing that, visual studio has python support, but it's a lot to handle if you just want to do simple python programs.Personally I would recommend EdSharp, it is very accessible and easy to use. It has support for python as well as a few other languages, and it tells you what indent level you are on when you do that. If you started at level one, your screen-reader will let you know that. EdSharp has built-in support for NVDA but if you are a JAWS user, it will install the EdSharp JAWS scripts for you during the install. Just google EdSharp, you will easily be able to find the developer's github page.Hth. URL: http://forum.audiogames.net/post/402059/#p402059 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: learning to code games with python
Re: learning to code games with python As pointed out by Guitarman, Python is the core of the language and has basic fundamental functions and tools for creating logic and actions, as such you should start with that. Pygame and its ilk are Libraries, which provide more functions for specific tasks, like creating a window, keyboard and mouse handling, playing sounds, physics, machine learning, etc.I would suggest books like [Think Python], or [A Byte of Python] to get started. Then you could follow up with libraries like Pygame, Pyglet, and Tolk. Also, I have a number of OpenAL examples for working with advanced audio available in a repository [here], if your interested. URL: http://forum.audiogames.net/post/402056/#p402056 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: learning to code games with python
Re: learning to code games with python where should i learn URL: http://forum.audiogames.net/post/402052/#p402052 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: learning to code games with python
Re: learning to code games with python Hi.Well you should first learn python if you haven't already, then you can start learning things like pygame and soundlib and things like that. When you have an understanding of python, then you can jump right into game development. URL: http://forum.audiogames.net/post/402037/#p402037 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python you may be right URL: http://forum.audiogames.net/post/402035/#p402035 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python Hi Mohammed.Demanding an answer fast is not the best way to get them. To get all these things is simple google it. If you really want to be a programmer, you will have to do this a lot anyway. If you really have trouble finding these things I will post links, but I think it would be good for you to do this yourself.Hth. URL: http://forum.audiogames.net/post/402034/#p402034 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python I know.I developed my website also.programming maybe crazy for sometimes but I like it URL: http://forum.audiogames.net/post/401950/#p401950 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python as a programmer, you need to be paishent programing can be great, but it can also be frustrating URL: http://forum.audiogames.net/post/401949/#p401949 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python hello? I want quick answer please URL: http://forum.audiogames.net/post/401936/#p401936 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
learning to code games with python
learning to code games with python hi there! i wish to learn to code games with python, i am wondering should i learn python or pygame, and where to learn it, i presume pygame, but i'm not sure. Thanks URL: http://forum.audiogames.net/post/401932/#p401932 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python from where I can get all this? URL: http://forum.audiogames.net/post/401738/#p401738 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: what is the best way to learn how to create audio games iN python
Re: what is the best way to learn how to create audio games iN python Get accessible_output2, sound_lib, and optionally game_utils. Study the code and check out Paul Iyobo's modules if you want to do maps or encrypted sounds in python. (There's also Mason Armstrong's game engine, but it's designed for BGT and you'll have to write your own wrapper.) Also, VS Code. URL: http://forum.audiogames.net/post/401735/#p401735 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
what is the best way to learn how to create audio games N python
what is the best way to learn how to create audio games N python hello I want the best and easier way to learn how to create audio games in Python URL: http://forum.audiogames.net/post/401722/#p401722 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector