#game-development
1 messages · Page 9 of 1
no
i was a bit through the course and that was a project
it started from nothing and gave me worded steps which i had to turn into code
aah
.
guessing it's in the loops section?
~ Upon further inspection of the Code Academy tutorial in question, the code was fine, seems to be the suite locking up in the browser causing the error ~
https://pastebin.com/AVZqCvvk
hello, i have coins in my game that are 16x16 but they are in 32x32px squares. i centered them but how can i make them move from bottom side of square to top
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.
i don't understand your issue at all
you're using huge images to resize them to 32x32, then you make a board and you blit the tiles
what do you need
i scaled the coin image to 16x16 and printed them so it looks like on pic, now i want to make a coin going up and down from one top border to bottom and vice versa
Hi i made very simple but effective pygame Live coder you can see your code changes immediately in your pygame project
https://github.com/ElsevarAsadov/PygameLive
you mean you want to make the coin animated ?
or you want to make it move in the board
animated, move it down and up
well, you have to code this yourself, there's no "animated surface" in pygame
i dont know how so im asking for help
if its just about moving up and down you can use a global animation index
or you can make a list of surfaces for the animation (i recommend to do this with a rotating coin, going up and down isnt a good animation for a coin)
rotating animation is easier?
by rotating i don't mean rotating the surface
you see how mario coins look like ?
that's how a coin should be animated
but its not really related to your issue
i generaly make a global animation index (starts at 0 and is incremented at each iteration of the main loop), and i use it for all animations so everything is synchronized
like, if i have some animation in 20 frames i do animation_index % 20 to know the right frame to display
you can use this to make the coin move
https://pl.pinterest.com/pin/140033869651577325/
i wanted to do smth like that
without the particles at bottom
this is an animation you can't do with just moving the surface, the coin "rotates"
it's better to make an image with all the frames and import it as a list of 16x16 surfaces
also if its a grid making the coin move will not look good, its better to just have rotating coin like mario coins
like this one
Le GIF animé Coin Mario Pixel Art idéal pour votre conversation. Découvrez les meilleurs GIF sur Tenor et partagez-les.
ok, ty for help ill try to do that ❤️
Got some world generation going
can someone please explain why this isnt working, what I mean is that once the spacebar is pressed self.status = attacking, but when I release the spacebar it is never reset to flying
if keyboard_input[pygame.K_SPACE] and not self.coolingdown:
self.coolingdown = True
self.status = ('attacking')
#print ('Attacking')
self.create_attack()
self.attack_time = pygame.time.get_ticks()
for event in pygame.event.get():
if event.type == pygame.KEYUP and event.key == pygame.K_SPACE:
self.status = ('flying')
I have resolved this issue
I have another question, i have a list with 5 variables and i would like to set all of them to the same value
i dont want to change the variables name but what rather their value, I may be doing this incorrectly
yo can anyone help me with a pygame problem
can anyone explain the cordinate system for pyglet
can you give some code example so i can help you to do what you want
nm i got my answer after a bit of experimenting
Depends on the task at hand
What type of game
I am wanting to make 2d games but in the future I want to make a fps game. I know you'll probably say ursina. but there are more tutorials for pygame but does that really matter?
I have read into it you can make 2d games in ursina
i think
you can use opengl with pygame window but its super bare bones, don't try to make a full fps in opengl
ursina is made with panda3d itself made for 3d
Python i not good for 3d
i don't recommend ursina for 2d
should I use both
you don't have to write the engine in python tho
panda3d isnt made in pure python of course, and using raw opengl is still completely possible too
Yea but it's gonna have low frames
Depends tbh on how complex
yea, but with a few shaders you can do really cool looking stuff in opengl
never really used ursina so idk its power
anyone want to chat and code
cannot access local variable 'HOUR' where it is not associated with a value
i have this error code and cant find a way to fix it (yes ive looked on the internet and cant find anything)
class Planet:
AU = 149.6e6 * 1000 #Astronomical Unit
G = 6.67428e-11
SCALE = 250 / AU #1 AU = 100p
TIMESTEP = 3600*HOUR #represents 1 day```*gap*
```for event in pygame.event.get(): #every button press or click
if event.type == pygame.QUIT: #the x on the top right of the screen
run = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_PERIOD:
HOUR = HOUR + 1
if event.key == pygame.K_COMMA:
if HOUR >= 0:
HOUR = HOUR - 1```
@pure vessel pass the hour var into the class
ok
i swear if thats all i had to do
got the same message
@pure vessel show your proper code please
ok
Hey @pure vessel!
You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.
What error is the line on
You never even declare hour in the main func
@pure vessel
ah wait i’ll try it in a bit
soo technically im not getting anymore errors but now it just wont do what i want it to do
im changing the HOUR inside of the def main when i want to change it in the class Planet
@pure vessel def your hour in the init
class lol:
def init(self, blah):
self.hour = 24
test = lol()
lol.hour+=1
like that?
Yes
would be earth.HOUR
but i wanna do it over all
i saw that but dont get it
top of script do
global HOUR
HOUR = 10
Everytime you def a function add
GLOBAL HOUR
def lol():
global HOUR
?
You start the global at the top of your script
like the top of the code
Not in any func or class
show code now
what should this be
Did you global it in the main func
no
I'll do a example 1 sec
Not exactly game development, but python based discord ping system for Minecraft. It launches the self-hosted MC server as a subprocess and captures stdout, running different actions based on the printed string
global hour
hour = 10
class lol:
def __init__(self):
global hour
hour+=1
def main():
global hour
hour+=1
When ever you def a new func you put the global in there
Meaning you give access to that function to now share the var
wait
That was just example
thats smart
ok
So what are you trying to do ?
you are now part of my code
Haha good
Did you define it under the hour
.
@pure vessel i messed up have a look at it again
hm
so i call this inorder to add or subtract HOUR?
dident change the code just asking
like this
then just call that after key down
Everytime you call the class your putting the hour back to 24
For everything
@pure vessel i don't see any errors ? Any errors for you
no
just
still dosent work
not changing the speed of time
im trying to change the HOUR inside of the Planet class
You do all that in the init part
And make them all self.value
self.AU = blah
self.G = blah
Yes
ok
Put global hour in the init aswell
i would have to do that for each one
doing the class wrong
oh
what
i will send example
class planet:
def __init__(self):
self.AU = 100
self.EU =120
test = planet()
print(test.AU)
What?
what ??
I bind the class planet onto test. So now anything that is self.value becomes test.value
allowing?
wym ??
Why are you even sending the planet au if you already declared it in the class
The first parts your declaring in the class is the x and y
Did you get chat gpt to write the script
Lol
There is no way you got that far without understanding classes
its cause im multiplying the AU to get distance it should start in
no
dont worry about it
this is how i learn
its weird but works
some times
looks like you don't really know how oop works
here's a template of pygame app using oop, you'll need to make more classes and initialize the objects in the main constructor before using them in the main loop for example
import pygame
import sys
class Template:
def __init__(self):
pygame.init()
self.clock = pygame.time.Clock()
self.screen = pygame.display.set_mode((800, 600))
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
self.clock.tick(60)
if __name__ == '__main__':
template = Template()
template.run()
anyone here know pygame
just tell your problem
yes
its posted in python-help
Pygame wont respond
the window gets whited out
check dms 🙂
Is there a mix of pygame.time.Clock().tick and asyncio.sleep?
define "mix"
like does both?
have a steady fps and print x every 5 seconds and y every 1 second (an example)
?
yes but how?
it's basically running something every x amount of time
you can also not use them
and do your own thing
can you do multiple at the same time?
yes
how?
read this
i did
this hasn't worked -- in particular the image tiles once and then doesn't again, once you scroll past that it stops tiling
would there just be a decent way of checking if the image is scrolled past the display screen so then I would run the tiling function every time it's needed? I think that would help with the performance quite a lot, I can't seem to find a good way to do this unfortunately
I guess a solution would be to simply check the layer's coordinates and see if the value's greater than the screen itself
Hey is there any way by which we can earn money using pygame 🤔
You can make a game and sell it
hi pygame users, have a look at my doubt posted in help channel. Also its my first time developing a game using pygame so can anyone of you kindly become my mentor for this???
I can think of a few,
- Tutoring
- Selling your games
- Making games/prototypes for other's online (Fiverr)
I've tried a couple of other things, including some previous solutions from here - this has turned into a bit of a mess so I'm considering going back on most of my developments when it comes to the background, gonna try something fresh maybe it'll work
I tried this but unfortunately it seems to just push the image to the end of the screen
I also run into this issue where the player character stops blitting properly
I'll try tinkering with it a little more and I appreciate the code here. I dunno why i can't seem to get this concept figured out
nvm I think I figured out, just drawing the background twice seems to have done it
Anyone
Try linking it so we don't have to go search for it
its not about the help post anymore but for mentoring. Its my first time developing a game, so I need someone to become my mentor guiding me
but that seems to be pretty costly performance wise so I'm back to the same problem 🤕
for those who might be able to help:
def loop(*obj:object):
while running:
screen.tick()
# create keyboard instance and catch key presses
kb = control_dsg()
for event in pg.event.get():
if event.type == pg.QUIT: sys.exit()
kb.move(event, p1, kb.set_move_AD())
kb.borderEx(screen, p1)
kb.jumpEx(p1)
p1.animChara()
p1.delayEx(20)
p1.BulletEx(1000)
bg.draw_moving_scene(p1, screen) # <--- the culprit
...
bg = scene(screen, 0, 'assets//images//background//dune.png','assets//images//background//middle1.png','assets//images//background//front1.png')
Where to sell games
# This is a pretty hasty and thrown together function, but what I'm thinking of doing to clean it up wouldn't aid the performance much
def draw_moving_scene(self, player:fighter, screen:screen):
if player.is_past_border():
self.back.x1 -= self.back.drawspeed
self.middle.x1 -= self.middle.drawspeed
self.front.x1 -= self.front.drawspeed
if player.is_before_border():
self.back.x1 += self.back.drawspeed
self.middle.x1 += self.middle.drawspeed
self.front.x1 += self.front.drawspeed
if abs(self.back.x1) >= self.back.WIDTH:
self.back.x1 += self.back.WIDTH
if abs(self.middle.x1) >= self.middle.WIDTH:
self.middle.x1 += self.middle.WIDTH
if abs(self.front.x1) >= self.front.WIDTH:
self.front.x1 += self.front.WIDTH
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
self.middle.draw(screen, coord=(self.middle.x1, self.middle.rect.y))
self.middle.draw(screen, coord=(self.middle.x1 + screen.WIDTH, self.middle.rect.y))
player.draw(screen, False, (player.rect.x, player.rect.y))
self.front.draw(screen, coord=(self.front.x1, self.front.rect.y))
self.front.draw(screen, coord=(self.front.x1 + screen.WIDTH, self.front.rect.y))
without the function in place, I get around 200+ fps without any qualms. With the current implementation, just drawing the back, front and player leaves me with about 60 fps, and drawing middle drops it down to 40
you can earn a lot with python, but i don't think a lot of people will pay you for pygame stuff
you have to make your own things and sell them (tutorials, games)
I think I'll move this to the help threads, see if I can get it fixed
Steam, itch.io
It's unlikely to get sustainable income from it, but you'll get some cash
Of course, it all depends on the quality of your game and marketing
I've been developing games for 7 years now. As of November 18th, I've earned $6,249.30. This video serves as an explanation/breakdown for how I got that money.
Devlog Series:
https://www.youtube.com/playlist?list=PLX5fBCkxJmm1F3PofHWCGNH6se7QO7L3d
Discord:
https://discord.gg/9Qt2GxF
My Twitter:
https://twitter.com/DaFluffyPotato
Patreon:
ht...
This might help you
Nah I don't have to become rich by making games
I was thinking to make more games as projects then I thought why not to make money from games that's why I asked
Thanks for genuine tips
Sure, that's a sound idea
In Python arcade, how to set a track to play only on one of right or left speaker channel?
hi i am developing a game in which the characters are sprites. My code works currently. Do I need to import sprites class?
is it required?
or does it helps some functions that help in animating sprites?
please enlighten me
I think whether it will be beneificial or not depends on how your code works
But usually it's common to utilise them, and they can help in speed, consistency, and convenience
i'm not sure its supported tbh
arcade is based on pyglet and looks like pyglet doesnt have this feature
you can maybe use a different library for sounds if you need a feature like this
Yeah I also can't find any direct volume control on the individual speakers
But I can try to use the 3D sound feature for this
this a 2d game engine
i don't really see a reason to have that much advanced sound features in arcade
Pyglet has 3D Spatial sound support
But anyway I need the 2d part only
you can maybe try to use some other library, bass is a pretty lightweight one, fmod was still fire 10 years ago but i can't find any binding for python, fmod() being a python function lol
if you need live coding feature when you develop your pygame application then use this repo
https://github.com/ElsevarAsadov/PygameLive.git
hey guys how do i make my character able to move in all direction
i already figure out how to make it go up and down
but when i want to make it also able to go right and left something when wrong
theres no way you can get help without code
we don't even know the library used...
oh ok
my bad
so you able to help me if i send my code right
here, i cant send the code because of discord
Well, just at a glance...
you're just using 1 or -1 for the direction without any differentiation between moving in the X axis or Y axis
nor do you have any code to handle moving in the X direction at all
direction should probably be a tuple including an X and Y direction. EG, up {0,1} right {1,0} , down {0,-1}, left {-1,0}
(and perhaps some code to handle when 2 keys are pressed, like up and right {1,1} down right {1,-1} etc...
By extension, in the 3rd image. ```py
def move(self, direction, max_height):
if direction[1] > 0:
#handle moving up
elif direction[1] < 0:
#handle down
if direction[0] > 0:
#handle right
elif direction[0] < 0:
#handle left
might help
thanks
np lemme know if that helps out. Btw, are you going for a platformer or like zelda top down movement?
i want to make vertical shoot em up game
In either case, you might also consider the pygame.key.get_pressed
As with KEYDOWN and KEYUP you can run into weird behavior. EG right now if I'm holding "Up" and hit right to move that way, then release "Up" movement will stop in all directions
with get_pressed, if I've got Up, Down, and Right all pressed at once, you can add together all of the directions, Up and Down will cancel out, but I'll still be able to go right with them pressed.
Also you cna transition from moving up to down (or right to left) more easily
Also with get_pressed it'd be easier to recognize and handle diagonal movement.
@woven canopy how do i make it stop while using get_pressed
Well it's been a hot minute since I messed with it but
Probably have something that looks liek this in your main game loop so it fires every frame.
direction = [0,0] #resets movement at the start of every frame
keys_pressed = pygame.keys.get_pressed() #checks for all keys that are currently pressed
if keys_pressed[K_UP] or keys_pressed[K_W]:
direction += [0,1]
if keys_pressed[K_DOWN] or keys_pressed[K_S]:
direction += [0,-1]
if keys_pressed[K_RIGHT] or keys_pressed[K_D]:
direction += [1,0]
if keys_pressed[K_LEFT] or keys_pressed[K_A]:
direction += [-1,0]
Basically, you set direction to 0 at the beginning of the frame, and then check which keys the player has held down and update direction before it's handed off to the actual movement code
Thus if no movement key is held, it'll default the character to stationary
my character still keep moving even tho i i have let go the key movement
Can you post the section of code that reads your keys now, and the section that actually does the movement itself please?
(sry, am working so intermittent)
oh hey so have other to do so how about i send it on dm
works for me
Any way I can make this less laggy? I am calling .draw() twice to make the image scroll properly
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
self.middle.draw(screen, coord=(self.middle.x1, self.middle.rect.y))
self.middle.draw(screen, coord=(self.middle.x1 + screen.WIDTH, self.middle.rect.y))
player.draw(screen, False, (player.rect.x, player.rect.y))
self.front.draw(screen, coord=(self.front.x1, self.front.rect.y))
self.front.draw(screen, coord=(self.front.x1 + screen.WIDTH, self.front.rect.y))
(This is using pygame btw)
Implemented a scroll bar for my game
i was wondering why my wip tile-based sandbox was lagging so badly until i realized i was doing something really stupid - i was loading the block sprite to render for every block every frame
made the straightforward optimization of loading all the images before the loop and just getting them from there at the render loop
although im not sure i actually need that .copy()
this isnt really, "optimization", that's how the things always should be
always load the images you need first, and you should also avoid using pygame.transform functions in a loop or during runtime too
Testing arcade's texture caching```py
import arcade
s = arcade.load_texture(r"assets\images\lion_run01.png", width=145, height=69)
t = arcade.load_texture(r"assets\images\lion_run01.png")
print((s.width, s.height), (t.width, t.height))
print(s.image == t.image, s is t)Outputpy
(145, 69) (145, 69)
True False```So doing it this way makes the images not cache to the same key even though they are identical
well, they're not the same object
Yes as I already mentioned
hey can i change the origin point of a text in pygame?
origin point ?
you want to rotate a text surface ?
you're making a surface with the text right ?
yeah
you have to center it when blitting the surface
basically i want the (0,0) coords of the text be the center of the surface
not the top left corner
yeah
then you blit it where you want
ik
no i mean like
one sec
basically the origin point is the top left corner of the surface
well i want it to be at the center
yeah i know
then you blit it at the center, you can use get_size() to get the width/height
and then you blit it at (destination width - surface width) / 2, (destination height - surface height) / 2
you can also use pygame.freetype to directly blit text instead of making a surface
but using the surface it's easy to center it
@fallow finch just a question what does the get_size() return
does it get returned as a list or tuple or?
ok thanks
arcade.AnimatedTimeBasedSprite does not support collisions?
I assume no as then it would have to calculate hitbox and store the contours for each and every frame which will be memory expensive
So what is a solution here, a faux sprite which will have the animation as a separate attribute?
This might be noob question but how i can make polygon i draw to sprite and give it rect
i have sprites in my gae with pixel perfect collission but wanna do meelee attack and drawing it with code and stuff
i have sprite groups handling collission detection its small project just doing for fun and learning purposes
i dont understand your question
nvm solved it already
doing bulelthell rpg in school project for fun
its ice to code without game engines like unity, godot, unreal engine ect. learns something
nice*
Like 2 other people in the world use arcade I guess, and no one here
It does, its a direct inheritance of the sprite class
How do I set collision mode for such an object?
Are you using a physics engine?
Arcade
Yea arcade has bulit in physics engine for collisions
Follow this tutorial https://api.arcade.academy/en/development/tutorials/platform_tutorial/step_12.html
From L#108
I am not making a platformer or a side scroller
I am making an isometric, 8 directions
And this does not use the animaitontimebasedsprite class either, doing manual frame updates
Rudimentary level
FWIW The animated time based sprite does this only i.e the class has only has update_animations method implemented and nothing extra.
Are you using a physics engine for collisions?
Yes, I have seen the source code for all sprite subclasses already
😭
Your have lesser idea about this than me
arcade is the engine, it contains the pyglet physics engine
*pymunk
A physics engine is different, it is used to control the character's movement https://api.arcade.academy/en/development/api_docs/api/physics_engines.html
That is unrelated to my question though
My question is not about movement, but edge detection for amimated objects for use in collisions
You don't seem to be providing any info. See if you are using a physics engine like the PymunkPhysicsEngine it would be easier to handle collisions.
Also about the hitbox, it is automatically updated when the texture attribute is changed in 3.0.0.dev19.
So can you answer in a yes/no are you using a physics engine?
You are literally googling and pasting wrong or not very useful answers for me
I dk why if you haven't even used this library
hey all, I am going through Clear Code tutorial and I am not sure why he is saying at this point in the video that adding a update status method to the enemy update would cause it to then be performed on all visible sprites. Thank you for any help.
https://youtu.be/QU1pPzEGrqw?t=16726
A Zelda-style RPG in Python that includes a lot of elements you need for a sophisticated game like graphics and animations, fake depth; upgrade mechanics, a level map and quite a bit more.
Thanks for AI camp for sponsoring this video. You can find the link to their summer camp here: https://ai-camp.org/partner/clearcode
If you want to suppor...
i got a question
since i wanna make a game once i get a better computer and i would like to have some music is there any good, free and trust worthy music making software?
for games you mean ?
yea i guess
the only free music sofware i use for games aside Audacity of course is OpenMPT
the thing to make tracked music, very useful for games
i really don't know a real good music app that is free
alright thanks that really helps
you know what tracked music is ?
no not exactly
it can be used for games but aside games it's kinda useless
ohh kinda like bossfight music and stuff?
looks like good free music apps really don't exist lol, never thought of this
no, it's music where you have samples and you write notes, kind of mix between midi and audio files
ahh got it
its not really used anymore nowadays
that's funny to see how there's good free video editing sofware but for music i really can't find anything free that is known
Audacity
its more for editing music, you can't use just this to make music
sure you can, it also has generators and stuff
probably not the most sophisticated tool for creating music, but you can still try sth
Frozen program in pygame without error messages https://hastebin.skyra.pw/yilureholo.prolog
im not really sure if this is glitched or not but i tried making a pendulum sim
is it worth implement a split in blackjack where the hand will split until it can no longer split? Or is is fine to just do one split since the prob. of getting multiple splits in a row is pretty low. I can't seem to get the recursive splits quite right.
hey can someone help me how to make my character move diagonally. I've try using key_get_pressed but with some reason it doesn't work
def run_game_loop(self):
game_over = False
player_character = PlayerCharacter("game assest/pemain.png", 270, 500, 45, 45)
direction = [0, 0]
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if pygame.key.get_pressed()[pygame.K_w]:
direction = [0, 1]
if pygame.key.get_pressed()[pygame.K_s]:
direction = [0, -1]
if pygame.key.get_pressed()[pygame.K_d]:
direction = [1, 0]
if pygame.key.get_pressed()[pygame.K_a]:
direction = [-1, 0]```
if pygame.key.get_pressed()[pygame.K_w]:
direction[1] = 1
if pygame.key.get_pressed()[pygame.K_s]:
direction[1] = -1
if pygame.key.get_pressed()[pygame.K_d]:
direction[0] = 1
if pygame.key.get_pressed()[pygame.K_a]:
direction[0] = -1```
Probably change the 2nd and 4th if to elif
Welklam
I'm moving the background for my game but how would I go about moving the sprites in relation to that? is there any other way of doing this besides manually pushing aside the objects as the screen slides?
relevant code (ish?)
def draw_moving_scene(self, screen, *players):
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
for p in players:
if type(p) == player:
if p.is_past_border():
self.back.x1 -= self.back.drawspeed
if p.is_before_border():
self.back.x1 += self.back.drawspeed
if abs(self.back.x1) >= self.back.WIDTH:
self.back.x1 += self.back.WIDTH
p.draw(screen, False, (p.rect.x, p.rect.y))
Can anyone help with the next?
I need to draw let's say a cube in 2d (net of a cube!) for further game developing using pygame.
It should look like something like this:
i don't understand what help you need
the next ?
haha sorry
i need to draw net of a cube like in the picture i sent
furthermore, i need to make tic-tac-toe boards on each of 6 squares
so your screenshot is what you want to do ?
you can use images or drawing functions from pygame
i think its better to use images rather than just rects
yes
you know how to blit an image or how to draw a rect ?
no
i just know how to draw it by drawing each line separately to draw that net
thats not really something you should do
just use an image its easier
its not apple II basic heh
okay i found something and i think it could be correct but i can't adapt an image to the code
also i tried to draw one square and load it 6 times but same problem
import pygame
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# Initialize Pygame
pygame.init()
# Set the dimensions of the screen
size = (400, 400)
screen = pygame.display.set_mode(size)
# Load the images for each face of the cube
front = pygame.image.load("cube_model.png").convert()
back = pygame.image.load("cube_model.png").convert()
left = pygame.image.load("cube_model.png").convert()
right = pygame.image.load("cube_model.png").convert()
top = pygame.image.load("cube_model.png").convert()
bottom = pygame.image.load("cube_model.png").convert()
# Create a list of Rect objects for each face of the cube
faces = [
pygame.Rect(100, 100, 100, 100),
pygame.Rect(200, 100, 100, 100),
pygame.Rect(0, 100, 100, 100),
pygame.Rect(300, 100, 100, 100),
pygame.Rect(100, 0, 100, 100),
pygame.Rect(100, 200, 100, 100),
]
# Draw each face of the cube on the screen
screen.blit(front, faces[0])
screen.blit(back, faces[1])
screen.blit(left, faces[2])
screen.blit(right, faces[3])
screen.blit(top, faces[4])
screen.blit(bottom, faces[5])
# Update the screen
pygame.display.flip()
# Wait for the user to close the window
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Quit Pygame
pygame.quit()
probably i just don't know how to edit an image that i'm trying to load
hm so several problems here
first, dont load the same image several times, of course you can blit the same images more than once
then, blitting should be done at any iteration of the main loop, for example 60 times per second
and so pygame.display.flip() will be the end of your main loop
what do you mean by editing the image, you want to do what now
i loaded this
your image is a black square ?
yes when i tried the option with loading it 6 times to make the net
hey there! I'm getting a really weird bug and was wondering if I'm just doing something wrong
so, I have code that lets me scroll a background image indefinitely (that, I don't plan on using afterall, because it is a bit too costly), and whenever it glides, I make in sort that every entity aside from the player (so, all npcs) are pushed alongside it (as it would be in most games, moving the background moves everything on it logically). But I am having a strange problem when there is more than one entity to move, in particular, they just don't all move
The code
def draw_moving_scene(self, screen, p:player, *ents:entity):
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
for e in ents:
if p.is_past_border():
self.back.x1 -= self.back.drawspeed
e.rect.x -= self.back.drawspeed
if p.is_before_border():
self.back.x1 += self.back.drawspeed
e.rect.x += self.back.drawspeed
if abs(self.back.x1) >= self.back.WIDTH:
self.back.x1 += self.back.WIDTH
e.draw(screen, False, (e.rect.x, e.rect.y))
p.draw(screen, False, (e.rect.x, e.rect.y))
e.rect.x -= self.back.drawspeed is what should push the entities out of the day when needed
it's a bit easier to see with a video
see?
okay so I found the problem but I can't seem to figure out something to fix it. Basically I need to get rid of the list for the moving function
because this works when there are 2 entities to move:
def draw_moving_scene(self, screen, p:player, *ents:entity):
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
if p.is_past_border():
self.back.x1 -= self.back.drawspeed
ents[0].dx -= self.back.drawspeed
ents[1].dx -= self.back.drawspeed
if p.is_before_border():
self.back.x1 += self.back.drawspeed
ents[0].dx += self.back.drawspeed
ents[1].dx += self.back.drawspeed
if abs(self.back.x1) >= self.back.WIDTH:
self.back.x1 += self.back.WIDTH
ents[0].draw(screen, False, (ents[0].rect.x, ents[0].rect.y))
ents[1].draw(screen, False, (ents[1].rect.x, ents[1].rect.y))
p.draw(screen, False, (p.rect.x, p.rect.y))
remediated code:
def draw_moving_scene(self, screen:screen, p:player, *ents:entity):
"""draw all elements of a scene and perform all necessary calculations to move objects in the scene approriately
Args:
screen (screen): The screen to blit to
p (player): the player object
"""
p.update_borders()
self.back.draw(screen, coord=(self.back.x1, self.back.rect.y))
self.back.draw(screen, coord=(self.back.x1 + screen.WIDTH, self.back.rect.y))
p.borderMoveLayer(self.back.drawspeed, self.back)
if ents:
p.borderMoveEnt(self.back.drawspeed, *ents)
for e in ents:
e.draw(screen, False, (e.rect.x, e.rect.y))
p.draw(screen, False, (p.rect.x, p.rect.y))
# Player Class
def update_borders(self) -> None:
self.past_border = self.rect.x > self.border and self.action == 1
self.befr_border = self.rect.x < self.border and (self.action == 1 and self.charaFlip == 1)
def borderMoveEnt(self, speed:float, *ent:entity) -> None:
for e in ent:
if self.past_border:
e.rect.x -= speed
if self.befr_border:
e.rect.x += speed
def borderMoveLayer(self, speed:float, *layers) -> None:
for layer in layers:
if self.past_border:
layer.x1 -= speed
if self.befr_border:
layer.x1 += speed
if abs(layer.x1) >= layer.WIDTH:
layer.x1 += layer.WIDTH
I just started learning python this week I hope I get to your level of coding
Yep! The theme for the game jam I'm participating in is "Fool the player". The type annotations are misleading, so you have to select the values based on your knowledge too. Or you can guess and have fun :)
If the program executes without any errors, you get gold, otherwise you get fool's goold(pyrite) (the other theme is 'Gold')
Tomorrow I'll be working on the combat, but I've finished everything else
Hey, I'm trying to make a window close once I click escape, I'm newish to python and would like some help if possible.
Here is the code I have right now >
import pygame
while True:
pygame.display.init()
pygame.display.set_mode(size=(1000, 1000))
pygame.display.flip()
If you can direct me to any websites or anything that will give me some sort of material of how to figure this out that’d be great.
so that will begin the instance or initialize the prgram?
oh, I thought it looked something like that, sorry. I did it last night and forgot to save, I had close to exactly that
yeah, its just hard to remember
im taking cs in school but it's not the best... teaching method you could say.
thats what ive been doing all day, ill do the same with that.
lmao alright
true
I've been on the fence for most of this stuff "python" mostly because of the things you can do with it; game development, app development, you could make an OS if you wanted.
thats the main reason I don't know some things yet, haven't researched. Thought if I choose one thing, I would switch to another. The reason I'm making a minecraft clone as my first project.
so, just start with little things, progress the way you want to but in small doses so you can understand/ comprehend what you're trying to learn as well as be able to use what you've learned with any project/ mastering it.
good idea tbh
but, other than that. Now I have to go define my verticies and make a cube in a 3d display. for the game ofc.
Not to be rude, @dawn quiver , but it is unnessasary to set the window mode and initialize every frame.
Maybe try the following instead?
import pygame
pygame.display.init()
pygame.display.set_mode((800,600))
running = True
while running:
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
pygame.display.quit()
import pygame
import sys
class Template:
def __init__(self):
pygame.init()
self.clock = pygame.time.Clock()
self.screen = pygame.display.set_mode((800, 600))
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
self.clock.tick(60)
if __name__ == '__main__':
template = Template()
template.run()
anyone can make a better one ? 🙃
Can someone explain me how to control the opacity of color in pygame?
opacity of color ? idk this
you mean alpha transparency maybe
s.set_alpha(something from 0 to 255) to change alpha transparency of a surface
s is the surface
Can you show me a exemple pls?
this is an example
the set_alpha method changes alpha transparence of surfaces
Ok thx
I want to learm
ansi codes mainly
the ansi is not necessary at all, it just makes it actually understandable
it has a background which is the same color as the actual game
this looks like textual for some reason
textual?
I appreciate that alot! Thanks for your kind words. We all get thete after a bit haha
I just started learning data types. Lol. I got a long way to go
so i hear when using get_pressed you dont need to use .KEYUP but with some reason my character still keep moving even tho i dont press any key input. can someone help me
def run_game_loop(self):
game_over = False
player_character = PlayerCharacter("game assest/pemain.png", 270, 500, 45, 45)
direction = [0, 0]
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if pygame.key.get_pressed()[pygame.K_w]:
direction = [0, 1]
elif pygame.key.get_pressed()[pygame.K_s]:
direction = [0, -1]
if pygame.key.get_pressed()[pygame.K_d]:
direction = [1, 0]
elif pygame.key.get_pressed()[pygame.K_a]:
direction = [-1, 0]
if pygame.key.get_pressed()[pygame.K_w]:
direction[1] = 1
elif pygame.key.get_pressed()[pygame.K_s]:
direction[1] = -1
if pygame.key.get_pressed()[pygame.K_d]:
direction[0] = 1
elif pygame.key.get_pressed()[pygame.K_a]:
direction[0] = -1
I fixed the aspect ratio if you’re curious
You will need to do direction = [0, 0] inside the while loop
Otherwise the last mod sticks until next direction change
Remove the first four if elif block too
It's entirely useless when the lower one exists
Alternately, you can modify the if elif chains topy if pygame.key.get_pressed()[pygame.K_w]: direction[1] = 1 elif pygame.key.get_pressed()[pygame.K_s]: direction[1] = -1 else: direction[1] = 0
^ The lower chain, the upper chain can be deleted
hmm thanks
so i just need to move the direction = [0, 0] inside the while loop
lets go it work
That, or this```py
def run_game_loop(self):
game_over = False
player_character = PlayerCharacter("game assest/pemain.png", 270, 500, 45, 45)
direction = [0, 0]
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if pygame.key.get_pressed()[pygame.K_w]:
direction[1] = 1
elif pygame.key.get_pressed()[pygame.K_s]:
direction[1] = -1
else:
direction[1] = 0
if pygame.key.get_pressed()[pygame.K_d]:
direction[0] = 1
elif pygame.key.get_pressed()[pygame.K_a]:
direction[0] = -1
else:
direction[0] = 0```
ok i will remember this too
how can i help you 
who r u
what do u mean
i need help
instead of just telling your problem here
please
u wanted to help someone there so i hoped u were a good helper
it's a server everyone can help, just don't ask to ask and dont ping for help 😉
oh ok
ok thanks
im trying to make a .exe like a launcher
15 useless messages lol
to open the game
what tool are you using for this ?
python
no, i mean to make the .exe
i dont know i just know i need to turn it into .exe
you need a library like cx_freeze to do this
i started doing pythong 3 days ago myself
im also using a macintosh i dont know if that matters
.exe on macintosh ?
i dunno im trying to making a game for Windows players
nice
cx_freeze makes completely safe exe files, but bytecode is present so it's kinda open source and there's a lot of files, so it's long to install
pyinstaller can make one file exes with all the code but it's not very good
and nuitka is probably the best choice
can u help me can i friend u on discord?
hi guys, i got a question but i wondering where should i really ask ? its about a simple question. really simple
plz
we can talk here
nuitka, pyinstaller and cx_freeze are all python libs
you can make exes with python script or cmd using them
whats best and easiest to do with mac
not related to mac, they're just python libs
you can use them with commands
and they'll create your files
why
you don't need this
no it's just about typing a command
you have to install the modules first
which one do you want to use
pyinstaller is the easiest one but it's also the worst one
why worst
def getstr(string):
while True:
if string.isalpha() and len(string) > 1:
return string
else:
string = input("Try again: ")
pyinstaller exes can be detected as malware, you have to tell it's not to play
what should i use then
nuitka or cx_freeze
i want the code to accept only string with one except that is blank space
which one better and simpler?
but i don't know how, could someone help me ?
cx_freeze is easy and 100% safe but source code is present as bytecode, and so there's a lot of small files, not the best to install and it's easy to get the code
and nuitka can bundle the code in the exe file but it's harder to use
so nuitka is good with exe file but hard to use but cx is bad with exe but easy to use?
try using --onefile to remove this; sometimes upon starting it things that the 'primer' file is a virus, where it just is there to correctly start the program.
i mean when using --one-file of course, so the code is bundled in the exe
the python interpreter is the first part, it can be detected as malware
so do i use cx or nuitka
read this
so i use cx?
adding a digital signature to the exe can maybe fix the issue with pyinstaller, signed exes arent detected as malware generaly
i think its good option?
if you don't care about having a lot of files yes
it needs to be smaller than 1gb
you'll get a folder full of .pyc files and other python related stuff
will it work?
not 1GB but can be large
like, easily 60-70MB if you're using different libraries
like numpy, pillow...
when you make a exe distribution you bundle the python interpreter and the python modules
so the players can play without installing python and the modules
python is not compiled, pygame will not be converted as machine code
you have to bundle it to make a exe with a game made with it
so what do i use tell me what do i download
which software to help
making the launcher
they are python modules
and it's not a launcher it's just making a .exe file that acts as if you run the main python file
yes
pip install cx_freeze to install cx_freeze, then you make a setup file, you run it and you get the exe
terminal
so i just open a terminal tab paste the thing and it is done`?
so do i download cx_freeze
you can easily find setup file examples on the net
you pip install it
it's a python module
like pygame or any lib
open terminal
type pip install cx_freeze
i mean, you never installed a lib ?
how do you made a game so
with tkinter ?
so you already installed a lib
i do that?
what do u mean
i put that in search?
plz dont give up on me
dont leave me
noo
its a command
commands are written on the terminal
for terminal?
so what do i do
i put the pip install autopip install cx_freeze in the terminal
now?
plz dont leave
you have to make a setup file
you can easily find example setup files on the net
can u send me
i put this?
import sys
from cx_Freeze import setup, Executable
Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"excludes": ["tkinter", "unittest"],
"zip_include_packages": ["encodings", "PySide6"],
}
base="Win32GUI" should be used only for Windows GUI app
base = "Win32GUI" if sys.platform == "win32" else None
setup(
name="guifoo",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("guifoo.py", base=base)],
)
you have to tell what third party libs you're using (like renpy)
in terminal?
this should be a python file
is it a pyhton file?
then you run the python file
so i put it in terminal
no, you create a new python file with the code
.py file
then you open terminal, go to the folder and use this command
python setup.py build
(if your python file is called setup.py)
cant u just add me on discord pleaseeeee then i can call u share my screen and u can tell me what to do pleaseeee i dotn understand
plz
pzl
yeah i dont understant that though
you know how to create a python file ?
no
so how you made a game in python
i started doing python 3 days ago by mself
without python file
.py file, containing python source code
if you don't have a python file you can't use python
well, looks like you don't really know what you're doing
the code isnt long
are you sure you have to make exe now ?
119
make exe only to distribute a finished game
sentances
otherwise just distribute the python file
it's easier for running it on all platforms
i did nothing i dont understand what u said
you don't have to make an executable / "launcher" as you call it
i dont?
make this only when you want to distribute a finished game
are you sure you have to distribute it now ?
why not
if that's just for showing it to friends just send the py file
okay make the exe
how
everything is on the doc, you don't need me
if you know what a file and a command is, you don't need anything else
do u think i can solo it
if you can create a .py file and run a command on a terminal, yes
also renpy has its own distribution thing
that is really similar to cx_freeze
DDLC is made in renpy and the lib folder is just like cx_freeze with also some linux/windows relative stuff
Is using, for example, (0,0,0) as a key to a dictionary faster than using '0,0,0' and parsing it?
why you want to parse a string containing a tuple
because of json ?
I had a system I had used at one point, before knowing you could use a tuple as a key to a dictionary, where I used keys to store coordinate values.
if you don't use json, there's no reason to not use tuples as keys
fair. I was just wondering which was faster to use, performance-wise.
idk if using a tuple as key is slower than using a string
but if you have to parse the string, i don't see how it can be better performance-wise
fair
A lot of other VNs are renpy as well afaik
it's the only renpy game i have
so i was just checking if it was cx freeze or not
ah ok
how do i turn pygame games into exe
afaik people use pyinstaller for that, but you may want to try pygame wasm on web too for platforms that don't support .exe
use cx freeze or nuitka
pyinstaller is easy to use but its bad
cx freeze is easy to use but bytecode files are present (so source code is kinda visible and there's a lot of files)
and nuitka can bundle all the code in the exe but its harder to use
File "c:\Users\Rocket v 2\Desktop\codecool\roguelike\roguelike-game-python-Ruda05\main.py", line 1, in <module>
import menu as menu
File "c:\Users\Rocket v 2\Desktop\codecool\roguelike\roguelike-game-python-Ruda05\menu.py", line 2, in <module>
from ui import *
File "c:\Users\Rocket v 2\Desktop\codecool\roguelike\roguelike-game-python-Ruda05\ui.py", line 3, in <module>
from movement import player_sprite, enemy_sprite1, enemy_sprite2
File "c:\Users\Rocket v 2\Desktop\codecool\roguelike\roguelike-game-python-Ruda05\movement.py", line 2, in <module>
from main import *
File "c:\Users\Rocket v 2\Desktop\codecool\roguelike\roguelike-game-python-Ruda05\main.py", line 18, in <module>
menu.window_start()
AttributeError: partially initialized module 'menu' has no attribute 'window_start' (most likely due to a circular import)```
Hey guys... got some bugs and dont know how to fix it... can anyone help me?
@chrome ruin check the imports in those files. Like it says, there is probably a circular import
i.e foo imports bar, but bar imports foo
so neither can get anywhere
I have solved this problem already. Thank you for your response anyway. I feel like I shall have more problems with my code XD
very nice!
Sick dude
use f strings
HAHAHH
Hey, I might need this by 31st for a game jam submission on itch.io. I've made it work before, but not with a dynamic aspect ratio. What are your thoughts on this? Is it doable with pygbag
How I initialize the display:
self.shared.screen = pygame.display.set_mode(
self.shared.SCRECT.size, pygame.NOFRAME
)
How SCRECT is defined:
user32 = ctypes.windll.user32
SCREEN_WIDTH, SCREEN_HEIGHT = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
SCRECT = pygame.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
If not I can probably just set a fixed size for the display when I'm building the game with pygbag, but just curious if this is possible
pygbag is for web right
you're using windows stuff, how can this work on web
Yeah, I was asking more if pmp had something to fill the entire browser window rather than a specific fixed aspect ratio
I could change the way I get that based on sys.platform
Something Emscripten. And yes, it is
Hi, for some reason im completely unable to create a class to render a small dot on the screen would anyone be able to help i cant figure out what im doing wrong
afaik im creating the class correctly to just be a simple rect with xy hw stuff and color
but it never shows up
hi 🙂
i'm new to coding and i just want to learn and become game development what language should i learn. can anyone advice me pls
you could ask the browser for the window size but beware that anything > 1024x600 may be too much for a lot of device like tablets or chromebooks
so better use 1024x600 ( or adjust for ratio ) and let browser upscale
Alright thanks
Make a post in the help forum and post your code
window size should be (platform.window.innerWidth, platform.window.innerHeight)
Oh that seems more cross platform
but it's not it is only valid on wasm 😄
Ah, well still useful thanks
there's not much in stdlib platform module 😦
By the way, what was the sys.platform output for pygbag exactly
on wasm it can be emscripten or wasi
All lowercase?
lowercase yes, and emscripten can run on Node or Browser
Alright, I'll check for that when assigning the window size
So I've been avoiding pygame in my learning of python so far
Is pygame a good framework? I'm no artist, so I don't need something that does fancy 3d models, or uses meshes and textures
Hi i'm a beginner with Pygame and i'm looking for people to code with. I make somewhat good pixel arts too and i can make sprites
It's not made for 3d work afaik
well that's a bonus then :)
I'm kinda working on a texted based adventure and was thinking of improving it to have a visual clickable inventory, colours, maps etc
Oh I thought you said you need it, well for 2d games i can vote for it for sure
This is my current project if that helps, but you should probably check out dafluffypotato on YouTube to see its capabilities
re 3D games, I'm sure I read a tutorial about those a day or say ago
lemme browse my history
ah sorry I was looking at Panda3D
so pygame is 2D
cool
Sounds like just what I want
peak action in my game
You can try participanting in PyWeek #1084299721151090698
Hello can someone help me with turtle GUI?
I couldn't get help from the python-help :3
how you made this.. i what to know
like ik some basics so is it with pygame?
yeah, its written using pygame
how do you get pygame to work on mac?
it just does, what specifically does not work for you
I'm making a game like a infinite jumping game so like i have a baground which is like a mountain on the bottom so like when i wanna make the baground infinite so the baground keeps on repeating but u wanna use another baground for clouds but i wanna loop the clouds baground not the mountain one
Anyone help me
like doodle jump?
Yepp
ive made one like that before
Like doodle jump
Niceee
But i really want the first baground same but wanna loop the 2nd baground again and again
Help me pls
In this Python tutorial I code an endless vertical platformer using the PyGame module. I'm going to explain how to add an endlessly scrolling background.
Code & assets on my website: http://codingwithruss.com/gamepage/Jumpy
Alt link on github: https://github.com/russs123/Jumpy
Credits for assets used:
https://free-game-assets.itch.io/free-obje...
this might be helpful
Can anyone help me fix my code?
im having trouble create a tictactoe game can anyone help
if self.left:
self.x -= self.speed
sleep(0.1)
elif self.right:
self.x += self.speed
sleep(0.1)
elif self.up:
self.y -= self.speed
sleep(0.1)
elif self.down:
self.y += self.speed
sleep(0.1)```
for this simple snake game, im trying to make it so that it waits for .1 seconds before moving again, but, when it sleeps, it pauses the code, preventing any inputs from user, preventing the player to move 50% of the time. what is a solution?
can someone give me a quick recap on raycasting? i want to make a doom-like horror game
I don't think there are IDEs for pygame
Personally I just use VSC with the recommended python plugins
Have any of y'all put pygame into an open ai gym
@vagrant saddle i've been waiting for a few minutes now.. but it seems to be blank
can't tell what i did wrong, I:
Build zip
pygbag --archive game_folder
Uploadgame_folder/build/web.zip
have a link ?
It's draft, anyway i can make it so only you can see it?
eh screw it, ill make it public
the jam is almost over anyways
This is my version info
(venv) devex pip show pygbag
Name: pygbag
Version: 0.7.1
Summary: pygame wasm, package and run python/pygame directly in modern web browsers.
Home-page: https://github.com/pygame-web/pygbag
Author: Paul Peny
Author-email:
License:
Location: D:\d\p\devex\venv\Lib\site-packages
Requires: token-utils
Required-by:
awesome work btw, i wouldnt be participating in game jams using pygame if it werent possible to upload to the web
hmm..okay silly mistake, i didnt check to make sure the code i was building actually worked
now i did, and packaged that code with pygbag
but yeah, same result
okay, update, it shows the first frame in the embed
but then it stops
so i know for sure my code is working to have reached that point
after i click "stop" when firefox prompted that it was slowing down the browser this happens
but its static
is it just... really laggy?
i do have one successful pygbag project from a while back
tried using an older pygbag version too.. 0.1.5.. but it doesn't seem to be working(almost the exact same result)
I give up.. I'm going to submit the game for now and then maybe add the browser support later
please look at this #1091401732967366818
firefox is usually way slower than chromium based browser, also size of rendering surface has a lot of impact on speed
it has been set to 1024x600 like you suggestd
and i tried edge too, i dont have chrome
so you fixed Game.run to run async but not yet published
oh shit....
i completely forgot the async part
😅 .
let me uh, well, do that
also side note, how do you add an image to a submission
end of game.py should be something like ```py
async def run(self):
while True:
self._update()
self._draw()
await asyncio.sleep(0)
def main():
game = Game()
asyncio.run( game.run() )````
maybe it's the screenshot section
i looked there but there doesnt seem to be an option to add one 🤔
maybe the submission takes the cover image ?
hmm, ive given it all possible images though (bg, bg embed, image)
okay now moment of truth, running it with async
!!
thank you @vagrant saddle
i used the link you posted earlier which led me to https://v6p9d9t4.ssl.hwcdn.net/html/7619482/index.html
maybe it's not updated
i have updated it now
yep it works now
it looks questionable with the limited display size lol, but hey it works
Updated game link, it was the only way to get the image
https://itch.io/jam/april-fools-day-jam/rate/1995767
A game where you play as the developer. Play in your browser
Do you sort sprites by there y position?
well hmm
yeah so sprites higher in y would be farther back and should be sorted to the back
you just need to decided what y position exactly to sort. Id probably find the bottom center of your sprite and use that.
This is the way
blit in order of lowest to highest and you've got a nice overlap system
Hello
how to detect with pygame multi-keyboards events ?
(by example : KEY_A + KEY_B)
import pygame as pe
for event in pe.event.get():
# two key detections :
if event.type == pe.K_a and event.type == pe.K_b:
# do something
Ellipsis
little example with python
PROBLEM solved :
if pe.key.get_pressed()[pe.K_a] and pe.key.get_pressed()[pe.K_b]:
print("a and b pressed !!!")
So I noticed that a lot of games use .pkg or .pk files to compress their files. Is it just a modified .zip file? If not how can I make a .pkg file in Python?
tipe on google i think bro
hey i have annother problem :
def who_win() -> bool or None:
"""player won : true for player 1 and false for player 2 else None"""
global matrice
def rangef(enumeration: any) -> None or bool:
"""return true only if all are true"""
global matrice
cptA = 0
cptB = 0
for x, y in enumeration:
if matrice[y][x].s:
cptA += 1
elif not matrice[y][x].s:
cptB += 1
print(f"x,y = {x, y} matrix.s ={matrice[y][x].s}")
return True if cptA == 3 else False if cptB == 3 else None
# cut the one-liner
forall = [[[x, y] for x in range(3)] for y in range(3)]
forall += [[[y, x] for x in range(3)] for y in range(3)]
forall += [[0, 2], [1, 1], [2, 0]], [[2, 0], [1, 1], [0, 2]]
for combi in forall:
if rangef(combi) is not None: res = rangef(combi)
return res
# In main loop :
if who_win() is not None:
print(f"player {'cross won' if who_win() else 'circle won'}")
carry = False
elif checked == 9:
print("no one won")
carry = False
why this call is always True ? (matrice[y][x].s is None or False or True)
isnt pkg like msi for mac ?
also file archive extensions arent uniform, a lot of games use the same format but the data isnt stored in the same way
UE5's .pak files and popcap's .pak files arent the same
or .arc files from nintendo arent the same thing depending on the game
you can use a modified zip, however decoding it will take time and some ram to decode it, especially if you don't want to temporarily store the decoded files
a lot of proprietary archive files in games are xor encrypted non-compressed files
and then they have a function to read the bytes and they can open the files nearly at the same speed than non-archived files, but encryption is weak, and you should not write this in python too
if you want to make a proprietary compressed archive file in python i can just recommend you to split into different archive files to avoid this
also, keep in mind music files should be streamed instead of being loaded in ram, so if you have large wav/ogg or even mp3 files, you'll have to store them somewhere in temp folder
you should focus on this (from most important to less important)
1 - loading time
2 - compression
3 - encryption
4 - amount of files
class Grass( pygame.sprite.Sprite ):
def init( self, image, x, y, rotation=None ):
pygame.sprite.Sprite.init(self)
if ( rotation == None ):
angle = random.randrange( -1, 0 )
self.image = pygame.transform.rotozoom( image, angle, 1 )
self.rect = self.image.get_rect()
self.rect.center = ( x, y )
pygame.init()
window = pygame.display.set_mode((window_WIDHT, window_HEIGHT))
grass_image = pygame.image.load( 'Back 2.png' ).convert_alpha()
all_grass_sprites = pygame.sprite.Group()
for i in range(50):
new_x = random.randrange(window_WIDHT)
new_y = random.randrange( window_HEIGHT )
new_grass = Grass( grass_image, new_x, new_y )
all_grass_sprites.add( new_grass)
however i can't get the grass image clones to move pls help me
Latest Devlog here: https://youtu.be/ZkQD9Uu8jTM Chungette, Particle Updates, and More!
In this week's devlog I show Chungette and talk about updated particle effects.
#indiegamedev #devlog #gamedev #gamedevelopment #indiedev #python #pygame #pygame-ce #pythongaming
Hi, I'm making a spaceflight simulator, I want someone who knows about astrodynamics and has experience with python. it needs a lot of calculation. my code is on GitHub page https://github.com/Jackcybox007/spacecraft-simulator. I have been coding it for a few days now. if you are interested in this please DM me for more information.
I am making a zelda like game using pygame and i have 2 questions:
How can online multiplayer be implemented?
How can a "save game progress" be implemented?
for online you should use networking/sockets
and game save can just be a text file, but i recommend using a python dict as json or pickle (both are builtin python things)
hello I have this function to see if a polygon contains another polygon and I don't know why it doesn't work.
def polygon_contains_polygon(poly_points1, poly_points2):
# Check if either polygon is empty or has less than 3 points
if len(poly_points1) < 3 or len(poly_points2) < 3:
return False
# Calculate the bounding box of polygon1
xmin = min([p[0] for p in poly_points1])
ymin = min([p[1] for p in poly_points1])
xmax = max([p[0] for p in poly_points1])
ymax = max([p[1] for p in poly_points1])
# Check if any point of polygon2 is outside the bounding box of polygon1
for p in poly_points2:
if p[0] < xmin or p[0] > xmax or p[1] < ymin or p[1] > ymax:
return False
# Check if any point of polygon2 is inside polygon1 using the ray casting algorithm
inside = False
for i in range(len(poly_points2)):
j = (i + 1) % len(poly_points2)
intersection = 0
for k in range(len(poly_points1)):
l = (k + 1) % len(poly_points1)
if do_lines_intersect(poly_points2[i], poly_points2[j], poly_points1[k], poly_points1[l]):
intersection += 1
if intersection % 2 != 0:
inside = not inside
return inside
# Helper function to check if two line segments intersect
def do_lines_intersect(p1, p2, q1, q2):
def ccw(a, b, c):
return (c[1] - a[1]) * (b[0] - a[0]) > (b[1] - a[1]) * (c[0] - a[0])
return ccw(p1, q1, q2) != ccw(p2, q1, q2) and ccw(p1, p2, q1) != ccw(p1, p2, q2)
My game i have it saved in a csv file for some reason?
But i agree, use a dict
i got an assignment due to make a 2d adventure game and ibr i have no clue on how to start, are there any channels or videos i can look at?
csv is not really made for games i guess
json is just for dicts but can be modified by humans very easily
and pickle is not just about dicts, its about every python object
use pygame
okay thank you
Which software did you used for creating that graphics?
dafluffypotato uses pygame and sometimes moderngl or pyopengl idk
Pygame and ModernGL, yeah
Hey, is there a way to create platforms colision without having to make a list of every blocs ? I'm trying to create a little platformer but eveything that I found online use a giant list for every bloc in the game to achieve colisions
Optimization is absolutely essential for infinite worlds. This video covers a well optimized method for infinite tile-based worlds. I also discuss the concept of optimization more generally.
Project Download:
https://dafluffypotato.com/static/platformer_project_4.zip
Discord: https://discord.gg/9Qt2GxF
Twitter: https://twitter.com/DaFluffyPot...