#game-development
1 messages · Page 20 of 1
I already have overlap conditions for entering internal rooms. Each internal room object has a collision rect constrained to its rect.center, if this rect overlaps any wall tiles, the object cannot be entered
Since exiting the object places player at object rect.center, if that portion of the object is overlapping tiles, it can dump player into a completely surrounded collision
So I needed a check for it
So I'll need to get both of those working together, need another condition
Time to put the overlap code into its own method, so it can be called from that moveUP() method
I suppose I could actually break that iteration when assigning True to overlapping
Had an incident worth documenting:
with Pyglet, when you let objects go out of scope in a game loop, make sure they are entirely deleted from texture memory so they don't get accidentally GCed during the draw process, or the draw process will crash.
This turned out to be a side effect of some bad object management on my part.
Falalalala, yes. Is this a ban speedrun?
Okay, what administrative need to you have pertaining to game development?
I changed all my gates to use the wider stems and ports too, I like it
Overriding the .wide attribute, so we can ignore all the elses in the draw() method, I might use them again though, leaving them in https://paste.pythondiscord.com/7GKA
If I do end up using them again, I'll refactor the narrow stems creation
I'll likely never use them again, the wider images are easier on the eyes
Time to ctrl cv the code folder and delete them
Very satisfied with how they animate current flow now
I have so this is as close to the corner that robot can be and still allow entry
No way one could use a robot to 'tunnel' through a wall or even into one
Also, robots won't move if any more than their bumpers are touching a wall
So that robot, even if he thrusts, won't move
Is the project a folder with a few files? Use VSCode's File menu > Open Folder, browse to and select that folder instead of opening the files within the folder, this will open all files in the folder and set the working directory to that folder
Or work out the ../ path name and load it from where ever it is
I usually have a file structure as such, with Assets next to the code folder which contains all the .py files and open the code folder is VSCode. From there, I can get my assets with ../ like so...
But only because I open the code folder in VSCode instead of a file
Btw, for anyone interested in those functions, one must from os import walk to get walk
my project starts with a nice file structure, but ad testing goes on I end up with a file named like V6 lol
Right on, I always ctrl cv my code folder periodically, so end up with sometimes dozens of backups
The Droidquest project has loads of files and stuff, it's huge by my standards
I haven't counted total lines but gotta be near 25k
So keeping a clean file structure is important, and avoiding circular imports
I usually have one file in my folder, this one called lame.py, just to test whatever things I need....to test
Over 200 occurrences of 'class ' in Droidquest
And tons of inheritance
Almost everything has Item(pygame.sprite.Sprite) first in the mro
Yeah , once I make my tower game, I'm gonna use like atleast a Gig of storage for backups lol
25k lines os crazy
biggest program I made was like 3k lines across 3 files for a networking IRC server
Okay, so I tried using the pygame detection using the built in collide_circle method, and it is extremely slow compared to using a rectangle and checking for yourself
just so you know
im not sure why tho
def collide_circle(left, right):
"""detect collision between two sprites using circles
pygame.sprite.collide_circle(left, right): return bool
Tests for collision between two sprites by testing whether two circles
centered on the sprites overlap. If the sprites have a "radius" attribute,
then that radius is used to create the circle; otherwise, a circle is
created that is big enough to completely enclose the sprite's rect as
given by the "rect" attribute. This function is intended to be passed as
a collided callback function to the *collide functions. Sprites must have a
"rect" and an optional "radius" attribute.
New in pygame 1.8.0
"""
xdistance = left.rect.centerx - right.rect.centerx
ydistance = left.rect.centery - right.rect.centery
distancesquared = xdistance**2 + ydistance**2
try:
leftradius = left.radius
except AttributeError:
leftrect = left.rect
# approximating the radius of a square by using half of the diagonal,
# might give false positives (especially if its a long small rect)
leftradius = 0.5 * ((leftrect.width**2 + leftrect.height**2) ** 0.5)
# store the radius on the sprite for next time
left.radius = leftradius
try:
rightradius = right.radius
except AttributeError:
rightrect = right.rect
# approximating the radius of a square by using half of the diagonal
# might give false positives (especially if its a long small rect)
rightradius = 0.5 * ((rightrect.width**2 + rightrect.height**2) ** 0.5)
# store the radius on the sprite for next time
right.radius = rightradius
return distancesquared <= (leftradius + rightradius) ** 2
It seems fast
My code using a rect and checking angle, versus thier circle method
this is game dev, but you need to delete line 4-7. And then assign a+b
I guess that makes sense because rects don't need any distance checks
[0.45833669998683035, 0.4615948999999091, 0.4721016000257805, 0.4676309999777004, 0.46541229996364564]
[0.06254219997208565, 0.06156130007002503, 0.0633681999752298, 0.06414100003894418, 0.06397799996193498]
``` Mines faster ☠️
All because I do an intial check
if pygame.sprite.collide_rect(sprite_1, sprite_2):
btw, you're not supposed to use that function like this, but whatever ig
also sprite_1.rect.colliderect(sprite_2)
ah, thats What I have in code actually. I'm not sure why I wrote that
@limber veldt would you mind running some code real fast for me and seeing if you get the same speed difference?
Not at all, I'm just running a decent laptop, let's see
ah its like slightly too big..1 sec
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
the bottom is faster by like a factor of 7 lol
I feel like im doing something wrong
My values [0.40089050005190074, 0.38983520003966987, 0.40523919998668134, 0.4458810999058187, 0.41937420004978776] [0.05229899985715747, 0.050902700051665306, 0.05090170004405081, 0.04992869985289872, 0.051856900099664927]
yeah same
or close
to the same ratios
all thats different is a tiny check
if not left.collide_rect(right):
return False
idk. Im not seeing how the performance tanks so bad by not having this
its averaging at a 9.5x decrease in time
just pushed a pull request
Added a little debug menu thing. Not really a "menu" since the buttons are hardcoded. But its good for now
hey,
I have been trying to make a game where I want to display some texts
but the thing is that I want it in such a manner that when the player presse spacebar the next text/message should come
I have created a list with all the texts in it
can anyone help me how to achieve that thing
Always helps to have debugging of some kind. Sometimes I send a debug attribute or variable to everything
That can be kind of complicated but work through it one step at a time. First get your spacebar incrementing some counter, this will be used as an index into your list of texts. Learn to display any text in whatever engine you're using, eventually displaying the text referenced from your list using the index
For me using pygame, I would probably pre-create a list of font.render() surfaces using my list of strings (the texts) and display those according to the index, avoiding creating a bunch of surfaces during the main loop
hello, anyone here know about wave function collapse? I don't get this picture on how it was propagated, at first I thought it was easy but I didn't know there's also a thing called entropy, is there more that I'm missing? or its only the entropy?
Each gridspace has an associated probability distribution for the possible tiles based on neighbours,
And probability distributions have associated entropies you can calculate
@burnt dawn
Not sure if that fully answers your question or if I've misunderstood
oh thanks, that helps
It's this entropy, btw https://en.m.wikipedia.org/wiki/Entropy_(information_theory)
It's actually super simple to calculate for a discrete distribution like this: sum the probability * log probability of each tile
oh nicee, but idk math soooo 💀, I don't even know what this means
wait are u telling me I need to know the math about wave function to be able to implement it?
it's basically saying
H = lambda X: -sum(p(x) * math.log10(p(x)) for x in X)
Not necessarily, but it's easier if you do IMO :p
https://youtu.be/rI_y2GAlQFM?si=Jt54cndpFZtqSFds
The coding train has a full tutorial in Javascript.
At 8 mins, he explains thr concept and the math related
Straight out of quantum mechanics, Wave Function Collapse is an algorithm for procedural generation of images. In this video (recorded over 3 live streams) I attempt the tiled model and explore a variety of solutions to the algorithm in JavaScript with p5.js. Also, check out WFC's predecessor: Model Synthesis (more info below). Code: https://the...
Inside my blue robot compared to the 'original'
Just finished refactoring all my objects that were using the old port stem objects to use the new ones
That got rid of 400+ lines of code between a few objects
Now everything with a port and a stem is using instances of the same object
Just different types
With the old stems, I was creating sprites for them, adding to a group and drawing the group. The new ones are being blitted directly on the device's image
Easier to deal with the objects now. Like I don't have to move their port and stem objects between rooms when player carries them into different rooms, they're self contained objects
Ah I see you also made a slider and a button for speed and Remote
Yeah, the original just used keys to change the settings with no indicators
wait, why are there 2 screens
Cept the antenna appearing over player head when remote is on
Running my game and the original game on top of it, then screenshot
ah nice
My rooms have more resolution in the grid size, the og had 20x12 tile rooms, mine has 24x15
This grid defines my robot rooms
Then of course, the items are added to it, the bumpers and thrusters and things
I, not too long ago, updated my python from 3.9.5 to latest, really enjoying the match/case statements. But I wonder if there is any substantial speed difference
I did some stylized tiles in some early versions, eventually changed to just plain colored tiles
Objects with internal rooms inside internal rooms inside internal rooms...and so on
I wonder if nesting a thousand of them would throw a max recursion error
hi guys i wanna make a game in pygame, but i need to know what protocol should i use for tha lan multiplayer ?
anyone to help me
@limber veldt idk I gave up
Imm take a break from coding idk who the hell made vs studio code but they sure make it hard to change a simple directory
might just delete vs studio code and restart on a different one
ill probably actually juse use the standard python idle
That's unfortunate
Check out this handle and train object, both of them are instances of Player and actually change the levels current player to themselves
https://paste.pythondiscord.com/HW3A the can_be_picked_up() method swaps the player
So like the player doesn't necessarily pull the handle, the handle becomes the player and picks up the actual player then moves
Nevermind my purple background flipflop, makes it easier to debug the image and ports
I just did a renaming and bit of refactoring session that feels soooo good
I had too many uses of the word 'Port', sometimes as Port2, ExternalPort, Portal, whatever, that gets confusing when one of my files has 300+ occurrences of the word
My stem objects are now called Stem and referenced as .stems, not to be confused with the port objects referenced as .ports
Wonderful, what was the problem?
I was able to get my player animated which was actually very hard becuase I using opp to do it and I honestly have never used object orientated programming
So many advantages to using a proper IDE
it was the fire directory but instead of using > I used :
file*
now I don't know how to bring my player down to floor level in a class
You need him to be down with those bushes
yea
I just don't know how to implement it with opp I tried just bringing him down but it just gave me a error
there has to be a way to do it I just suck and don't really understand computer logic well
If you'd like to share the part of code where you're placing the player, go ahead, maybe someone can see something to fix it
I closed my ide but tomorrow i'll be sure to do that
Ok, that's fine, good enough for now
A lot of really small steps to learning a lot of this stuff, just takes time and practice, practice, practice
ty
np
I made something
do you plan to release your game for sale?
No, but will eventually post to github
awesome, it looks fun to play :D
It's such an ambitious project for me, I really feel like I should get it a little better than it is before sharing, but I'm making good progress lately
is it based on a game you used to play?
Yes
Robot Odyssey, originally released by The Learning Company in like 1985. Then rereleased as Droidquest in 1999 or so, ported to Java
That source code is on github https://github.com/ThomasFooteDQ/DroidQuest
He did great at it
My python version is basically that ported to python and pygame
I have built from that source, but I'm not sure it will build with recent SDKs
Cool! do you plan to add multiplayer, or do you want to keep it as faithful as possible to the original?
No, I don't plan to, but it might be a cool feature
My version vastly improves the interface with modern controls
considering the distinction between camera and world in openGL
would it make sense to think of it as: the camera doesn't move, the world moves around the camera?
Another tutorial level populated
My level objects inherit so the levels themselves have only the init() methods to define the rooms, all other methods are from BaseLevel()
One or two out of the 17 or so levels, has an extra override or two
The antenna objects, those which send and receive signals from other antennas inside other robots, share a common channel. If one is broadcasting, they all receive the signal. I'm thinking give them a channel selector so they can talk in private
It'd be easy to implement since they all 'broadcast' True values to the same list in the main.py and at the same index each time, like the blue robot only sets list[2] to True and so on
The other robots are currently using any() on that list but that's not a problem to change
I'd probably just give the antennas additional ports, one input and output for each channel
One could come up with some really smart puzzles with that functionality
Is python game dev just pygame or is there something more
There are many python game libs, pygame, pyglet, Ursina, Panda3d, Arcade, to name just a few
Some, like Godot, use a very similar to python language
Maybe I make a new object, an antenna transceiver with a button that can cycle all four robot colors and whatever color it's set to is the color of the robot it hears or talks to
Oh well, that's features, I have one more level of content to populate, about 20 more rooms
Another tutorial level 'Circuits'
if any1 wants to waste time downloading my terrible game, you should
https://github.com/dcjvliet/Duotrigordle
I didn't play it yet but it looks well written
And I finished populating the last level, now I can play with features
Cleaning up the imports. When I first started writing these levels, I just imported everything into all of them, they don't need everything
So they a little better now, one of levels
And I see why * imports are generally bad
One, because you get everything that module imports too
And two, they're unreadable
thx
there should be less empty lines there tbf
Okay
And both imports from settings should be one line
I'm still fairly new to all this inheritance stuff, so still learning, and I love it
My last few projects have quite a bit of it
It's all about categorizing my objects. all enemies should have a BaseEnemy, all devices a BaseDevice and things like this. That way they can all share functionality from the Bases
Is something like this better, somewhat organized?
yep, I'd say it's def easier to read, some more structure to it
now, if speaking PEP 8, I'd do
json
random
tkinter
pygame
the
rest
of
them
but yk, not forcing it or anything, lol
(as if I could)
i follow this order:
__future__typing,collections.abcsys,builtins,osand other low-level stuff- rest of stdlib
- 3rd party
- my modiles
I just let isort order them, and it follows pep8 (3 groups (builins, third-party, modules within package itself) and alphabetical within a group).
in rare cases have to be careful if import order matters for functionality with that though
nonetheless a very cool tool
No no, of course not, but I want to have a good structure, it needs to be clean-ish for me
The shortcut paths through all of the tutorial levels is complete
damn how many imports XD
Well, there's 200+ items, from rooms, to levels, to devices, to robots, tryna keep them organized
In about 35-40 files
i always do :
import <stdlib module>
import <stdlib module>
from <stdlib module> import <stdlib thing>
import <third party module>
import <third party module>
from <third party module> import <third party thing>
from <file of my project> import <thing of my project>
from <file of my project> import <thing of my project>
from <file of my project> import <thing of my project>
Radio channel selectors done
So you do one line for each thing?
Okay, gotcha
aside if its from module import x, y, z, w
but the important point is the newlines
i make 3 blocks
Makes sense
you want me to reorganize this
Sure, let's see how you would have them
can you give text version
One sec...
powertoys is mid
These are bound to change but look at this mess https://paste.pythondiscord.com/XPYA
I'm going to change to importing the levels during the method to set the level instead of importing all of them
Yeah
So the Levels folder should be lowercased?
yes
Okay
don't uppercase folder names
And ChipStuff folder as chip_stuff instead?
Right on, thanks
Easy to change
Especially now that I've cleaned up most of the import sections
It is a work in progress and I really appreciate the input
import json
from os import walk
import pickle
from random import random, choice, randint
import sys
import pygame
from pygame import Vector2 as vec2
from tkinter import Tk
from tkinter.filedialog import asksaveasfilename, askopenfilename
from devices import ANDGate, NewPen, NewSwitch2, XORGate, NOTGate, ORGate, NANDGate, NORGate, XNORGate, BUFFERGate, FLIPFLOP, NODE2
from items import EvalButton, PaintBrush
from robots import NewBlueRobot, OrangeRobot, WhiteRobot, RedRobot
from settings import EDITOR_DATA, Colors
from support import Timer
# Newline maybe
from ChipStuff.stems import Stem
# Newline maybe
from Levels.level_lab import LevelLab
from Levels.level1 import Level1
from Levels.level2 import Level2
from Levels.level3 import Level3
from Levels.level4 import Level4
from Levels.level5 import Level5
from Levels.level6 import Level6
from Levels.level_robots import LevelRobots
from Levels.level_wiring import LevelWiring
from Levels.level_sensors import LevelSensors
from Levels.level_toolkit import LevelToolKit
from Levels.level_circuits import LevelCircuits
from Levels.level_teamwork import LevelTeamWork
from Levels.level_design import LevelDesign
from Levels.level_endgame import LevelEndGame
from Levels.level_main import LevelMain
from Levels.level_test import LevelTest
# Newline maybe
from PathFinder.pathfinder import PathFinder, DiagonalMovement
you really have a lot of imports from your files
so separating them a bit could be a thing (at least the things from different folders)
Yeah, the Level2() object, for instance, all of them really, are just room definitions and item population for Level() to run and DQ.py to set
is everything initialized at once like this too
Uhhh can u guys help me
So I think all those level imports can be in the set_level() method
like initializing all levels at once is probably not required
Right
don't dm already bruh
WAIT
you don't have to load all objects at once too
just load whats required for the level
maybe its a small game but for a larger game you can't load everything
I do for that particular file because it handles the toolbox, from which the devices are added
But yeah, I know what you mean. I still have some cleanup for these imports
Just dm me when ur wanting to help
Ok
don't tell HELP ME and don't dm
I did get a pygame oom error earlier, too many Surface()
HUH
how much exactly
and and all the level stuff creating surfaces and stuff
your ram has one too 
you can't just load everything
I know
And it's the levels that are eating it up
because just one level needs to be loaded at once
you need to code something to unload them as well
They create, in some cases, more than 100 font.render() surfs
100 surfs is nothing tho
But for that many levels, and some even close to 200 surfs, it adds up
Wait
you can have thousands of them
I changed my Text2() object to not use .convert_alpha()
it gives me a error
tell error bruh
import os
os.chdir(r'')
for f in os.listdir():
f_name, f_ext = os.path.splitext(f)
f_title, f_num = f_name.split("-")
print('{}-{}{}'.format(f_num, f_title, f_ext))```
i have the path
So yeah, that will probably be my next bit of refactoring, loading levels on-the-fly so to speak
first don't use any absolute path like this
the error is that
no
the error isnt provided
python tells you an error message
about what's not working
ValueError: not enough values to unpack (expected 2, got 1)
8
its the split
so how do i fix it
how
because there's not always a - in the string
f_title, f_num = f_name.split("-")
if f_name is "banana" the split will just have one value which is "banana"
and you CAN'T put it in 2 variables
bro how do i fix it
if your string is "ban-ana" you'll have "ban" in f_title and "ana" in f_num
but if value count isnt 2 then your code isnt valid
if the string is always intended to have a - then you're getting the wrong string
print it to see
example: I have C #3
i want the #3 C
idk what this means
u want me to print f_name?
print it in the loop
to see its value
because the problem comes from here
you're expecting a string with a - in it
if you don't understand this that means you don't understand your own code
overusing this can lead to mid code tho
I wanna do it just for those levels
No, there are also portals that lead to that level
i mean is your program one file
and you're doing everything in the pygame event if statement
No
i make a class to abstract pygame events
that i use in classes representing my game states
i use a class like this for states
with simple accessors for each part of the "engine"
Changed in set_level()
also its not a very good way to handle levels ngl
How else?
instead of hardcoding classes for levels you should have something like a json file
It's a great way to handle portals
to load as much levels as you want
Becase in the portal object, I can define the .next_level and read that in main
a level should be a json or pickle or something else file
not a code file
the level can have an id and you can use it from the code
That's an idea but pickle can't pickle surfaces
to_string()?
but just use image name
Right
Something I haven't yet exploried
I'm also drawing with pygame primitives many of my images

So there isn't a lot of image loading, but still some
Right
levels don't contain assets they use them
In my case, Level() uses them and levels define them
even assets like string could be elsewhere and loaded by the asset manager (so you can easily handle locales for example)
i'm saying most serious games nowadays dont have a Level1() class or a Level2() class
yo
My level objects are just __init__() methods
so what i need to do?
i told you
print f_name to see what it contains
because the issue comes from there
but looks like you don't understand your own code ngl
is it written by you
Always print things, man
ye but not all
First thing to do when something goes wrong, print your values
try to read about the split() function
you definitely don't understand it
do you know what unpacking is too
uhhh to unpack the things
you dont 
bro cant help than just say u cant
So should I do a del current_level before instancing the new level?
i can
i totally understand what your code does
but you don't understand it
dont gotta make fun of a new coder
i don't make fun bruh
but as an experienced coder i can definitely see its not your code
or maybe you made it 6 moths ago
than can u just help
at the end??
ok
ngl you should work on something easier
i did print it
Making json out of all the room layout defs in the levels would be a good start, I think
it says C #3 which is a txt in my file
so the string contains "C #3"
thats not possible
splitext is for file name and extension
a file name CAN'T be "C #3"
Here's one layout, as you can see by the index, it's room[62]. So that level has 63 of those defs in it. Importing those from json would be awesome
bro what???
json is manually editable but pickle is made for python and supports all objects
Oh you know what, I think you're right
your situation is unreal
ong
a file name can't be C #3
bro
ngl you should check a python tutorial and do easier things first
can i just ss?
I am already trying to implement pickle for saving a level, it's kinda working so far but still much work to do on it
because you're completely lost
screen share
no sorry
a level can be way more than just a list of lists
But I think you are right, pickling these levels is a great idea
Now that I have them all defined, even moreso
{
'id': 2,
'time': 400,
'layout': [[...]],
'mobs': {...},
...
}
this can be whats in a level
Right, that's a good idea too
I'm just not confident that these levels will pickle
I'll try it right quick...
bruh
if you use object types like lists and dicts it will always be pickle-able
most pygame objects can be serialized too
It worked!
I haven't unpickled it yet but I did get a saved file of a pickled Level() object
why are you worried about pickling 
Because previous experience tryna pickle sprites
you can serialize surfaces using tostring() but its a dumb idea
firstly because assets and levels arent the same thing
secondly you'll have the same images in the objects more than once
thirdly because serialized surfaces are big like BMP (while formats like png are compressed)
4thly because big pickle objects will be slower to load
Very interesting
i'm average pickle enjoyer
So can pickle the Level() objects, but not yet the sprites...eventually I'm working out saving current level
just use the image/sprite names in the pickle
and your asset loading will handle loading the images
And all the items/locations/wires/states
you can make dicts for them too (in the dict itself)
like each item with the location and the type for example
in a dict
Right, then parse that into the level on load
yes
but you load a python object
no need to parse a txt or binary yourself
to extract the info
That's the last main thing I really need to get woking
is this the game save file handler
Saving the state of all items/locations/wires within the current level
by that i mean its not saving a level
Yes, and they will be specific to each level
Right, I get what you mean there
first thing is the game save files should be in appdata
but otherwise it can be a pickled dict too
Eventually
just don't put a modified level in it
But I gotta get them first
to get appdata you use pygame.system.get_pref_path()
pygame.system.get_pref_path("My Company Name", "My Game")
returns smth like "C:\Users\...\AppData\Roaming\My Company Name\My Game"
I just printed the pickle.load() object and, sure enough, it is what it's supposed to be
Happens to be the level I pickled....mind you. I only pickled the Level() object, that which defines a level, nothing to do with game saving here
if you make a serious game you need something to create the levels
That's what Level() actually does
to create them i mean
level design
you can use tiled and convert the tiled file to a dict of your format and pickle it
or make your own editor
But something to specifically create and another thing to specifically run, yes
you can't edit a pickle file by hand
Don't want to
and even if it was a json file it would not be a good thing to create levels
I thought about using tiled
it exports a xml thingy
And just importing the tmx
there's a module called pytmx that creates surfaces and stuff directly from the tmx
its widely used by beginners
Yeah, I don't really need it here, I think
i'm pretty sure tiled wasnt created for that purpose tho
I mean, it could make some things better, but as I have all these things already coded and parsing into objects in levels, I probably won't
yes its better to code your own thing
i don't think tmx files are intended to be game files
they're tiled projects
just like .ase
huh matt
Perhaps I'll move forward with this loading levels on the fly thing using pickled objects
I personally export Tiled to json and parse it myself
thats close to what we're talking about
i export tiled to my own format thats not pickle (but i could use pickle too)
As for the moment, I'm having a smoke break and a drink or two
wait you mean tiled can export to json natively
yep
This worked
Mind you, these are just shortcut keys for me to navigate the levels, not part of the game
So I can choose levels on keypresses for testing things
So for the set_level() method, I'll have a dict of relative paths from which to find the pickled levels...maybe
Because we don't need to get_path() for just teleporting to a new level
Testing passed, implementation next
I kinda really wanna lay the ground work for some kind of asset management
thats a very important part too
what type of assets do you have
Just images, really
And I'm just loading those with a couple of functions to load them into dicts or lists
you can make a global dict ngl
So they're already in dicts
just be sure to define the images to load or unload
Some make sense for me to have in a list for the objects that they go to but an overall dicts of them is a good idea
a dict can use strings as keys
Right
so you can use the keys in the levels for example
Ease of use
Yeah, I do that often
you probably need more types of assets btw
Don't have to change any args or params, just send the dict
such as :
- fonts
- strings
- sounds
- music
- shaders
- videos
- ...
all assets arent handled the same way
asset handling is also about how you handle the asset files
This is populating my player image dict
the images can be defined in a json
thats what i do at least
but having it in the code is fine too
(i use a .pak file that contains all files including the jsons to define asset dicts)
And I have similar code for other assets
i wasnt talking about this at all
i was talking aboiut a global images dict
not related to player or smth like that
they're not related to the game logic
By global, what do you mean there?
all images of the app in a dict
they can be loaded or not
i have a global dict for each type of asset in my asset class
I mean, I know what global is, but as these assets are all part of main, they are kind of global in that they are being sent where they need to go
the game logic just use the names
the the names are defined in a json file
there's no pathes in the game code
I mean, there has to be something populating a global dict by loading assets into it
then the game logic just use the image name
yes
the assets manager class
but the keys and pathes are defined in a json file
Well yeah, that's what I do, I never load images during game logic
Only load them in main init() and send them
By lists or dicts
any game is doing this
what i mean is a more specific thing tho
i use a dict for all images of the app
and the keys can be loaded and unloaded
wdym
when i load some assets the asset manager reads the json files and loads the assets
and then the game logic uses keys like "player_up" or "box"
not surface objects or smth like that
I'm trying to get what you mean by global dict of assets
a single dict for all images of the game
and a single dict for all sounds too
and same for all types of assets
Well that's just packing and unpacking into a dict, I don't see the advantage of having everything in the same dict though
Maybe to send the entire dict to other objects?
the advantage is
keys can contain None or the actual asset
because i don't just load
i also unload
to not keep everything in memory at once
and i can also use simple strings (keys) in the game logic
instead of using variables contaning surfaces or stuff like that
i make my own high-level handlers for the things too (like canvas for drawing stuff or mixer to play sound or music)
I'm kind of doing that with the various images for 'hot': [NESW], 'cold': [NESW] for individual object images
Then when I decorate() them
Just use the dict
whats this class
Parent class for all devices, those things with ports and get evaluated
idk what a device is
Many of those objects override that though
AND gates, NOR gates, these are devices
They have ports to which wires are connected
but so its a game logic object
Totally not making sense

I create the image dict when I instance the object
its not a dict like i use
i was talking of a dict for whole app
you're talking of a dict related to a game logic object
what you're doing is the usual way to load assets in a simple way in pygame
but your code doesnt really unload the assets right
and if you load different objects that means the same surfaces can be present more than once in ram
making the right classes and stuff is not that easy
One of my devices https://paste.pythondiscord.com/33SQ
alright
you want to hear something
the game objects shouldnt know they're rendered
Only in that they objects get kill()ed
thats right
a good game should be able to run without the rendering part
what you're doing doesnt respect that
What do you mean?
you have draw calls and images directly in your game objects
It's only drawing on its image, not to screen
oh
You see no reference to screen there
All of these objects are being drawn in main when it draws the groups they belong to
Device is an Item and Item is a Sprite
The mro
As for using images for every state of every object, just no way
Like my stems have to be drawn on the object in the state they're in, I can't have an dict with every image for every state in it
Item has all the moving and selecting and all handling of all items, including robots, keys, sensors, everything the player can interact with, devices are those things which get evaluated in the simulation
Images in objects, I don't get that. All pygame sprites must have an image
But there may be something I'm missing here. Is there to be a method in the objects for assigning the image from main or an asset manager?
Like, I could, and in fact, have had them being sent to the objects, just all that drawing on the image not in the object itself and instead being sent
Because the stems aren't part of the device image, they just get drawn on it
This is a class for a different game, it defines a bunch of paths in a dict and has this method for getting them. Perhaps this kind of idea for all these images
That's not a terrible idea. Would give me that global dict, so to speak
I'm always mixed between drawing and loading images. For things like my player, I have to load them but for simple things like my gates, I'd rather just draw them
But I'm going to draw them in a new object
i was missing that part
i don't use pygame.sprite on my own
some of my images are sheets and i create a json file for sprite positions
I always send (pos) to sprites, sometimes convert to vector (if the object is animated, as in, going to move)
I did this kind of thing so far, not sure if it will stay this way
So I'm drawing the images, storing in a dict, instancing the object with the dict and getting the images from it
And sending them to the AND gate
Where it is using them instead of drawing them itself
Problem with that though...I gotta make sure to use image.copy()
Because drawing on one would otherwise draw on all and gates
Hmm, just tested and I could be wrong there but I'm not sure why
Oh, I get it, my Device.generate_images() is using copies of what it is sent
Slight change to that Images() object
object huh
i don't see a __init__ there
Well, it's not quite an object
its a behaviour-less class
But in the sense that everything in python is an object, it's an object
an object is an instance of a class

bru
a behaviour-less class is basically functions and variables using a namespace
I see no need to instance it and make it an actual object, I can reference it as Images.get_images('')
Which is what I'm doing now
that feels very incorrect
getters arent even pythonic
idk whats your level in python oop but if you want to make unusual classes you should learn stuff like getattr/setattr
do you know properties at least
you mean properties
Yeah
they're the pythonic version of getters and setters
what do you not understand in them
getattr and setattr is also a cool way to make a dict-like class i use it sometimes
Just looking over some older code for an implementation I once did...didn't find it. But I don't understand the advantages of using properties over attributes...yet
properties call a function
if x is a property doing
my_object.x = something
can do way more than changing a value of an attribute
properties arent a replacement for attributes they're a replacement for getters and setters
well they use getters and setters to make something easier to use
no need to add useless comments to the getters and setters like in java
I'm going to try implementing some of this in another class...
Time to get our hands dirty
hah
show class
🎉
By the way, thank you for taking the time to scrutinize and point out other ideas to me
there's no real point in doing this tho
No?
are all your classes actually behaviour-less
I don't know what that means
well this one isnt behavour-less
I mean, they all have methods
but are the methods just functions with a namespace (like in the Images one)
or do you have a real oop structure for your app
can i see how your main class looks for example
Yeah, and I instanced it
It's basically just a class with a bunch of methods like this one
i meant the structure of your program
what classes do you have
how do you handle the states of the app too
This is the main loop
i was more interested in seeing all the classes and methods rather than whats in the methods
So far, I mean, it can always and often does change
how are states handled
There are no 'states'
i don't see anything state-related in the main loop
huh
do you have other states aside game
It runs levels, that's all it does
states is the first thing i implement when making an oop app
I use states often, perhaps a different implementation that you're used to
well i didnt see everything
but looks like your codebase uses oop but absolutely doesnt benefit of using it
This is for another game, but just runs (and draws) objects depending on its state https://paste.pythondiscord.com/RBPA
I like the structure of that project
It's part of Galaga
Yeah, pretty much
i never use any parameter in main class
Runs this
neat
i wasnt expecting seeing a game of that complexity
But to the point, i like that structure
be sure to learn about new stuff instead of just using what you already know
in general
you'll not regret it
You're already helping me with that
Yeah, I just started learning oop a year and a half or so ago, and I have much more spare time these days than I did back then, so ya know, learning, practicing
you can learn everything about oop in python in one month or two
thats not what i think about when i hear state machine
And some of that code is not even implemted, like the change player, it's there and I had used it before not anymore, maybe again in the future I implement two-player mode
state machine is one state -> one class for me
and i keep my main class minimal
(creating the high-level accessors classes for the states code and defining pygame event stuff)
That game is completely different setup, one of my own making from the ground up
Galaga kicks ass so far
what if you have a lot of states tho
like menus loading screen splash screen ...
or different game states
I have used the same idea on NPCs or any object for that matter
In a lot of ways, it makes things easier, as each state has its own logic
i don't see how hacing so much methods is clearer than just using a .update() method
my states just have .draw()/.display() .set() and .update()
other methods are just used in the class itself
I shared the short video..lemme look for the one that actually changes states...
i know the thing works yea
i'm talking of codebase rn not how it looks
but how would you handle a stack of ingame menus like in geometry dash for example
you see a level you check the creator
then you check something else in the creator menu
...
and it has to revert all the way to level
your game is good
but i was talking of code
how would you handle a stack of ingame windows for example
I would create a class for each of them, instance it, update() and draw() it
but where's the stack
What do you mean stack?
you click on something in the red window
it creates the green one
when you leave the green one you have to get back on the previous state (with the red one)
Right, not sure how I'd do that
with a classic state machine this is extremely simple
And close the green one?
when you close the green one you get back on previous state
you cant touch the red one when the green one is active
like you generaly add a dark overlay to the screen before putting the green window
ui stuff you know
Right, okay, so I'd create them, add them to a list or dict or object or something and only update the last one while those under it don't get updated
when you use a classic state machine you .update() one state
its pretty trivial to understand
The current state
But the state can always change to another state, depends on what triggers a state change
my .update() method returns the new state
thats not what everyone uses btw
To where?
its used in the main class
and at next iteration of the loop it will be the new state
the update() methods from the states i mean
That's what I use that set_game_state() method for you see it's sent to all of the objects, so they can callback a state change
I'm always interested in learning more state machine implementations. In fact, that was one of my first questions in this channel a couple of months ago
I suppose it would be trivial to return something from an update() method and use that to set the next state
yes its straight forward
Done right, I wouldn't have to send that method to the objects
i do this so i can change the state directly in the state code
the main file is really minimal
i make the state machine and then all the code is inside state classes
You got a GitHub repo?
the state machine contains the stack too
me or @limber veldt
U
also not a repo 
i have a lot of improvements for this if you want
It's basically just a launcher
yes lol
but i have things to say about some parts still
replace this
by os.path.join(path, image)
you can replace this
by os.path.splitext(image)[0]
splitext also works with full path
constants should be defined in a constants.py file
you may also not agree with this since a lot of people do it but "importing a folder" is a bad thing
any file that's added in the folder will break the game
Cool beans, this looks like you've been using pygame for a while. Is this apart of some bigger application/project/game?
including some that can be created by software if the user just reads the file
It's the main for Galaga
What's Galaga? And where is
Game
Defined?
Well, I mean, imprting a folder of images and not finding an image will certainly break something
and adding any other file will too
open one of the images with HxD and you'll get a .bak file
the user can break the game by just opening the files
Well yeah, this is python
One can open the file and type, broken game
just don't load whats in a whole folder lmao
serious games don't do this
its absolutely not related to python
for my games i use a single .pak file that contains all the assets but that's more complex to setup
I want that whole folder of images, it is a game folder, inside the game's file structure
How do they do it, if you don't mind me asking
like me generaly
one or more archive files
and if they use folders they don't ask windows to check whats in the folder and then trying to load everything as images
make a dict with the images to load
just define it yourself
instead of checking the folder
Load the entire folder into a list or dict and be done with it. If someone goes in there playing around with files, they deserve to break it
Or you could just check the file extension to see if it is a type of image and then load it or not
I learned it from reputable sources and yes, I do like it
thats still a pretty useless thing to do
and adds more loading time too
why would you load additional images
a game isnt made to be modified this way
are the sources DaFluffyPotato
No
well most games you'll see don't use a folder for their assets anyway
@swift solar dont laugh lol
That's why I'm drawing some of my surfs instead of loading, eventually only loading player images...maybe
i like dafluffypotato's games but how he's loading files is MEH
It's a funny name, I kinda want it now
bruh
I haven't watched him hardly at all
an archive file is generaly a non-compressed slightly obfuscated file containing all files using a fast way to extract specific files
but some can use encryption/compression
you can also have more than one if game is large
an easy archive file you can make is a zip
but zip adds unnecessary loading times
especially if your asset formats (like png or jpg images) are already compressed
I have no need to compress my images
i mean you can use it to have one single file for assets
not for the compression part
Or obfuscate them or the codes
Like an xml or json file?
no not that
an archive file is a container like a zip
with images/sounds/... in it
games generaly use this to handle the assets
Ah
And to obfuscate them so regular Joe can't go in there poking around
Wait like a .rar
.pak extension is the most common one
but .wad is more historic i guess
its the format used by doom
rar is a compressed folder like zip tho
the point of these archive files is just to have everything in one not to compress (and obfuscate too generaly)
Like every project I go look at github has a folder of images, seems the norm for python at least, to include images in the package
RIght, mine are
python allows to handle your project pretty much like you want btw
Like I don't care once I'm done with it what someone else does
unlike java with gradle which is very strict
if you just finish projects then yes
but a game distribution isnt code files
Yeah, I'm a long time hobbyist
Hmm, I've been pygaming for about four years now, more heavily lately, as I said, more spare time
I worked through all of Coding Train's NOC series and that taught me a lot on making things move
Coding train?
He's a youtuber
I thought he taught JavaScript?
Writes Java and js though, not python
I can do a little, too, but he's so good at explaining that the language really doesn't matter
I know python and pygame well enough to transfer his logic into my codes
I tell ya, it is kinda nice having all this drawing in one place. I'm not sure it will stay this way but even if it doesn't, I have all the drawing in one place and easy to implement any way I choose
The end result will be a dict with all the images in it, I can then use that anywhere or just keep pulling them from the class
how do you make an actual game with Python, like an accurate, fun, and addictive game
it has nothing to do with python
tbf, snake is/was a fun and addictive game
Python is a snake
see the correlation?
Makes perfect sense to me
I wonder what is meant by "accurate" here...
does anybody know any good begginer projects
im tryna go back to the basics and develop a stronger base. I realized that im moving to fast I haven't even been 2 weeks in and i've moved past some subjects I would like to go back to and start from scratch . skipped to many projects and wasted time I shouldnt have
What concepts are you trying to relearn and what types of python games/projects have you built?
ive worked on a few games but they never rlly completed nad its been from alot of source code and tutorials I can read and edit the code and add some parts but im missing alot of logic I feel that I skipped over
@swift solar just how everything connects
Ah I did something similar when I first started, you should choose a simple game like snake, tictactoe, or flappy bird (my favorite) and build it from beginning to end all by yourself self using past code and the Internet to help you when you get stuck instead of online tutorials
I'm working on making a game with pygame
How would I check to see if ESC was pressed?
K_ESCAPE is the key constant
be sure to check the docs
Thanks!
So python is mainly for creating web pages? 🤔
It's not just for web development as you can see in the topics
Does anyone have experience with integrating LlamaV2/other LLMs with Unity, whether through Sentis or otherwise? LlamaV2 can be serialized to .onnx yea?
pong
extremely expandable btw
Definitely not, that's what html, css and js are for
ofc Python is used in the backend a ton where some pages might be generated from templates, but that's about it, there's not that much Python to it anyway then
I kinda added a lot of balls, this game has all 32 or so levels
Nice, but it has a USB connection lost sound, thought I lost a device, lol
So, how are you doing image assets? Drawing them in code, importing images?
I had problems capturing audio at first. Your pain is my pain
@limber veldt I dumped them from the source ROM
they're just loaded as PNGs
there's only a one-time import cost anyway, so it's just easy enough to turn them into an asset pack and load that at game start.
How many enemies do you have so far?
just enough for waves 1-4. Brains come next 🧠
then tanks , and then I just have to set up the wave counts
and write the attract mode stuff
and do some high score keeping
Right on, it's looking really good
I wrote a custom shader to do the color cycling effects
I need to write shaders
it was quite the crash course
the 'beamdown' effects I didn't do with shaders last time, so I may just keep the old technique
oh, and I have been able to use another utility I wrote to deliver the game as a standalone package
anyone goT a good game they could show me?
made with pygame-ce: https://store.steampowered.com/app/2596940/Isometria/
how to make a game anyway like isometria or a 3d game like roblox, or anything
start by learning how to make something along the lines of Pong
you'd be surprised how complex even a "simple" game is, and how much you have to do just to make that game's mechanics workable
what about c++ is it easier?
not remotely
It's not about the choice of language
