#game-development
1 messages ยท Page 65 of 1
I'm working on making a solitaire game in python
Is it just handling the MOUSEUP and MOUSEDOWN events?
I think so
@jade owl here's a solitaire tutorial: https://arcade.academy/tutorials/card_game/index.html
hey guys, how are you doing?
Hey, check this out:
I'm creating a web based game, I'll need to have some kind of map, but it's not a common map, its like a galaxy map, a good example is stellaris maps, how can i do something like that in js?
something like this
i dont need that lines and symbols, just a big galaxy generated with data that I've created
with some very basic interaction, like: click a galaxy and zoom in to the planets
hello i am using pygame how can i make my movements smooth?
You should
how?
clock = pygame.time.Clock ()
my movement is still choppy
And clock.tick ()?
How much have you put
60
Put 100
import pygame, sys
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption('BoxBoxTriangle')
clock = pygame.time.Clock()
player = pygame.image.load('assets/player.png')
x = 100
y = 100
width = 50
height = 50
vel = 2
while True:
for event in pygame.event.get():
if pygame.event == pygame.QUIT:
pygame.quit()
sys.exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x <500 - width - vel:
x += vel
if keys[pygame.K_LEFT] and x > - vel:
x -= vel
if keys[pygame.K_DOWN] and y <500 - width - vel:
y += vel
if keys[pygame.K_UP]and y > - vel:
y -= vel
win.fill((192, 192, 192))
win.blit(player,(x,y))
pygame.display.update()
clock.tick(100)
@ionic depot
Put 1000 , 700 at pygame.dsiplay.set_mode ()
And then add more at clock.tick
For me it moves smoothly
When I added more' speed'
Or just make the player smaller
Idk if it works that way
@dawn quiver
@ionic depot thx
So , it works?
import pygame, time
pygame.init()
win = pygame.display.set_mode((800, 600))
textCol = (255, 255, 255)
textFont = pygame.font.Font('freesansbold.ttf', 32)
def drawMenu():
global rect
rect = ((50, 50, 50), (400 - 34, 100, 80, 30))
rect = pygame.draw.rect(win, rect[0], rect[1])
text = textFont.render("Start", True, textCol)
textPos = (400 - 32, 100)
win.blit(text, textPos)
def drawBack():
global windowRGB
winRGB = (0, 0, 0)
win.fill((winRGB))
time.sleep(1)
winRGB += 1, 1, 1
drawBack()
drawMenu()
pygame.display.update()
So I have this but the background never changes colour.
You are indeed drawing it only once. You need to put all this in a loop so that it is drawn every frame
Oh yeah, thanks so much
now it is saying
`Traceback (most recent call last):
File "C:/Users/olive/Downloads/Wenrex/Menu.py", line 24, in <module>
while winRGB != (255, 255, 255):
NameError: name 'winRGB' is not defined
`
but it is
oh i see nvm
def drawSecret():
global secretRect
if secretButtonPressed:
textCol = (255, 255, 255)
textFont = pygame.font.Font('freesansbold.ttf', 96)
text = textFont.render("SECRET FOUND!", True, textCol)
textPos = (0, 300 - 96 // 2)
win.blit(text, textPos)
pygame.time.delay(100)
textCol = (0, 0, 0)
pygame.time.delay(100)
secretRect = ((80, 80, 80), (429, 114, 4, 10))
secretRect = pygame.draw.rect(win ,secretRect[0], secretRect[1])
I have this
and this is in while true loop
drawSecret()
but the text doesnt change colour
Hello
:3
how do you make code repeat 60 times per second?
put it on loop
yeah but how do you make it 60
do tick.clock(60)
but you need to make an var
clock = pygame.time.clock()
in using tkinter
og
ok
I started studying pygame through school, and theres a question here I got stuck on.
I need to draw 100 lines from the center of the screen, all in the length of 350, to create a "circular" shape from all the end points.
I'll send an image as an example
my issue here is purely mathematical, I know how to draw lines its just I have no idea how to perform the movement to achieve this shape
I assume its something to do with trigonometry
all the endpoints are of the form center + radius * (cos(angle), sin(angle)) idk if this helps
the reason is that cos and sin are the projections on the x and y axis of a unit vector of a given angle, so you can get the (x, y) coordinates of a vector with a given angle this way
then scale it radius * ... and shift everything so the center (0, 0) become center so center + ...
I'll try this, thank you
Okay, it comes out pretty close to the end result
it comes out like this
where my code is like this:
for i in range(100):
pygame.draw.line(screen, (255, 0, 0), [350,230], [350 + 250*math.cos(i), 230 + 250*math.sin(i)], 1)
pygame.display.flip()
So I wonder what im doing wrong
the center point here isn't (0,0), its worth mentioning that
its 350,230
240*
cos and sin want angles in radians, so between 0 and 2*pi. If you want equally spaced rays, you will want the angles to be equidistant in [0, 2*pi]
With n rays, it the distance between two angles is 2*pi/n so the i'th angle is i * 2 * pi / n
while True:
event = pg.event.get()
if event[pg.MOUSEMOTION]:
print("Moved")
not working please help
while True:
event = pg.event.get()
if event.type == pg.MOUSEMOTION:
print("Moved")
ok
AttributeError: 'list' object has no attribute 'type'
So I have an importable script
on my scripts
Hello, Im working with Pygame, and Im trying to create a collision system where when my player runs into a rect, its velocity will be reversed (i think thats how it works) so that the player cannot move into the object/rect. I have been looking for a while and Ive not found much. Ive tried a few methods and none have working. Here is my code: https://gist.github.com/ethanedits/391c2e655ce637e655b37d6a736cee09
any help would be greatly appreciated
Also the speed is based on FPS which is annoying
Hi, I'm not really sure if this counts as game development but in school we were assigned to create a Rubik's Cube Solver and I never coded before so I have no clue where to start. Can anyone just give me a good starting point or some IDE's that might be useful? Thanks in advance! ๐
visual studio code for an IDE, and do u mean create a game or a robot that solves a rubiks cube
Create a game, where you can scramble the cube and it finds the fasters route to solve it
can anyone help me with a socket io game im working on
@jolly sigil download Pygame ๐
lmao i hate pygame now after making a platformer a year ago
@jolly sigil download Pygame ๐
@glossy gust You don't need graphics to do this... you need to 1) learn python 2) write down precisely what the movement of the cube are 3) implement how you would solve the cube by hand
And 4) if you are very good, learn how good algorithms work to solve it in a few movements (they are quite complicated and interesting)
Thanks guys, I've downloaded all the programs now and I'm starting to decompose the problem. Fingers crossed it all works out ๐
@sacred trout my bad I thought he needed graphics to show what the cube looks like
like colors
@sacred trout my bad I thought he needed graphics to show what the cube looks like
Yeah, i wanted to have a 3D simulator of what the cube looks like so that the user can rotate it and have a look at it. I don't know if that's too ambitious though...
Your whole project is ambitious, but doable ๐
It is a bit more than a one weekend project if you've never coded though
Yeah I agree.. it's going to be pretty hard. We have the whole academic year to finish it though so I think I have time to learn ๐
That's cool !
Then you just need to start by learning python. First objective could be to code a "guess my number" game in python after learning about loops and conditions
hey i am currently trying to make a text based game in python becuase i wanted to try something else after doing it in C++
i made a prototype for it in C++ and it was a good prototype, it was a turn based rock paper scissors rpg type of game. and i balanced a lot of it for melee combat but i have no idea how to balance it if the player wants to used ranged attacks
the way it works is each there are three types of melee attacks and defenses, each count the same attack and defense. aka pierce attacks are countered by parries. and if the same attack hits each other they get into a bind, if two defenses hit nothing happens.
if you block an attack you get a pot shot in as well. but i cant seem to find a way to make bows and arrows/ranged magic fit into this system
there is melee magic
but not ranged. and i dont know what to do for it
i could make ranged spells and bows be a special move used once per turn
but idk
maybe that will be what will be done but idk
Can anybody here please help me with my issue from before? #game-development message
@signal root What is the error
You could use if
if player.collidepoint(rect.collidepoint):
touchingWall = True
Then in your walking thing
if touchingWall:
return
before the rest of the code in that function
how do i make games?
like minecraft
(i only know till if and else statements)
anybody?
There is a lot of work from just if/else to something like minecraft. @dawn quiver
Do you know about OOP ? Classes, methods, functions ?
Loops (while/for) ? Lists ?
If not, you should learn basic python stuff before trying to make such a big game.
There are good resources listed here :
!resource
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
k cries
@lusty oyster I apologize for not giving you an error, the previous methods ive tried did not give me an error, I just didnt get the collision. And for the code you provided. i would put ```python
if player.collidepoint(rect.collidepoint):
touchingWall = True
Ok
so
if player.collidepoint(rect):
remove collidepoint on the rect
should work
@signal root
remove collidepoint on the rect
@lusty oyster what do you mean by this?
where
i get that, this is where i would stop my player, reverse velocity etc
but where would i put this if statement? It needs to be constantly run to check if a collision happens
So would i just throw it in an infinite loop?
@lusty oyster
keys = pygame.key.get_pressed()
if keys[pygame.K_a] and man.x > man.vel:
man.x -= man.vel
man.left = True
man.right = False
elif keys[pygame.K_d] and man.x < scrWidth - man.width - man.vel:
man.x += man.vel
man.right = True
man.left = False
elif keys[pygame.K_w] and man.y > man.vel:
man.y -= man.vel
man.left = False
man.right = False
elif keys[pygame.K_s] and man.y < scrHeight - man.height - man.vel:
man.y += man.vel
man.left = False
man.right = False
else:
man.right = False
man.left = False
man.walkCount = 0
if player.collidepoint(rect):
print("Collision!")
redrawGameWindow()
like that
@lusty oyster (should i ping u or no?)
I moved it above the keys bit, and below the for event loop. Now im getting an error: 'player' object has no attribute 'collidepoint'
@lusty oyster
hm
would you like me to put my code in a pastebin or something
collision detection in pygame
Have you watched this vid?
In this video I explain how to check if two objects are colliding. We will test if the projectile shot from our character enters the hit box of our enemy. All of this is done in python 3 using the module pygame. If you are having any trouble following along leave a comment dow...
yes
And?
colliderect
Wow
try that
Hey @signal root!
It looks like you tried to attach file type(s) that we do not allow (.zip). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .svg, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .webm, .webp, .flac, .afdesign, .m4a.
Feel free to ask in #community-meta if you think this is a mistake.
bruh
Hey @signal root!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
I have a super weird problem
my if statement
I first print it (it prints False)
wait nvm I got an idea
@ionic depot can u help me out with the collision detection
do you know how to do collisions
hey all
does anyone have any recommendations for 3d physics engines to implement in an existing engine?
have been looking at pybullet but I'm not sure what's out there or what's best for the job
my only requirement is that i can apply arbitrary forces to objects (i'm trying to make a fancy boid simulation)
thought this might be the best place to ask ^^
I dont have any suggestions for a physics engine, but are you creating a 3d engine in python?
@icy steppe
I dont have any suggestions for a physics engine, but are you creating a 3d engine in python?
@signal root not a full engine, just a harness for running some simulations I've gotta run
I was rolling my own physics engine up until now, but it's become too much work than it's worth
๐ no problem
it's something for my work so I can't divulge too much info but I can talk about it a little bit
alright
(removed because i'm sure that this was probably personally identifiable info)
and it doesn't display realtime actually, it renders out to a few different filetypes
the main one I use is SVG, and I just did a lot of cheap tricks with translate3d to get that to work hehe
it's not as solid as it should be to be honest but it works really well for our use-case
sounds interesting. I dont have much experience in the 3D physics world, so i cant give you any useful info, but good luck!
Ask a professional ...
lol
:))
I am a professional ahaha
I've just never had to write physics simulation code this complex
hence why I assumed that #game-development would help :p
Yeah
usually I write in Ruby! this gig is new to me
so I'm real unfamiliar with the python ecosystem
thanks!
@Dp_dontmiss Pls accept the invitation of kermit
@ionic depot with Python? or with writing code in general?
ion know I walked into an interview lol
5-6 yrs professionally, I'd say 11 years as a hobby
would have to check my linkedin to be sure
ion know that i walked into an interview lmao
Have you build an AI till now?
oh yeah? What for?
very cool
Yeah
take some interesting readings: https://faculty.ist.psu.edu/vhonavar/Courses/ai/studyguide.html
Thank you!
no problem
Hello, ive been workign with pygame trying to do a collision system. and ive been having issues with my code. Basically I have a player class, and inside that player class there is a self.rect which is equal to pygame.Rect blah blah blah. thats all well and good, and I can see that rect is working because I drew it, and it displays the correct size and all that. Now my main issue is when I try to detect collisions with other rects. I tried doing python if player.rect.colliderect(rect): print("Collision!") and I just get an error saying type object player has no attribute rect even though i assigned it self.rect. I dont know why this isnt working. Here is my full code:https://gist.github.com/ethanedits/c9d0eaa5bf90a7a9a8085fae86a0bcfa
I think you meant man.rect, not player.rect
This is why it's a good idea to capitalize class names
ill try that out
what's the difference between community pycharm and pro
community pycharm is pycharm pro, but a version that's about 6 months old, iirc. It should be fine for pretty much 100% of users.
is coding hard?
at times, yes. At other times, also yes. But practice makes it easier.
@tranquil girder i did that, same error
You haven't defined rectanywhere. The one you're trying to colliderect with
line 86, in <module>
if man.rect.colliderect(rect):
NameError: name 'rect' is not defined
Ok, so i tried doing this instead: ```python
if man.rect.colliderect(wall.rect):
print("Collision!")
@tranquil girder
Ok, so how would i reference it if its from pygame?
False
But again, you're referencing the class and not the instance
the instance is called collider1
Yeah, the rects don't update either, so they will never collide
ok
so instead of rects i should be using sprites?
What if I want a invisible collider
@tranquil girder
I don't know much pygame, sorry
oof ok
I can't seem to animate pygame movement properly despite having all the files needed...
i think general is a bit busy so ill try here because my code is a game
i think its simple but i dont know why it doesnt do what i need it to do
basically
when a player types in an attack a bool goes true
when the enemy then reacts to that then selects an attack another bool goes ttrue
when both are true it prints that i got that far
but it doesnt
@cinder nacelle I will be happy to help you out later tomorrow. I apologize if you need assistance earlier than that, but just dm me or ping me tomorrow (Iโm EST time) and Iโll help you out ๐
Thanks
import pygame as pg
pg.init()
display = pg.display
MODE = pg.RESIZABLE
win = display.set_mode((400, 300), MODE)
image = pg.image
transform = pg.transform
class Player:
def __init__(self, sprite, size, pos):
self.sprite = image.load("Llama.png")
self.size = (200, 200)
self.pos = (200, 100)
self.sprite = transform.scale(self.sprite, self.size)
player = Player()
win.blit(player.sprite, player.pos)
How do I fix this?
I get
Traceback (most recent call last):
File "C:/Users/olive/Downloads/main.py", line 20, in <module>
win.blit(player.sprite, player.pos)
NameError: name 'player' is not defined
>>> ```
import pygame as pg
pg.init()
display = pg.display
MODE = pg.RESIZABLE
win = display.set_mode((400, 300), MODE)
image = pg.image
transform = pg.transform
class Player:
def __init__(self, sprite, size, pos):
self.sprite = image.load("Llama.png")
self.size = (200, 200)
self.pos = (200, 100)
self.sprite = transform.scale(self.sprite, self.size)
player = Player()
win.blit(player.sprite, player.pos)
I get
Traceback (most recent call last):
File "C:/Users/olive/Downloads/main.py", line 20, in <module>
win.blit(player.sprite, player.pos)
NameError: name 'player' is not defined
>>>
:incoming_envelope: :ok_hand: applied mute to @lusty oyster until 2020-09-30 06:30 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
!unmute 413916672001441793
:incoming_envelope: :ok_hand: pardoned infraction mute for @lusty oyster.
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
@signal root can you help me with sprites?
please use
thanks
wdydmddwdyam
import pygame as pg
pg.init()
display = pg.display
MODE = pg.RESIZABLE
win = display.set_mode((400, 300), MODE)
image = pg.image
transform = pg.transform
class Player:
def __init__(self, sprite, size, pos):
self.sprite = image.load("Llama.png")
self.size = (200, 200)
self.pos = (200, 100)
self.sprite = transform.scale(self.sprite, self.size)
player = Player()
win.blit(player.sprite, player.pos)
yes
Traceback (most recent call last):
File "C:/Users/olive/Downloads/main.py", line 18, in <module>
player = Player()
TypeError: __init__() missing 3 required positional arguments: 'sprite', 'size', and 'pos'
>>>
yeah you need to give 3 args to Player()
so waht do i give it
class Player:
def __init__(self, sprite, size, pos):
self.sprite = image.load("Llama.png")
self.size = (200, 200)
self.pos = (200, 100)
self.sprite = transform.scale(self.sprite, self.size)
player = Player(sprite, size, pos)
win.blit(player.sprite, player.pos)
not work
Traceback (most recent call last):
File "C:/Users/olive/Downloads/main.py", line 18, in <module>
player = Player(sprite, size, pos)
NameError: name 'sprite' is not defined
>>>
okay wait
coding is a pain in the fing ass
class Player:
def __init__(self):
self.sprite = image.load("Llama.png")
self.size = (200, 200)
self.pos = (200, 100)
self.sprite = transform.scale(self.sprite, self.size)
this should be the class
still same error
you don't need to specify sprite, size, pos in the init because you are creating those inside init
now change back player = Player()
is it better to have a different class for each sprite, or one class for all sprites
@dawn quiver
uhh you are creating a sprite as an attribute to each player
?
what does that mean
pg.draw.rect(win (0, 0, 0), (player.pos, player.size))
Traceback (most recent call last):
File "C:/Users/olive/Downloads/main.py", line 44, in <module>
pg.draw.rect(win (0, 0, 0), (player.pos, player.size))
TypeError: 'pygame.Surface' object is not callable
>>>
you're missing a comma after win
ah yes thank you
hello dear pythonians, i need some help.๐ i am trying to install questionary (https://github.com/tmbo/questionary), but the install fails spectaculary (i am on windows unfortunately, my editor is VSCode)... i have no experience with this error as of yet
hello dear pythonians, i need some help.๐ i am trying to install questionary (https://github.com/tmbo/questionary), but the install fails spectaculary (i am on windows unfortunately, my editor is VSCode)... i have no experience with this error as of yet
@hasty sand i solved this problem with some help from the roguelikedev community, thanks HexDecimal over there. usin py -3 -m pip install questionary worked...
Hey, I can help in a few hrs (sorry) I have a class rn
yes
I just came back from dinner
are you alright with looking at it from a stream perspective?
@lusty oyster
ok
damn
hmm
call?
alright
Weird
import pygame, sys
pygame.init()
#screen
win = pygame.display.set_mode((500,500))
pygame.display.set_caption('BoxBoxTriangle')
clock = pygame.time.Clock()
#player
player = pygame.image.load('assets/player.png')
player1 = player = pygame.transform.scale2x(player)
x = 50
y = 60
width = 100
height = 100
vel = 5
#tornadoe
tornadoe = pygame.image.load('assets/tornadoe.png')
tornadoe = pygame.transform.scale2x(tornadoe)
tx = 50
ty = 64
twidth = 100
theight = 100
#earthquake
earthquake = pygame.image.load('assets/earthquake.png')
earthquake = pygame.transform.scale2x(earthquake)
ex = 50
ey = 64
ewidth = 100
eheight = 100
#main loop
while True:
for event in pygame.event.get():
if pygame.event == pygame.QUIT:
pygame.quit()
sys.exit()
#playermovementkeys
players = player.copy()
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x <500 - width - vel:
x += vel
if keys[pygame.K_LEFT] and x > - vel:
pygame.transform.flip(player, True, False)
x -= vel
if keys[pygame.K_DOWN] and y <500 - width -vel:
y += vel
if keys[pygame.K_UP]and y > - vel:
y -= vel
win.fill((199, 199, 199))
win.blit(player,(x,y))
pygame.display.update()
pygame.time.delay(60)
clock.tick(100)
i am trying to flip an image
how can i do it
i am trying to do it by if the player presses left arrow key
the image flips to the left
but it doesnt seem to work
any help
hey guys can you recommend any tutorial series to code a python jump and run game?
watch tech with tim
or watch learn pygame by making flappy bird
begginer myself but after 3 days
i already know how to make an screen make an image move using keyboard
movement
ietc
etc
ok thx
player image @ionic depot
What exactly are you trying to make?
And?
You should add more
Sprites to the left and right
i ended up with diferent sprites
so when i move left
the sprite for left moves
left
but the sprite for the right
You followed the tutorial provided by tim?
You should
i dont watch him anymore
Why?
i dont need the animated sprites
He has some good vids
i still watch his other vids
i said the fix for the flip lol
Is there such a thing as 'erasing a shape from another shape' in pygame (e.g. removing a small circle from a big circle to form a ring shape that is drawn by pygame)
yes
Okay
You should find a list of images for player's movement
Go and search on Google
i just need to fricking flip the fricking image!!!!!!!1
well actualy you can
How
using pygame.transform.flip(player, True, False)
it will flip the image
the player is an variable
player = pygame.image.load('assets/player.png')
please Dp_dontmiss accept the inviation
plzzzzzzzzzzzzzzzzzzz
who like rainbow six here
@dawn quiver This is for game development, not asking about games you play.
yes
its true
it s just a question
@spare phoenix accept the invitation of kermit pls
!warn 735559934619549879 posting random gifs in #game-development and begging another user repeatedly for accept an invitation
:incoming_envelope: :ok_hand: applied warning to @dawn quiver.
i don t post random gifs
!tempban 735559934619549879 7d You were warned and you insisted on continuing. You are welcome to comeback if you actually want to be a part of the server
:incoming_envelope: :ok_hand: applied ban to @south sinew until 2020-10-07 14:01 (6 days and 23 hours).
?
:))
pygame has no init member
???
Module 'pygame' has no 'init' member pylint (no-member)
it's not running because it keeps saying that something called mkl service isnt installed
Hey @cinder nacelle!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
pylint is just a warning that maybe something is wrong. Do you get an actual error message when running the code?
Yes , he does
pylint is just a warning that maybe something is wrong. Do you get an actual error message when running the code?
@unique dragon Please install mkl-service package
And then quit ()
Can you screen shot that error message if pygame.quit() doesn't fix it?
There are missing a lot of things in your code
Actually, quit is already being used so I don't think that's needed again
Huh?
That's just a warning message, your actual error is just below it
You are using QUIT but Python doesn't know where QUIT is coming from
If you see the red lines in your code, VS Code is showing that is doesn't know what the variables are
@ionic depot Dial down a bit thanks, no need to come across like that
thanks @ionic depot
??
its working now
i added "pygame." on everything
Good job
@stable lodge
how to host a anitispam bot like mee6 24/7
What music formats does pygame support?
Arcade 2.4.3 is out. Release notes will appear here soon: https://arcade.academy/release_notes.html
Ohh I just used that
yes
ok great
do you guys use any resources for pygame?
like is there a tutorial to get me started anywhere
i have an idea i want to make it's a ninja star throwing game
no i figured I would start with a project
A simple game?
Hmm
Start with simple games
And then build the game from what you've learned
@gilded grove
it would basically just be like a reflex game
you have your character and some other person running at you and you have to throw a shuriken
Idk what to say
i'll watch some videos to teach myself and then get back here
If you are new to pygame , you should start with small things
like what
An example
Snake game
Or chess game
Any game from what you can learn stuffs
In order to make a game by yourself
ok
Good luck
thank you
@gilded grove another good example of game could be flappy bird
i'll try following some videos first before making games
do you think the ninja star throwing game is too difficult for a beginner
Understand them
What is that ... why is it there ... how does it work ...
Ask yourself
I really don't know
It depends
guess I'll find out
Yeah
Not sure I understand
but at first glance, iterating through a dict seems like something that can be done faster
I see
First of all, it's more convenient to iterate over only the dict values
with myDict.values()
another thing you can do, is to approximate math.hypot
by adding the numbers instead of doing math.hypot for example
then you can at least filter out most of the foods
also, min probably needs to run its own loop
so it's better to have that be part of your main loop
instead of math.hypot(a,b) then abs(a) + abc(b)
@prime juniper
it also depends on what on the rest of the code
like...
if you're running this on every frame
you know that nothing changed between two frames
they spawn every frame?
yeah! that's probably the best
import pygame
#initalize the pygame
pygame.init()
#create the screen
screen = pygame.display.set_mode((800,600))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
um i don't know why my window isn't popping up on repl.it
pygame decided to sue repl, so then repl blocked them
I canโt find anything saying it got banned
anyone knows where to download sprite sheets?
help
Any solid reson to code game on python? Am planning but people suggest me C++ no hates tho......
help
@dawn quiver which IDE is this?
oh thnx ๐
np
@cinder nacelle which variable is the error referring to?
@stuck stone lmao
That's not necessarily
But repl.it is really REALLY bad with sharing graphics.
Normal terminal programs work well, but when you go to video, it is bad.
The framerate is bad and the compression is bad.
It could also be a region problem
@cinder nacelle i dont care what ide you use i am happy with my ide i am asking for help on my error not you're opinion on my ide
so pls stop wasting my time
@dawn quiver well your sprite is a Surface object not a Rect object, so your probably mixed up what you assign sprite as
so how do fix that
show you code relating to the sprite object?
import pygame, sys
pygame.init()
#screen
win = pygame.display.set_mode((500,500))
pygame.display.set_caption('BoxBoxTriangle')
clock = pygame.time.Clock()
running = True
#variables
#player
player = pygame.image.load('assets/player.png')
player1 = pygame.transform.scale2x(player)
x = 150
y = 150
width = 100
height = 100
vel = 5
#tornadoe
tornadoe = pygame.image.load('assets/tornadoe.png')
tornadoe1 = pygame.transform.scale2x(tornadoe)
tx = 50
ty = 64
twidth = 100
theight = 100
#earthquake
earthquake = pygame.image.load('assets/earthquake .png')
earthquake1 = pygame.transform.scale2x(earthquake)
ex = 50
ey = 64
ewidth = 100
eheight = 100
#bullets
bullet = pygame.image.load('assets/bullet.png')
Bx = 40
by = 64
bwidth = 100
bheight = 100
#end of variables
#functions
#if collide with another sprite
hits = pygame.sprite.spritecollide(player, tornadoe, False)
if hits:
running = False
#main loop
while running:
for event in pygame.event.get():
if pygame.event == pygame.QUIT:
pygame.quit()
sys.exit()
#playermovementkeys
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x <500 - width - vel:
x += vel
if keys[pygame.K_LEFT] and x > vel:
x -= vel
if keys[pygame.K_DOWN] and y <500 - width -vel:
y += vel
if keys[pygame.K_UP] and y > vel:
y -= vel
win.fill((199, 199, 190))
win.blit(player, (x,y))
win.blit(tornadoe, (tx,ty))
pygame.display.update()
pygame.time.delay(60)
clock.tick(100)
@void spade
!code
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```python
print('Hello world!')
```
Note:
โข These are backticks, not quotes. Backticks can usually be found on the tilde key.
โข You can also use py as the language instead of python
โข The language must be on the first line next to the backticks with no space between them
This will result in the following:
print('Hello world!')
lol
so any fix
@dawn quiver addon starting and end of the text
well i wonder who is asking for help
@dawn quiver shut up
player needs to be a sprite object
why did you forgot?
how
and you can edit messages btw
cares
randomly ping ppl lmaoo
first learn how to spell kid@dawn quiver
ok
ok
and if you havent learn classes then Good Luck
def run_game():
pygame.init()
pygame.display.set_mode((800, 600))
pygame.display.set_caption("tattie")
run = True
while run:
for event in pygame.event.get ():
run_game()
pygame.display.flip ()
if pygame.event.type == pygame.QUIT:
run = False```
its not opening the window
its runs successfully but the game window is not opened.
@void spade
@proven vault you are running run_game() in run_game() function
probably the nesting of function is causign issue
also there is a weird space here flip ()
and you need to add pygame.time.Clock().tick(60) 60 being the framerate
put it in your while run loop
@dawn quiver We also have code paste service for longer snippets like that : https://paste.pythondiscord.com/
lol he is probably too piss to get any help
i fixed it
you need to declare screen before you can use it
def run_game():
pygame.init ()
pygame.display.set_mode ((800, 600))
screen = pygame.display.set_caption ("tattie")
colour = (0, 250, 0)
run = True
while run:
for event in pygame.event.get():
pygame.time.Clock().tick(60)
pygame.display.flip()
if event.type == pygame.QUIT:
run = False
run_game()``` but im getting another error ```screen.fill(colour)
AttributeError: 'NoneType' object has no attribute 'fill'```
@placid oxide
is there any way to keep a randomizer running in the bg?
like what I have rn is owo = True while owo: clock.tick(1000) r1 = random.randint(1,4) update(r1)
but i think im doing this update thing wrong
display.update is for screens while this update is for dictionaries i think
dino run game
just making a random mob spawning machine rn
@ionic depot any idea?
Not really
yeet
now im having class manipulation errors
cuz i wanted to be more organized and look where this got me
it destroyed my character animation function
Python is nice to game dev?
no
@dawn quiver kind of
no
@cinder nacelle why?
@dawn quiver kind of
@ionic depot its possible create 3d game?
@dawn quiver with blender, yes
How would you make a pygame white background?
Also I just started learning Python 1 month ago..
hi
How would you make a pygame white background?
Also I just started learning Python 1 month ago..
@quartz elbowscreen.fill((255,255,255))
Lol
Anyone familiar with graphics.py in python?
what does this error mean
File "main.py", line 17, in <module>
mixer.music.load("background.wav")
pygame.error: mixer not initialized
exit status 1??
there's the github link I pulled the files from
You're missing a call to initialize the library.
File "main.py", line 6, in <module>
pygame.mixer.init()
pygame.error: No available audio device
all of this just to see how a game works
oh playing audio doesn't work
on repl.it
i got it to work
is the framerate on pygame always this terrible
or is that just repl.it
is there any module for 3d games?
@dawn quiver https://www.panda3d.org/
Probably
@ionic depot I'm going ahead with my ninja star throwing game
I have my files set up and now i'm getting my background stuff set up too
pygame.display.set_caption("Space Invader")
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)
can anyone tell me what that's supposed to do
I read the doc and I'm still confusion
And the result of your code? @gilded grove
it's not my code I got it from github
I'm going piece by piece and trying to reconstruct it into the ninja star throwing game
if that makes any sense
other than making the screen size and setting the background nothing
Continue with the players movement
got it
If Iโm making a button class should I put it in another file for ease of use?
Do you have any good ideas on like a level based game to create?
i am so uncreative xD
Is a colour changing background possible with pygame?
I made a strobe effect but it makes the window unresponsive.
Any ideas?
@wind smelt make among us but pygame
@gilded grove lmao
i'm struggling but it's ok
@gilded grove with what
making the ninja star throwing game
what does pygame.keydown mean
i looked it up on the doc
File "main.py", line 38, in <module>
screen.blit(background(0,0))
TypeError: 'pygame.Surface' object is not callable
import math
import random
import pygame
#Intialize pygame
pygame.init()
#screen size
screen = pygame.display.set_mode((800, 600))
#background
background = pygame.image.load("Background.png")
#player ninja
playerImg = pygame.image.load("player.png")
playerX = 370
playerY = 480
playerX_change = 0
playerY_change = 0
#enemy ninja
enemyImg = []
enemyX = []
enemyY = []
enemyX_change = []
enemyY_change = []
num_of_enemies = 6
#game loop
running = True
while running:
#RGB
screen.fill((0,0,0))
#background image
screen.blit(background(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
playerX_change == -5
if event.key == pygame.K_RIGHT:
playerX_change = 5
what does that error mean
i just want to have my background set up
i don't know what's wrong with it
do you guys know whatโs wrong with it?
There's an error on line 38
What arguments are you passing to the function?
idek i just got this from a youtube tutorial and tried to make it work on code for another game
blit()
draw one image onto another
blit(source, dest, area=None, special_flags=0) -> Rect
that's what it says in the doc
make sure you're not missing a comma
This line, 38:
screen.blit(background(0,0))
i added an extra comma after the second zero
How many arguments are you passing to blit()?
2
Are you sure?
is it 3
No, only one
not, pygame specific
python
you're just missing a comma
oh is it after background
yes
sometimes you just have to double check you didn't have a typo
or you can try rewriting it to make sure it's correct
can you explain what .blit does
in simple terms it just means to draw it on the screen
oh ok
Hey may someone help me Iโm trying to make a game called guess the blocks where thereโs three blocks and there are the colors red, blue, yellow, orange, purple, and green. If the user guess block 1 correct then they move on two block 2, if they guess block 2 correct they move on to block 3, if they guess block 3 correct the game will end and tell them the number of tries they had. So itโll also count the correct and incorrect tries. I just donโt know how to get started.
I have the text and stuff set up
I want the user to be able to enter answers in the guess here box and they can click text
Check*
Currently if I click check itโll close the program
hey guys is pygames on 3.8.5?
hey im pretty new to python i want to develop games so im getting a head start for when im ready what will i need?
hey i'm here asking questions it's not dead yet
it's more spicy in the general section
@pale fiber yes
@dawn quiver 1. design, 2. game theory, 3. coding (donโt have to be python)
for general game dev ^
@dawn quiver not sure what you mean but i have the day the screenshot are unreadable
@void spade how do i install it then? plz teach me
hey so i wanted to ask how to go about coding some game stuff in python
idk if i missed the party
but ill type here anyway
:0
@dawn quiver not sure what you mean but i have the day the screenshot are unreadable
@void spade got it
has anyone used Python to create png images before?
I want to create a program that automates the creation of text images
Basically I need to select font, placement, resolution of image, and set background as transparent with python and output .png images
You could use the pillow (PIL) package for that
pyglet??? asteroids
hey guys do you have any nice tutorials for making a map with pygame?
Hello. If anyone would like to contribute to a open-source game project for an organization and be it's Lead Developer, please drop me a message.
You can either make from scratch or use an existing open-source project, no worries about that.
idk @spare cloak if i'd be the lead i'm still very new to game dev
what language would you be using
@gilded grove You're at freedom to choose that. Basically I'm the Founder of the crypto currency Xolentum, and the Devs will be working on the core itself which needs lots of fixes and stabilization.
So we're looking for a separate set of developers to work on a game that will use our crypto currency.
Integrating the payment system won't be very difficult, you just need to setup a good game with a payment system, into which we will integrate Xolentum payments.
You can use any language you want to make it from scratch or use an existing project from GitHub, we don't have any issues with that. ๐
it would look good on my resume but I think I want to stick with my shuriken throwing game
it's more basic and a good introduction to pygame
It's your choice, the one who joins in first will be the lead Developer and maintainer of the game, so a good opportunity just waiting to be filled. ๐
yeah plus i have school so that's a F
Same here.
Damn
How old are you unless you mind sharing that?
19
I'm 17. ๐
wow cryptocurrency founder at 17
:))
sounds great
Yeah
your resume must be stacked
The best of them
Right?
Yeah
Nice
well done
In case anyone wants to join the project, with helping with the game or anything else, just drop me a DM, I'll reply as soon as possible. ๐
i'm willing to give credit to people on github for the ninja star throwing game
if you want that on your resume idk
Well, I'm mostly juggling between school and my existing projects, that's the primary reason of outsourcing the game because I don't have time for it, but a much needed entity for the project's success.
Thanks ๐
i'm new to pygame so i'm trying to create a basic one haha
@gilded grove
um
i don't know github so well tbh
i tried watching some tutorials
do you create a repository every single time you have a new project?
Idk actually:))
do you create a repository every single time you have a new project?
@gilded grove Yep
And if it's just a code snippet that you'd like to share with the world you use GitHub Gists
me a clown bc i did this thing where i coded a spongebob mocking meme function where it turns stuff like bug into bUg
it was just one function and i shared it as a repository
LMAO
@gilded grove lmfao
oh ok good you can delete the repository happy
@gilded grove you want to create the game as 2d or 3d
2d
third
so the spaceship/ninja would now be on the left side of the screen and the aliens/ninjas on the right
yeah so far i'm trying to get it to have a background but that's not working
@gilded grove I checked your repo. Probably you're new to GitHub so .. anyway, you don't upload zip archives to GitHub.
Check an example repo - https://github.com/sohamb03/bench-sh
No issues take your first step at learning Git
That's how the files should be, and to do that, you need to either upload each file individually or use the CLI tool git to push the files all at once.
๐
@gilded grove how many lines of code does your game has so far?
around 45
45 incorrect lines of code bc i still can't see a background
what's the difference between .keyup and .keydown
both control what you hit on the arrow keys
Key down is when you press the button
And key up ...
Do you understand?
It's the opposite
If you need help with the game
Or with the main parts
Tell me
should i just DM you instead of blowing up this section
As you wish
@gilded grove btw , I'm a beginner too
But I learned a lot of stuffs from what I've made so far
And still learning
Thatโs good
Iโve been trying to learn pygame for a while now but I never built up a good understanding of it
But I want stuff on my resume and projects are like the only way
panda3d, working on this racing game - game menu
nice
c# better to devlop games or python ???
whatever you like more tbh
import math
import random
import pygame
#Intialize pygame
pygame.init()
#screen size
screen = pygame.display.set_mode((800, 600))
#background
background = pygame.image.load("Background.png")
#player ninja
playerImg = pygame.image.load("player.png")
playerX = 370
playerY = 480
playerX_change = 0
playerY_change = 0
#enemy ninja
enemyImg = []
enemyX = []
enemyY = []
enemyX_change = []
enemyY_change = []
num_of_enemies = 6
#game loop
running = True
while running:
#RGB
screen.fill((0,0,0))
#background image
screen.blit(background,(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
playerX_change == -5
if event.key == pygame.K_RIGHT:
playerX_change = 5
if event.key == pygame.K_SPACE:
bulletX = playerX
#fire_bullet(bulletX, bulletY)
File "main.py", line 48, in <module>
if event.key == pygame.K_SPACE:
AttributeError: 'Event' object has no attribute 'key'
i fixed it but now whenever I run it I don't see a background at all
@ionic depot any ideas
they're all png files i swear
Youโre using == instead of = in playerX_change == -5
Thanks @merry echo
that didn't fix anything tho while it was definitely an error
Oh the line where the error happens is indented wrong, should be aligned with the other two if statements. I didn't see it cause I was in mobile lol
@gilded grove
and you also need pygame.time.Clock().tick(60)
File "main.py", line 9, in <module>
pygame.clock.Clock().tick(60)
AttributeError: module 'pygame' has no attribute 'clock'
OMG GUYS
IT WORKS I CAN SEE A BACKGROUND
so under the while running
yep
Nice
hello, may i get an opinion ... is it better to write a card game in pygame or tkinter?
can anyone teach me how to use class
class is a blueprint, collection of fields and methods
from it you instantiate object
class Car ...
car = Car()
how can i make an sprite collide
hits = pygame.sprite.spritecollide(player, tornadoe, False)
if hits:
running = False
when i run it
it says no rect
how can i make an sprite have an rect
you must add to it bounding rect
didn't use pygame
ok
hmm draw rect
Draws a rectangle on the given surface.
so you have rect on the sprite
and then spritecollide
hmm you don't need to draw rect
just get the rect from image
self.rect = load_image('head.jpg', -1)
in this way if you use class way
if you extends your class with Sprite
for example
class Head(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('head.jpg', -1)```
i dont use class
or self.rect = self.image.get_rect()
how can i do it without class
ok how?
ok this is module
sprite = pygame.sprite.Sprite()
sprite.image = # here image
sprite.rect = sprite.image.get_rect()
ok @celest iron
should work
import pygame, sys
pygame.init()
#screen
win = pygame.display.set_mode((500,500))
pygame.display.set_caption('BoxBoxTriangle')
clock = pygame.time.Clock()
running = True
#variables
#player
player = pygame.image.load('assets/player.png')
player = pygame.transform.scale2x(player)
x = 150
y = 150
width = 100
height = 100
vel = 5
#tornadoe
tornadoe = pygame.image.load('assets/tornadoe.png')
tornadoe1 = pygame.transform.scale2x(tornadoe)
tx = 50
ty = 64
twidth = 100
theight = 100
#earthquake
earthquake = pygame.image.load('assets/earthquake .png')
earthquake1 = pygame.transform.scale2x(earthquake)
ex = 50
ey = 64
ewidth = 100
eheight = 100
#bullets
#end of variables
down = False
up = False
#functions
#if collide with another sprite
#main loop
while running:
for event in pygame.event.get():
if pygame.event == pygame.QUIT:
pygame.quit()
sys.exit()
#playermovementkeys
keys = pygame.key.get_pressed()
if keys[pygame.K_DOWN]:
down = True
up = False
if keys[pygame.K_UP]:
up = True
down = False
if down == True:
y += vel
if up == True and y <500 - width - vel:
y -= vel
win.fill((199, 199, 190))
win.blit(player, (x,y))
win.blit(tornadoe, (tx,ty))
pygame.display.update()
pygame.time.delay(60)
clock.tick(100)
this is my code
so what i have to do is
ok so image should be from ?
sprite = pygame.sprite.sprite()
sprite.image = 'assets/player.png'
sprite.rect = sprite.image.get_rect()
@celest iron
S?
sprite = pygame.sprite.sprite()
the 2nd way:
sprite = pygame.sprite.Sprite()
the 2nd wa
