#game-development
1 messages · Page 56 of 1
You would have to ask the question to potentially get any response
lol
Maybe also help channels would be better if you are a beginner
Make a well formulated question with a code snippet
No one is going to respond to someone just asking to get help because they don't know if they can answer your questions.
The help snippet above is helpful to read. Read though it to get the most out of this server. Especially if you need help 🙂
Someone made online 2d game In Python?
Kind of. Depends what you mean by "online".
yes?
So, along that same idea, how would you be able to take input from a computer that is, for example, 2 hours away? Would a server have to be used, or is there something with Python that could do this on its own?
Probably easier with a server unless you want to do a deep dive into the p2p world
You could of course configure your router to forward some port to a computer in your network, but you never know when your IP address will change, so that will also require you to update a dns entry if it changes.
while True:
#if start == True:
y = target.ycor()
target.sety(y - 2)
without the # this dosnt work, how to resolve?
Do you need to indent the last three lines? The if has to be indented a tap-stop. Then lines below it two stops.
its ment so the target only moves when start is activated, and the indent inst the problem xd its just how i wrote it in disc
without the # when start is true, it just crashes
with no errors. ping me pls if u know
@rose cloud , my guess would be that the function has an error in it, or something is possibly misspelled. The syntax of the if statement looks right, so that would be the next place to look.
Hey @rose cloud!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
https://paste.pythondiscord.com/cidezitami.py
try it line 150
, when removing the hashtags, press escape and see it crashes/freezes
is kivy underrated?
probably
There are lot of tutorials out there if you search
yeah most of the docs didnt work for me
maybe its because i was looking up textures
not sprites
forgot sprites was the name of a object with a texture
I like the water physics, really cool! How are you doing those? heightmaps or physics engine?
I just have a list of heights for the surface of water. Then I make those levels bounce up and down while also having points pulling nearby points closer.
how do i get images loaded and used by sprites? ive copied this pygame.sprite inherited class, but it takes in a color, not a image/texture. ```py
class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
super().__init__()
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()```
instead of setting self.image to a Surface and filling it with color, use pygame.image.load("/path/to/image_file.png") instead
Or for better structure in your code, load the images you are using onto variables and use those instead of calling pygame.image.load() everytime
ah
ill try that thankyou
@merry echo have i read your message wrong? i have py self.image(image) with image being a pygame.image.load
ah i figured it out
thankyou
Unity or Unreal ?
pygame
there is no question word, so i cant answer
what, when, why, who, etc
you arent asking a question
Invalid answer
What is this a game show
^
S h o u l d, I, l e a r n, u n I t y, o r, u n r e a l ?
depends on what your interested in what games you want to make
2d
There's so many variables when picking a game engine (preferred language, engine strengths and weakness, what platform you're making the game, etc.), that you're better off telling us what your use case is
What is your favorite ?
who are you asking, him or me
Both
also, salami, i have class Invader in another python file im importing, but for some reason its unrecognized
i find unreal too large to use, its more for big companies and big games to me
i prefer unity because i usually work on my own or in small teams
Should I learn c# if I want to learn unity ?
Unreal is in C++ and Unity in C#/JS
Unity supports JS
oh, didnt know that
Though performance wise, C# might be a better choice
salami, how do i call a constructor for a class in python?
ive forgotten, im trying to do this and im gettin errors for it invaders.add(Invader(invaderTexture, 1000, 1000))
Ok... and should I learn c++ if I want to learn unreal ?
yes
Ok. Should I learn c# to learn unity or do unreal with the c++ that I already know ?
What languages do you know?
up to you
C++, python
You could look at other game frameworks that's in c++ or python
Ok. Thx
got this in 1 file
import pygame
class Invader(pygame.sprite.Sprite):
def __init__(self, image, width, height):
super().__init__()
self.image = image
self.rect = self.image.get_rect()```
and import invader which is the name of the file this is in
creating an invader yields an unknown error
Invader isnt recognized
import pygame
import invader
pygame.init()
width = 800
height = 600
WHITE = (255, 255, 255)
RED = (255, 0, 0)
screen = pygame.display.set_mode((width, height))
invaderTexture = pygame.image.load("invader.png")
invaders = pygame.sprite.Group()
invaders.add(Invader(invaderTexture, 1000, 1000))
running = True
while running:
for event in pygame.event.get():
if event == pygame.QUIT:
running = false
screen.fill((WHITE))
sprites.draw(screen)
pygame.display.update()```
you are only importing the file with import invader, so when you want to use your Invader class, you would do invader.Invader() instead
or if you don't want to do that, do from invader import Invader
that's assuming they're both on the same folder
yeah ofc
id have to sudo into a directory if i had it in another folder
btw how can i assign different class values to other values without assigning the entire class
pseudocode:
self.rect.width *= widthMultiplier
.width isnt a real thing
is there a way to do this?
i cant just append .width because i cant find a way to access each variable at a tiem
unreal doesnt support 2d
@elder forum and poor Paper2D?
Paper 2D is a sprite-based system for creating 2D and 2D/3D hybrid games entirely within Unreal Engine 4.
Nope
my bad, didnt mean to mislead him i just havent used unreal engine much for a while
didnt know they had a 2D thing
That’s okay 🙂
Even if they didn't, workarounds exist to render your 3D scene into 2D
I don't quite get what are you doing with .width
You want to change a class' .width variable?
The Rect is in your invader class?
Since its in a Group class, you would have to get your invader class there first, like so invaders[index]
then accessing the width variable would be invaders[index].rect.width
how so
hm
hold on
for some reason my app is crashing
ah wait
i might have figured it out
hold on
class Invader(pygame.sprite.Sprite):
def __init__(self, image, widthMultiplier, heightMultiplier):
super().__init__()
self.image = image
self.rect = self.image.get_rect()
print(self.rect.width)
self.rect.width *= 2
print(self.rect.width)```
so ive confirmed that the rects width does get increased when i multiply it
but im not sure why the width doesnt seem to affect how it shows up on screen
it takes the width of the image, multiplys it by 2, but in the render, it still shows the images real width
do i have to multiply the image size or something?
so, in pygame, does the image size have to be the size you want it to be on screen, as opposed to being able to scale the image up and down in pygame?
or can i scale the image with pygame?
@elder forum I believe you need to you the scale functions(I don’t know the syntax completely, but I believe it is Pygame.transform.scale().
Probably will just have to look it up.
hmok
class Invader(pygame.sprite.Sprite):
```py
def init(self, image, widthMultiplier, heightMultiplier):
super().init()
self.image = image
self.image = pygame.Surface([widthMultiplier, heightMultiplier])
self.rect = self.image.get_rect()
pygame.transform.scale(self.rect, (200, 200))```
still trying to figure out how to scale a sprite.
transform.scale requires a surface, but when i add self.image = pygame.Surface([widthMultiplier, heightMultiplier]) to turn it into a surface, it removes the sprites image.
class Invader(pygame.sprite.Sprite):
def __init__(self, image, widthMultiplier, heightMultiplier):
super().__init__()
self.image = image
pygame.transform.scale(self.image, (200, 200))
self.rect = self.image.get_rect()```
new development on the issue
my code looks like this, transform.scale does not make a difference.
Have you tried putting this outside of a class, and then hard coding it in? (Then transferring to a class, or just removing the scaling and putting that into the main loop) It’s possible it needs a display update, or it’s just not taking the scaling inside of the class.
pygame.transform.scale returns the new, scaled image
you're not assigning it anywhere so it gets thrown away
I'd also suggest keeping track of the original image if you need it, to make sure you don't repeatedly transform the same image too much, which will make artifacts
hey can anyone here help me with something
im not sure why this keeps crashing https://hastebin.com/afuperofad.py
@dense marsh A lot easier to help if you share more information. Do you have a stack trace for example?
stack trace?
im pretty sure it has something to do with the while loop above running = True
Hey @delicate smelt!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
Hey @delicate smelt!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
So I'm working on a Space Invaders type game, and I'm trying to make the ship stop when it hits the wall, but it keeps on going. Heres the first part of the code(had to split up because it was too long)
import sys
import pygame
class Settings:
def __init__(self):
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)
self.ship_speed = 1.5
class Ship:
def __init__(self, ai_settings, screen):
self.ai_settings = ai_settings
self.screen = screen
self.image = pygame.image.load('C:\\Users\\mrgam\\Desktop\\ship.bmp')
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
self.rect.centerx = self.screen_rect.centerx
self.rect.bottom = self.screen_rect.bottom
self.moving_left = False
self.moving_right = False
self.center = float(self.rect.centerx)
self.ship_speed = 1.5
def boundaries(self):
self.rect.centerx = self.center
if self.moving_right and self.rect.right < self.screen_rect.right:
self.center += self.ai_settings.ship_speed
if self.moving_left and self.rect.left < self.screen_rect.left:
self.center -= self.ai_settings.ship_speed
def update(self):
if self.moving_right:
self.rect.centerx += 1
if self.moving_left == True:
self.rect.centerx -= 1
def blitme(self):
self.screen.blit(self.image, self.rect)
def ai_settings():
pass
def run_game():
pygame.init()
screen_settings = Settings()
screen = pygame.display.set_mode((screen_settings.screen_width, screen_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
bg_color = (230, 230, 230)
ship = Ship(ai_settings, screen)```
And the second part:
while True:
def check_events():
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
ship.moving_right = True
if event.key == pygame.K_LEFT:
ship.moving_left = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
ship.moving_right = False
if event.key == pygame.K_LEFT:
ship.moving_left = False
if event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
ship.moving_right = False
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
ship.moving_left = False
ship.update()
screen.fill(bg_color)
ship.blitme()
pygame.display.flip()
check_events()
boundaries()
run_game()```
Plz help!
Just set the ship's left if it hits the screen's left to the screen's left, and vice versa with the right
My pygame window crashes immediately can someone send me a fixed version of my code so I can study the changes
it wont let me post it
im very sorry
ill create a github
!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.
If it's just one file you can paste it here, if not, then yea make a github
No
thank you
Is there any errors printed in the console?
Not in sublime
I haven't run it in anything else
do you want to dm because other people might have an issue and I don't want it to get lost
just looking at your code, off the top your identation looks incorrect. There's a part of ball_animation function that is not idented.
that's ok, everyone starts at nothing
thank you
but yeah, in python identation is important. If it's not idented properly, like in your code, that piece of code will be executed first
and ball.right is not defined on startup, so most likely this is where it crashes
there's a bit of code starting on line 16 that is not idented to the function
so from pov of python interpreter, your function ends on line 15
i see
then because that part of code has 0 identation it's executed before anything else.
Personally I suggest making a main method and then calling it through main
So what should include in the main?
it likely uncovers another bug
What's the error
in the main for now simply put everything you want to run first, like the stuff outside of your functions
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.
I ran your code with fixed indentation, and a blank window pops up with black background
Yeah your indentation is wrong
The standard is 4 spaces each indent, sublime should handle that if your press tab
NameError: name 'quiet' is not defined
i dont have quiet in my code
yeah you're right. It might be caused by previous errors. Try to fix identation first
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.
there's still something wrong. Look at your first function. The lines should all start at the same column
it looks like it's possibly double tabbed? Or you somehow used tabs and spaces interchangably
the import pygame, sys, random?
no, def ball_animation()
your lines 4-15 appear to be double tabbed, maybe
then 16-21 look ok
should look like this
https://paste.pythondiscord.com/qolocigawi.py
Look at the spacing
why is there a 2 line space between import and def?
I think pycharm complains otherwise
o
Don't look at that look at the indentation
but that's just a warning, it doesn't matter. Do look at the identation because python cares about that. It doesn't care about blank lines
ok
I KNOW WHAT I DID WRONG
i thought after: there was an indention
but its HALF an indention
i think
i hope
and salami i tried your code but the game window looks like this
yeah missed some indentation
sorry haven't used pygame
should look like this right
yes so far
but when its done it should count down and the numbers on the side shouldnt rocket up
1 more question
actually 2
- How do you learn the indentions
- How do you install the turtle module
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.
that looks like a python compatibility errors
and second, are you sure you're installing the right turtle? That package is a http proxy
Turtle is an HTTP proxy whose purpose is to throttle connections to
specific hostnames to avoid breaking terms of usage of those API
providers (like del.icio.us, technorati and so on).
i ran pip install turtle
I think turtle requires tkinter
C:\Users\Blank>pip install tkinter
ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none)
ERROR: No matching distribution found for tkinter
what do you get when you simply try to import turtle?
it looks like it's a part of a standard lib
nvm thats a default python lib
wdym simply import?
thats what i get when i run pip install turtle
C:\Users\BLANK>pip install turtle
Collecting turtle
Using cached turtle-0.0.2.tar.gz (11 kB)
ERROR: Command errored out with exit status 1:
command: 'c:\users\BLANK\appdata\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\BLANK\AppData\Local\Temp\pip-install-xb4lz8e5\turtle\setup.py'"'"'; file='"'"'C:\Users\BLANK\AppData\Local\Temp\pip-install-xb4lz8e5\turtle\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\BLANK\AppData\Local\Temp\pip-pip-egg-info-4yj1meml'
cwd: C:\Users\BLANK\AppData\Local\Temp\pip-install-xb4lz8e5\turtle
Complete output (6 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\BLANK\AppData\Local\Temp\pip-install-xb4lz8e5\turtle\setup.py", line 40
except ValueError, ve:
^
SyntaxError: invalid syntax
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
in your file, instead of having
import pygame, sys, random
add
import pygame, sys, random, turtle
no this isnt for my game
just wanted to know how to because i lot of the tutorials i tried to follow used it instead of pygame
that's ok, try it to see if it finds it. The turtle you want is built into python. The turtle you're trying to install is something else entirely
if it doesn't find it, you'll get an error
if it doesn't complain, that means it imported it properly
it dosent complain
and my other question was how do i learn the correct indentions
sorry if im being slightly (really) annoying
There's articles on the web about that, they'd explain it better than I do
ok
last question i promise
where should i start if i want to create games without tutoirals
tutorials and any help
honestly, once you get the basics like flow control down, come up with an idea and google for solutions like your life depends on it
lol
thanks for your help!
bye
any of you know what twine is?
What's the best way to do this with functions?
I'm making a gui game that uses logic in each "scene", and a menu pops up which controls going to the next one
but how would i do that?
i'm not gonna manually define a hundred functions, and redefine them to be part of a dictionary
um
well you don't
You're not gonna have a dictionary with a hundred functions in the first place
also try out this code
ls = []
@ls.append
def square(x):
return x**2
print(ls)
okay a decorator
Alright my guess is that you're trying to recreate something like detroit become human where there are multiple paths
how do i get the dimensions of a surface object?
thankyou @potent ice
I think someone recommended this one in the past : http://kidscancode.org/lessons/
KidsCanCode - we teach kids to code
Basic drawing and sprites in pygame
ah ok
Can someone help me fix this issue
Where if i build my code in sublime
it dosent automatically open my pygame window
whereas in the tutorial i follow
it does
@dawn quiver I’ve noticed this issue with Pygame, if I understand you correctly. You need to open your IDLE console, and in the files button open the python file you want. Then run it. For this reason, I’ve stopped using sublime and just started using the python file itself to code.
So what text editor are you using now? Couldn't you instead run your file with your terminal?
is there any library of python for minecraft pocket edition server quieries?
@merry echo I’m using whatever text editor opens up whenever you open a new file with the IDLE. It’s just what I’ve found to work for me.
Can I display python code on html or pho with our using flask ?
Hi guys whats the best framework to use for a 2d rpg?
Lots of options. Here's an example using Arcade.
ok
Is pygame easy to learn?
That's one of the reasons it is popular. In my biased opinion it is a bit aged though, as its been around for a while.
Still a good library,.
Speaking of that, are there any good tutorials for a beginner for python? I know the very basics and syntax of the language, but Id like to make a simple game for some practice
Thanks, Ill check it out
Hello, can someone help me?
I'm trying to insert some input text in the pygame screen, only that the text overlaps and stretches in two sides instead of just to the right, do you have any advice on how to fix it?
That FPS tho 100+ 😮
@flat sail What do you mean by stretching in two sides? Does the text go in both directions when you add characters? Or is the text actually stretched? If you could post the code snippet on how you're rendering it, it would help to diagnose the problem
it almost doubles if I run it in Pygame 2 instead of 1.9.x
That's awesome work @foggy python
thanks
#game-development message wow this looks cool @foggy python
did you use pygame to build that
Pygame2 is shaping up nicely. going to try dev8 version soon. I think that even exposes all sdl2 window features
Hi
Do u have any advices or help for a guy that wants to make a game or any websites that help to learn python game development
@muted violet yep
Mostly the documentation.
@merry echo when I write some text, it goes on both sides
@merry echo if u want i can send u in a private message my code
You blit an image/ the background in the middle of the screen (0,0) at the start of the loop
kinda like filling the background, but bliting
Thnx man
@flat sail Then your rendering it centered, or it is by default. Try adding the width of the text halved when rendering your text
Question for all the music people; I am wanting to create my own audio files for pygame, and have an electric keyboard that I can connect to my computer. The problem is that I honestly don't know what programs to use, or how to set it up to take the keyboard input(I'm using a DGX-230 Yamaha). I tried using "MidiEditor" and converting the files to Wav, but that was... buggy to say the least. I would like to know what people use, and if it is possible to connect the keyboard to them. Thanks!
You probably need to run your audio out from the keyboard to the audio/mic in from your computer. Then use a program like audacity to record.
I’ve downloaded Audacity, but I can’t find the keyboard for input. The keyboard connects with a usb to the computer, and some weird looking box shape to the keyboard. I’m probably missing a setting to have the keyboard recognized as an input device.
So I made this in an effort to reverse engineer Perlin Noise:
It randomly shuffles through similar looking systems.
The question I have is that this takes for EVER to actually make. It's a 2D array of X-pixels by Y-pixels.
Is there any way to maybe make this more effecient?
Currently the process is:
go through a row, make random colors somewhat similar to the one next to and above the pixel it's at now.
Get a ratio scale of these values
Draw the ratio * 255 as the RGB values
@foggy python that's lit
@lunar tangle What are you using to edit the individual pixels? If you're doing it by setting each individual pixel (like surface.set_at), I could see how that would be slow. Try using PixelArray if you haven't already. That might give a speed improvement
https://www.pygame.org/docs/ref/pixelarray.html
That seems like this kind of thing that would be perfect for an OpenGL shader if you wanted super-fast performance.
Or I wonder if numpy would have options that would be good.
I used surface.set_at and that led to issues with anything over 600x600.
Yeah setting pixels individually ought to be slow, try PixelArray and see if that improves it
How would this work when I want to change the resolution?
I had it with set_at, then I changed it to drawing rectangles the size of the resolution
You mean like responsive? It changes when you resize it?
If so, either you set the size of what you're drawing to the new window and redraw it, or just draw only what has not been drawn yet if it is resized larger than initial, and crop it if its resized smaller.
PixelArray just wraps Surface on top of it, you could access it with .surface. So, there shouldn't much change need if you're going to switch to PixelArray.
No like, If I want the squares to be 4px by 4px
Currently I can do high res or a lower res with less actual blocks
same size
Oh ok then, you could just resize the Surface with transform.scale which should return another Surface that you could use
I'd advise you poke around the pygame doc site to help you get around pygame better
@merry echo could you remind me the sintax to manage the width when rendering my text?
Anybody can help me with sprites and animations 😅
!ask
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving.
• Be patient while we're helping you.
You can find a much more detailed explanation on our website.
Tell us your problem directly
Which algorithm can I use to find, which cells are occupancied by polygon object (just rotated rect)? Now I find topLeft and bottomRight cell of bounding rect of this polygon and select all cells between this two cells, but some of the cells shouldn't be selected in this case (red cells on image)
So do you check for each cell if there is a collision?
I haven't worked on the code in a while, but I think yes.
Figure out the bounds, then check each square for an intersection.
@daring shore you could also test if each border line is inside a square, this should be pretty trivial
@fervent rose how? I think its not that trivial
Something like the Liang–Barsky algorithm could work
I mean, that's trivial wth the power of google in your hands 😄
Cohen-Sutherland might work too
Both are implemented here https://github.com/marcusva/py-sdl2/blob/master/sdl2/ext/algorithms.py
thanks
@visual axle why are you asking that here?
idk bro
it says discussing game dev and pygame right? so it should be fine
im just really stuck rn and im kinda desperate to finish this
I've been working on a tutorial for using full 2D physics in a platformer with Arcade 2.4. If anyone wants to look at it, and maybe give feedback, I'd love to hear it. I'm want to get the right mix of power, and ease-of-use.
Any help for sprites and animations?
DaFluffyPotato has a great video tutorial about animations
Project Download:
http://dafluffypotato.com/static/platformer_project_2.zip
Discord: https://discord.gg/9Qt2GxF
Twitter: https://twitter.com/DaFluffyPotato
This video and the code produced in it are released under: CC0 1.0 Universal (CC0 1.0). This puts the video and code p...
He also discusses sprites in the video
@visual axle that requires context from my tutorial though. Have tried comparing it against my code to look for differences?
Man don't you just love reading the source code from different pygame projects
everyone should check out Ursina Engine, its a neat project. Beginner friendly too.
looks awesome @foggy python! https://www.reddit.com/r/Python/comments/ggt5ld/im_developing_a_game_with_python_and_pygame/
@foggy python yeah I tried but I couldn’t find anything because I added a lot more code, so I didn’t know what was affecting it
Guys how I can make an image as an object that a player can walk on and how I can create a map?
@visual axle slowly get rid of it till you find out what broke it.
i have an idea on what's causing it but i have no clue how to fix it @foggy python
try stuff until you figure it out
That’s generally how programming goes
People generally won’t help you with questions where you’re asking people to debug your logic.
@visual axle check you map/tile generator.
@rain lava create a Rect object as the player and blit a sprite over the player's rectangle. You can use colliderect to see if the player is colliding with the tiles' rects. Here is a video on how to make the tiles and collisions work: https://www.youtube.com/watch?v=HCWI2f7tQnY&t=477s (or you could use the Pygame.sprite.Sprite function)
The project can be downloaded here: https://dafluffypotato.github.io/dat/Platformer.zip
My Twitter: https://twitter.com/DaFluffyPotato
Video released under: Creative Commons BY-SA 2.0 (CC BY-SA 2.0)
@rain lava another option is using the Pygame.sprite.Sprite function, and using sprite groups to check for collision between two groups/sprites. “Kids can code” does a tutorial on how this function works.
@foggy pythonHey man cool stuff, btw, what made you choose pygame over other game frameworks (pyglet, arcade, kiwi etc.)?
would this be the proper play to discuss adversarial search trees? Specifically minmax?
Im working on creating a connectfour game and want to add a computer to play against
@merry echo I wouldn’t use arcade because I prefer the “do it yourself stuff”. As for the others, it’s mostly because it’s what I started on.
I'm the same thing too, last game jam, had to make my own platformer physics since I didn't like the one in arcade.
How about perfomance?
how do you add a bullet hit effet (spark or a hole) in a game
What game engine? Pygame, Arcade, Kivy, ?
pygame
Pygame’s performance is good enough for me. If I want more, I can switch to PyOpenGL.
basically what i want it to do is if it touches a wall it makes a spark
like a normal gun would do
or bullet
when the bullet rect collides with the rect you can delete the bullet and add particles. If you want to learn how to add particles, just search it on whatever search engine you use.
Doing game-related stuff is still very much on our minds. It's been amazing to see so many people talking about and working on games in Python.
And there are very nice people active in the python game framework community
It's something we really like and want to support as well
Is it recommended to use OOP with pygame?
Yup, every game should use OOP at some point, or it will be impossible to manage at some point
Just finished my Verlet particle simulation
now onto collision detection 😩
removed the stiffness and I played with the x_gravity which resulted in a cool wind effect 🙃
whoahh that looks cool
if anyone's interested, there's nice tutorial and a cool paper below:
http://datagenetics.com/blog/july22018/index.html
https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf
looks cool
That’s really cool, thanks for those links!
@merry echo really good!!!
Agreed, love it!
(not sure if this is the right channel) so im kinda a beginner in python, I'm coding a pong game and I can't fugure out what my mistake is. Prolly some stupid small mistake but can sum1 skim thru my code and tell me if they can catch what I did wrong? pls dm me if ur willing to help cuz it wont let me send the file here
Unreal Engine 5 have just being revelated!!!
Unreal Engine 5 empowers artists to achieve unprecedented levels of detail and interactivity, and brings these capabilities within practical reach of teams of all sizes through highly productive tools and content libraries.
Join Technical Director of Graphics Brian Karis and...
@dawn quiver You can use pastebin or a similar tool to place code for others to read.
Wooo! Another engine that my pc can't run 😅
What problem are you exactly having?
Oh my god that UE 5 engine looks nice.
@dawn quiver you shouldn't be adding here but multiplying instead *= by -1, which reverses the ball
Same goes with the other three directions
Man, this math is hurting my brain, it's not even hard math, its like high school math, linear algebra 😿
change the += to *=
What are you trying to achieve
@fervent rose I was waiting for him to show the triangles close-up, but he didn't 😢
I bet you can't even see them haha
Well, we will still have LODs for less powerful hardware, and they will still have an uncredible boost
There are some pretty nice annoucement at the end of page too
Now you need to give epic royalties only if you earn more than a million
im trying to make an incremental game like cookie clicker, just can't figure out how to increase the price of a "building" after you buy one by a certain amount
is there a way to increase it over time?
yes, call the code all x seconds
oh thanks
The building price is exponential, as seen in the wiki here
https://cookieclicker.fandom.com/wiki/Building
Price=Base cost×1.15^(M−F)
where M – the number of that type of building currently owned;
F – the number of that type of building you have for free (cursors and grandmas you get from Starter kit and Starter kitchen prestige upgrades.)
If you want you could check out the source code
http://orteil.dashnet.org/cookieclicker/main.js?v=2.002
hey all, whats the best game engine for using python?
(use your personal definition of best, seeing as I don't know)
just looking for fun... i know how to use python, just finished making a discord bot kind of looking for a new project
Arcade and Pygame are good to get started with in 2D (I'm biased to Arcade)
Arcade has a lot of examples you can look through there.
awesome! ty 🙂
Question about python, and coding. Should I be using a computer that isn’t “important”? (All computers are important, being an expensive piece of equipment) Like, is there any concern of running a code and suddenly the computer falls apart and I lose all the information stored on it?
Fortunately you will not achieve it until you will actually code something that will do it. So it's almost impossible
using a version control system, like git, and uploading your code to a remote server, like GitHub, is a good way to get around that
@pliant dust
but i would personally code in a decent computer; makes the experience much better
Anyone know why this code is just showing me a black screen? I get no errors btw
https://pastebin.com/j43jMvfV
You need to update the screen with pugame.display.update()
I think you call it after you finish drawing all of your sprites.
The update should come at the end of the while loop, it’s the last thing you want to happen, and you want it to happen every frame, or atleast whenever something changes.
im trying to make a program in pygame, where if u click you draw a dot and then a second click will draw a dot and connect the two, and so on
i got the mouse input down, but im not sure how to do the whole reading if there was a previous dot
ooh, how would i go about doing that?
perhaps u could add the coordinates of every click to a list, and add a check so that the program knows there was a previous dot if the list is not empty
good idea, ill give it a go
ah yes, it all worked out! thanks!
Whenever I try to pick up a block that has already been thrown, I get an error, con someone help with this?
The error is indexError: pop index out of range
This gets the index of the block that I am going to pick up:
# Checks if player is touching a block and pressing down arrow to remove a block and add a block above the player's head
if collisions["left"] and pick_block or collisions["right"] and pick_block:
for tile in xcollisions:
if pick_block_count == 0:
if not holding_block:
tpb = tile
tile_pops.append(tile_rects.index(tile))
holding_block = True
pick_block_count += 1
else:
xcollisions = 0
# Removes the tile that is picked up
for tile in tile_pops:
tile_rects.pop(tile)
drectp = display_rects.pop(tile)
That above removes the block, but the problem is that I loaded the game map above it redefining the tile_rects variable, making the index of the thrown tile out of the range
I can dm the full code if you need it
What game library are you using?
pygame
@dawn quiver Doesn't pop() take an index? You're passing the tile object instead
remove() might be what you wanted to use
Does anyone know how to make a shape constantly move in one direction without having to hold down button in pygame?
have an x, y velocity variable and add it to the shape's x, y position every frame
instead of checking when a button is pressed
ok thanks
What kind of game are you making?
Becuase I am a beginner its just a game where enemies try to touch you and you have to try and escape
Oh ok
have an x, y velocity variable and add it to the shape's x, y position every frame
@merry echo What would that look like?
I keep trying it but it says this:
SyntaxError: cannot assign to operator
How can I fix this?
You could post the part where the error is so we could diagnose it better
The error message should tell you where that line is
Do I need a separate velocity x and velocity y coordinate?
Yes
that's just for the x axis
if you want your sprite to go up and down you'd want one for the y axis too
ok
@merry echo this line gets the index of the tile I want to pop:
tile_pops.append(tile_rects.index(tile))
I am removing from tile_rects. I have a for loop that removes the block for every item in the tile_pops list
I can send you my code if you need to see it
i wasnt sure what channel to put this in but i am trying to make an auth software that is hwid locked, how would i do it?
Hey just joined. I'm brand new to programming, started learning Godot about 6 weeks ago, and realized I needed to learn a bit more about languages so I started studying python. Based on your experience, is python a good language to learn for a first timer if they are looking to be able to make complex 2d games?
I want to know if since I'm learning python to help me in Godot(GDScript) if there is a significant learning curve for python game dev compared to Godot, and if you could quantify that difference in time, even better.
I should also add that I decided to learn godot to make a simple card game for ios, and that it's possible I may develop for both mobile and desktop on a long term basis, but that's still kind of unclear at this point since it's a bit early to tell if I'm any good at it
Some general programming experience certainly don't hurt. GDScript is very similar to python
Maybe start simple with arcade for now : https://arcade.academy/
There are other lower level libraries as well of course, but they will require a higher time investment.
pygame and pyglet being the more popular ones.
@celest wasp I guess it doesn't really matter were you start. Just get started 😄
I cant seem to run arcade
Any error message?
hey thanks -- I have some books that mentioned pygame and arcade, and that depending on what you want to put in your game you'll choose one over the other. So you're saying for development if I wanted to make use of what I learn right now(since I'm learning it to make sense of the programming part in Godot) once I finish my Godot project I should start with arcade because of simplicity? or because of it being better for 2d?
@dawn quiver Looks like your computer don't support opengl 3.3, so it won't work. It could just be a driver thing also. Find out what GPU you have.
how to find it
@celest wasp What game/graphics library you chose not that important. What you learn will translate to other libraries later. I just thought arcade might be a less brutal start 😄
@dawn quiver No idea on windows. A quick search should solve that
ah right. you need OpenGL 3.3 / DX10 support for arcade
Doesn't it tell version 2.0 required
I had this exact same problem with kivy
i fixed it by changing some environmental variables
the kivy one
It says glCreateProgram is not available so there must be something weird with your drivers
oh
Kivy is using OpenGL 2.1 on desktop
oh
The intel hd 2000 is about 10 years old. You will have support with most integrated gpus that are 7 years old or less.
I know opengl drivers for hd 2000 and 3000 are very bad in windows
MC uses a java library
Yes, but they are using an older version (2.x)
Oh
I could spell its name, but I’d probably get it wrong haha
Lol
I think is LWJGL yay I got it right
Arcade relies heavily on more advanced shaders to push more work to the gpu
Oh
For example.. it's using geometry shaders for drawing shapes
So instead of generating a circles, arc or ellipse in python this is done on the gpu instead. Much faster
But you can use pyglet 1.5 and pygame. Both are also good options.
@potent ice ok so just not as brutal. thanks again!
@celest wasp No problem. Could be a good idea to make something a bit more boring in pure python first before jumping on a game/graphics library
So instead of generating a circles, arc or ellipse in python this is done on the gpu instead. Much faster
We said MC 😉
yeah I have arrived at the point where I understand most of the meaning of the language, I just don't have the problem solving down yet, so I've realized having simple projects to learn that aspect have been critical in moving past having no idea where to start.
Then definitely go arcade for now. Lots of good tutorials
seems like there just isn't a way to learn that aside from just trying to make something and realizing what you dont know lol
It's not a waste of time even if you don't end up using arcade later
Maybe this? https://learn.arcade.academy/index.html
is it useful to learn arcade at the same time with python? because python has some things that don't exist in godot and I thought maybe going all in on game dev in python just to learn how to do it in godot might be confusing, whereas if I just stick to the code aspect in python I can still learn godot habits without getting confused
see the link above
That is exactly what you talk about here
It teaches programming with python and arcade at the same time.
Just be aware that the current arcade 2.3 may be a bit slow when it comes to shapes, but the soon to be released 2.4 has major improvements.
I know gdscript was made very similar to python so that's why I reasoned out learning python since documentation on gdscript and godot is limited.
Yeah you are not the first person with this conclusion 😄
but I just didn't know enough about godot development processes to know if game dev in other engines would teach me something I could use in godot
from what I read everyone says godot can be easier for newcomers, which I find ironic since I've had to go to a more complex language and system in order to learn how to use godot lol
Worst case python can be used for almost anything so it's a very useful skill to have anyway
Even if your work isn’t about programming, python is still a very useful skill to have
yeah ideally I'll just be working on simple apps and then maybe a complex desktop game if I can get the nerve up
in the long run
And if you want to do some game dev, but more from an artist side, python will be very valuable
hows that? I'm curious because that's pretty much my background -- musician, graphic design
Start simple so you don't burn yourself on some gigantic project you'll be wanting to completely rewrite in 3 months anyway
Talking from personal experience there 😄
lol yeah thats why my first project is just a card game. Even just doing a card game I've had to start with smaller projects just to learn how to make the card game.
and it doesn't even have any real game mechanics it's just a storyboard game
If it does run, that’s a really good start
I'd like to think so. So far in godot I've got a script to manage the cards and instance the card nodes, and then now I'm just stuck on the ui design to set up how the cards actually look in the layout, and how to set up menus and other ui stuff. So that's why I started on python stuff, because the ui stuff in godot is a little heavier on understanding the math of what you're doing.
it's made me realize I might have got a little further ahead than my experience merits
I could have kept going, but it's likely I'd have a buggy game in the end
I think you are describing a situation all of us bump into in the learning process here 😄
haha great! at least I'm getting somewhere
The great thing is that what you learn will translate to other software/languages and areas. If you get a bit deeper into it you'll see many doors opening.. even in areas you did not expect.
and you can always ask questions in this community if stuck
yeah I was reading through some books ( i didn't end up getting them though because I'm not interested in the end goal) on python used for machine learning, data science, all that stuff seems pretty popular these days
you can use packages like pyinstaller and auto py to exe
If you could specify what problem you have we could help with that
Do you already know python basics and are looking for a library to make you game in?
so I turned my verlet sim into a web, ended up looking more like a trampoline 😔
hello @fluid lintel
good
Im new on this channel and I havent any knowledge of Python and I would like to learn something
btw @potent ice that link you gave me looks great for tutorials, but I can't find the project files the guy keeps mentioning anywhere on the website
do you know anything about that?
@solar stone i could help
ok
well i just have to find a way to post my game
what's the first thing what I need to know
needs 2 people to play it
ok
but i am currently making one about battling with robot's
good
basicaly it has a lot of tech !!
in wich part is your game @fluid lintel
every part
but I wanna see it
no python is the easiest language i have ever encountered
and is very powerful
hold on i will be back having something urgent to do
I ask that cause Im programmer but I program in Java and Javascript
oh
sure !
just wrap it up good
@solar stone here it is
yeah yet to show you my game
good
here it is
I use netbeans
this is the game
good
Hey @fluid lintel!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
Hi I'm getting this really weird PyGame error
even though I've successfully installed PyGame, it says: builtins.ModuleNotFoundError: No module named 'pygame'
Either you don't have it loaded in your VM, or you might have created a file called pygame.py
What are you running it from?
Command line, pycharm, etc?
Wing101
this is what my terminal says : Python 3.7.6 (default, Jan 8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
Basically I was trying to learn how to use the conda environment but I don't know how to close it so maybe that's the problem?
I forget how Wing manages virtual environments, but I'm guessing you installed pygame in one spot, and it is using a different virtual environment. Or you've got a regular Python install, and an Anaconda one.
they have a built in terminal to run script
You might try doing a pip install pygame from that terminal.
Ah, 'fraid I'm not going to be much help then. Sorry. Maybe someone else will chime in.
thanks I appreciate the help
what programming language should i learn first ?
python
and how long does it take to learn it >
okay what are you interested in when it comes to programming?
Learning is always an on-going process.
Because python is a good beginner language because of how easy the syntax is to pick up
and how the logic works in python
k
But I mean it depends on what you want to do with your coding skills
like if you want to do ML ---> python, if you want to do web dev ---> javascript, html, css
The first programming language you pick up takes some time to master. Once you know one language.. other ones will be easier to pick up.
coool
i had a run of the mill basketball coach teach us python
couldn't understand anything so i decided to stat=rt learning online
Think my path is : BASIC -> Asm -> Pascal -> C/C++ -> Java -> C# -> Python
Similar to mine. Although I spent a lot of time with Forth.
ooh
Programming is fun, hope you have a good time learning it.
so it gives you the basics; I can see
If you like more visual learning that one is a winner
cool
it kind if feels anoying
since i have schol online and some AP exams around the cornner
The other way to do it is just look at the example code:
And play around with it while learning. Then look things up,.
...as you need to.
Like, "how does a 'for' loop work"? Then look up video or on-line text.
Video or reading, one of the two. Whichever you learn best with.
k
hey paul craven that website mentions some project folders and I can't find them anywhere on that site
am I not supposed to use them?
Not really. I use that for consistency when I teach students so it is easy to find their work.
My question is here: https://stackoverflow.com/a/61808809/13357386
the answer that is already there doesn't work
what is the best method to make such a grid with pygame ?
Should I use a image or draw rectangles
I am making a battle ship game
@dawn quiver Could you help me ?
So like I said im making a battle ship game
and I am trying to recreate that grid
( with the letters and numbers around the grid)
with pygame
I can answer your second question, but not the first. you should use rectangles if you want it to look as you depicted it in the picture, but images if you want to add more detail to it.
I can't answer the first because I don't know the best way of doing it
I see
but how do I turn a image ( of a grid ), and make it a actual grid
you know what I mean ?
with cords and stuff
are you going to have mouse clicks?
@dawn quiver yes
I can't help you with that, I haven't really learn how to do that yet
Anyone knows about turtle library in python?
The listen function is not working in MacOS
I am trying to set up Visual Studio Code for python and pygame, however, continue to have an error. I have installed pygame to the VS terminal, it tells me it is satisfied, and then when I try to run a program, it stops at the "import pygame" and states that there is no such module. I have tried looking online, but it seems like no one else has this issue.
Check in lower left corner what python interpreter is selected
That should be the same as the version you used in the terminal
python --version
@rocky monolith Questions like that will almost never result in an answer. You need to be more specific.
hello @fluid lintel
so what's up
Im making a webpage
cool with django or flask or html
@solar stone with django , html or flask
k
does anyone deal with panda3d in python
anyone got any ideas on how i can further optimize my particles?
they're already fast but i want the freedom of using potentially up to 50k when currently it starts lagging at about 15k.
for particle in particles:
angle = int(abs(particle[1][0]%360))-1
oldx = particle[0][0]
particle[0][0] += costable[angle]*particle[1][1]
location = [int(particle[0][0]/tile_size),int(particle[0][1]/tile_size)]
if location[0] < len(tilemap) and location[1] < len(tilemap[0]):
if tilemap[location[0]][location[1]][0] != 0:
if angle >= 0 and angle <= 180:
particle[1][0] += 90
else:
particle[1][0] -= 90
particle[1][1] *= 0.9
particle[0][0] = oldx
oldy = particle[0][1]
particle[0][1] += sintable[angle]*particle[1][1]
location = [int(particle[0][0]/tile_size),int(particle[0][1]/tile_size)]
if location[0] < len(tilemap) and location[1] < len(tilemap[0]):
if tilemap[location[0]][location[1]][0] != 0:
particle[1][0] = -particle[1][0]
particle[1][1] *= 0.9
particle[0][1] = oldy
particle[2] -= 1
pygame.draw.circle(screen, particle[3], (int(particle[0][0]),int(particle[0][1])), int(particle[2]/10))
if particle[2] <= 0:
particles.remove(particle)
particle is [[x,y],[angle,velocity],lifespan,colour]
just realized my wall collisions are wrong xD floor is fine though
Using opengl instead of raster graphics via pygame can allow the GPU to help emmensly
does pygame not utilize the gpu already? i've got SLI 970's so opengl will definitely help 😁
oh yeah and while im here, is there a better way to store a tilemap than a 2d list?
The best way to do particles is to write custom shaders I believe. That's a lot of learning though. I don't know if pygame 2.0 uses much of the gpu? Pyglet does, and has opengl bindings. Arcade uses the GPU and hopefully soon will support custom shaders. Or use moderngl or pyglet and write your own.
Shadertoy and related tutorials is one way to learn to write your own shaders.
Hello Guys, does anyone who already used NEAT knows how to save a specific generation after a run?
anyone got any ideas on how i can further optimize my particles?
@coarse roost i know thats not what you want, but i always use a "skip frame".
When you cant draw all the particles in the expected time - 0.016s (60fps), you just skip the next frame drawing. That way your program recovery the loss time in the last frame.
You will lose some fps but the tick will be intacted.
if you want anything more than a quick prototype dont use pygame if you want any performance @coarse roost
it takes alot more to learn a graphics api like opengl but its orders of magnitude more performant
That's pretty impressive already! Like others have said, opengl really is the way to go if you want speed. Though you could do a few optimizations with your code.
Instead of computing the velocity everytime like you do here py particle[0][0] += costable[angle]*particle[1][1] you could only do it whenever you change the angle.
And if your tile_size is a power of 2, you could use bit-shifting instead when computing the grid location.
I don't know how large is your max particle size, but a compromise would be to have your particles as pixels instead, and change the alpha according to their life span. This would allow you to use pygame's PixelArray class and could help a bit with the performance.
Also when you hit a tile, you could just multiply the velocity by -1 instead of changing the angle. This all in all should reduce the amount of divisions and multiplications you're doing.
i started learning pygame!
if anyone knows any good sources or tutorials, do provide a link
im trying to make a side scroller, sort of endless runner, but im more looking for a general pygame tutorial
for now im following tech with tim's pygame tutorial series, but it seems a little slow to me
if anyone has some good youtube or other platform links for pygame dev, ping me
thanks guys!
what's up
@hearty adder kidscancode has a helpful tutorial series, while long, I have found it helpful for learning the concepts and how certain commands work in pygame.
hmm
class Pow(pygame.sprite.Sprite):
def init(self, center):
pygame.sprite.Sprite.init(self)
self.type = random.choice(['shield', 'gun'])
self.image = powerup_images[self.type]
self.image.set_colorkey(WHITE)
self.rect = self.image.get_rect()
self.rect.center = center
self.speedy = 3
so i'm not sure why, but the image will not clear out the white space when it is drawn
(WHITE is a defined variable for the RGB color)
@hearty adder kidscancode has a helpful tutorial series, while long, I have found it helpful for learning the concepts and how certain commands work in pygame.
@pliant dust thanks!
Shouldn't you be using __init__()? and super().__init__() for the inherited class
I honestly don't know, I followed the tutorial, it worked, and then it didn't. All other sprites work with that set up.
super() Just gets you the parent class, so it's the same thing as pygame.sprite.Sprite
Not necessarily
If you did a subclass of MyPow(Pow, MySprite) then super() would go to MySprite instead
It probably doesn't matter here but it is generally preferred to use super() over hardcoding types
Why does python do that? You'd assume that Pow ends first since it's called first right? Is it because they subclass the same class, which would be object?
It allows for easy dependency injection which is a benefit but I think the "real" reason is that it's to solve the famous diamond problem of multiple inheritance
someone got any recommendations on how to make an installer?
or how to use an installer
for a graphic game with images and pygame
wdym installer @unique narwhal
Idk how to explain it really much
lets say I create a game
and I want it to work in every computer
you have to install the app with an installer
Pygame can make it so that you can download an executable (.exe) from your game
If you wanna know more about it, ask the expert himself @foggy python
oh really?
ye
i dm'ed the expert
from walkda: https://discord.gg/3QjpZC
he also owns a website: https://dafluffypotato.com
thanks @iron galleon . I see that the link removal got implemented ;p
has anyone done paul cravens tutorial? I have a question
it's about this section on making an adapting viewport, I'll add only the relevant code for the question:
self.view_bottom = 0
VIEWPORT_MARGIN = 40
def update(self, delta_time):
self.physics_engine.update()
changed = False
left_boundary = self.view_left + VIEWPORT_MARGIN
if self.player_sprite.left < left_boundary:
self.view_left -= left_boundary - self.player_sprite.left
changed = True```
There's more of these if statements for the different directions, but I left it out, then there's this:
```self.view_left = int(self.view_left)
self.view_bottom = int(self.view_bottom)
if changed:
arcade.set_viewport(self.view_left,
SCREEN_WIDTH + self.view_left - 1,
self.view_bottom,
SCREEN_HEIGHT + self.view_bottom - 1)```
can someone help me understand how the left_boundary section works? it wasn't really clear how he came up with the math
so far from what I can read it's saying if the left side of the player is less than the left_boundary size, then .....the part after that I don't get
Viewport stuff can be a bit tricky. I always recommend drawing that down on paper
There is a high possibility arcade 2.4 will also have a camera that makes this simpler to manage
I was wondering if you can change an objects color based on what's the color of the background below it in pygame?
Not sure how that is done in pygame. Can you just read the pixel or something?
or keep some more sparse structure in python to make that easier to deal with?
Depends on the finer details
@celest wasp Imagine you've got a window that is 800 pixels wide. To start with, you might have a viewport then, 0-799
If you scroll to the left 100 pixels, you'd have 100-899.
"Margin" is how close to the edge you need to be, before you start scrolling.
If your character was at 300, then you'd be 200 pixels from the edge. 300-100 = 200.
If your character was at 150, then you'd be 50 pixels from the edge.
If the "margin" was 100 pixels, then 50 is too close, and you'd need to scroll to the left 50 more pixels to maintain that 100 margin.
That's the left-edge.
So if you were scrolled 100 pixels to the right, left would equal 100.
left and bottom together make the coordinate of the lower left corner of the screen.
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
if pygame.mouse.get_pressed()[0] == 1:
print(pygame.mouse.get_pos())
pygame.display.update()
How do I limit the mouse.get_pressed() to only execute on click, and not allow to hold the mouse button?
You can set a variable to true when it is down then check that that variable is false before allowing the second click
If the mouse works with the KEYDOWN event, ( or something similar) that would work to only allow one click.
While I was making a game engine for my game I ran into this issue:
Traceback (most recent call last):
File "main.py", line 148, in <module>
x,ct = trect.move(bmovement, tile_rects)
File "/home/user/Pygame/Throw-Away-Joke/data/engine.py", line 92, in move
collisions = self.obj.move(movement,platforms,ramps)
File "/home/user/Pygame/Throw-Away-Joke/data/engine.py", line 34, in move
xcollisions = collision_test(self.rect,platforms)
File "/home/user/Pygame/Throw-Away-Joke/data/engine.py", line 17, in collision_test
if obj.colliderect(object_1):
AttributeError: 'thrown_obj' object has no attribute 'colliderect'
Does anyone know why this is happening? If you need the code, I can post it
At a guess, without looking into it too much, and not being familiar with the colliderect command, the “thrown-obj” is not having a rectangle generated for it and therefore, cannot be used for the command. Idk if that is what is happening though.
How to make a binder?
Is it possible to use python in the unity engine
Yes, you could probably do that with IronPython, though you'd still need some C# code before you could get it running
ok
well id rather do it the simple way and learn c# because that is one of the languages you can use with unity
depends on how accurate you want to be
if a couple (approx. 5) circles following gravity in 2d is enough pygame should do the trick 🙂
yup. Kind of depends if you need 2D or 3D and how detailed you need the solar system to be
I normally use these ones. Very permissive and based on open data from NASA https://www.solarsystemscope.com/textures/
Distributed under Attribution 4.0 International license:
You may use, adapt, and share these textures for any purpose, even commercially.
but that ones made by Akarys himself!
ahh lol. Sorry 😄
That's actually a planet texture 😄
That's mercury iirc
But I had some fun with nodes so it doesn't looks like mercury anymore haha
So I'm working on a pygame project -- what could I expect to be my limitations
Kind of hard to answer without knowing anything about your project
so my idea is to create a game where it's kind of like asteroids, like the ship moves around but the aliens are static at the top, and if you shoot it, it duplicates though weaker
pygame can handle a lot of sprites per frame
Probably a few thousand easily at least. I'm guessing sprite groups is the way to go
They also provide simple collision testing
Is anyone here familiar with renpy?
just coded snake
The thing is that those are oranges.
hey guys i wanna learn python from scratch where do i start from , can someone help me ?
@drowsy warren check out https://learn.arcade.academy/
@frozen knoll thank you dude
on minmax search you dont calculate the value at each step correcT?
is this the place to discuss help with game code?
Yes
so, i wanna load a picture with pygame.image.load() however the image is in another folder, not in the script folder.
the folders looks like that:
main folder:
assets:
picture.png
scripts:
script_to_load_pic.py
how to load picture.png from script_to_load_pic.py?
@harsh trout Per Rule 6, your invite link has been removed. If you believe this was a mistake, please let staff know!
Our server rules can be found here: https://pythondiscord.com/pages/rules
I think you'd go up a level from your working directory, like cd .. in terminal
That would be os.chdir('..') in py
Then you could finally use assets/picture.png as the image path
@distant granite The best way might be to use the __file__ attribute in the module to create a path to your assets directory
thanks for help :D
Can use os.path or pathlib.Path. I would recommend the latter
For example```python
from pathlib import Path
resource_dir = Path(file).parent.resolve() / 'resources'
resolve just makes sure the path is absolute
oh, ok
but what if the script to load pictures was imported to the main script?
it would make a difference?
nope. __file__ will always be the module's location
Importing it does not change that
oh
Guys is it essential to use pygamr.time?
Yes and no. It more or less keeps the entire program running at a consistent frame rate/speed.
Otherwise you just peg a CPU at 100% too, as you do nothing but loop and loop and loop with no break.
It's crazy to see free-to-play games make more money than premium games now ahahaha
Time to make legend of delza on mobile then
hey guys im new to programming in python and was just beginning to experiment with the pygame module but everytime i try to run a sample projects or code from
shit i wasnt done typing
oops
everytime i try to run the code the terminal executes as if it was the beginning of the program but the graphics window python icon just bounces around in the dock and I cant get the freakin window to open
i couldnt find anybody w/ this same issue on reddit etc so if u know how to help please lmk!!
im in vsc and using a mac
installed the latest version of python, pip, and pygame
hey ! I make a game on pygame with wall composed of squares. But do you know how to associate a rect to each square easily?
You could have a square dataclass, which stores coordinates, a reference to the rectangle and what-not, and store them into a 2d list
i already have a list which stores every coorinates of the walls, but the characters of the game don't move square by square
Can you be more precise with what you want to do?
Having a 2D list of object with texture/position in the list/coordinates on screen seems a good option to me
i make a tower defense and I'm actually coding the behaviour of an ennemy. The level is composed of squares, which are blue if it's the ground where it can moves and red if it's a wall. The level is generated of a list where "m" is a wall and "0" is the ground. And I want collision for each wall
I suppose that pygame have already colision detection, then you can probably calculate the position of the item in your list and check if its m or 0
for example if you have 20x20 squares, you detect a collision at 0, 26, it's probably (0, 1) in your list
if you can build objects, it's even easier, make a list of objects with coordinates and if they block or not, when you detect that you collide with such object, you would just check their property
OK thanks
hi, does anyone know how to store/edit data without using external modules or text files?
oh if youre asking this u can ask general
if youre asking about the game itself ask ehre
oh ya right
Hi, python noob here.
Are there any ways I can determine which framework to use for my game without slogging through opinions?
@dreamy timber I am assuming you've already decided to use Python?
@dreamy timber Copying a previous reply of mine to a similar question: That will depend on your goals. At the very least you'll want to decide between 2d and 3d, and then, from there, figure out how much you expect the engine to handle for you. In general, I would likely go for Arcade for higher-level 2D and Panda3D (or the higher-level Ursina, which is built on top of Panda3D) for 3D. If you want to get more in the guts of graphics rendering, then maybe something like pyglet or moderngl would be better.
@dreamy timber Depends what kind of game you are making I guess..
I usually just recommend Arcade to newbies. What you learn there will transfer to other libraries anyway
Hi guys, why does the word "None" appears in front of my input for each of the 3 players for the following code ?
import random
print ('''Hi guys, few of few will have to guess the correct number between 0 to 10. ''')
number_to_guess = (random.randint(1, 10))
player1 = int (input(print (''' Hi Player1 please have a guess: ''')))
player2 = int (input(print (''' Hi Player2 please have a guess: ''')))
player3 = int (input(print (''' Hi Player3 please have a guess: ''')))
print (''' Now we will see who among you have guessed the right number... ''')
if number_to_guess == player1:
print (''' Bravo Player1. ''')
elif number_to_guess == player2:
print (''' Bravo Player2. ''')
elif number_to_guess == player3:
print (''' Bravo Player3. ''')
else:
print (''' Sorry. None of you found the right number...
The right number was actually %s''' %(number_to_guess))
@dawn quiver Because print returns None. Don't use print inside input. Just provide the string.
@potent ice Thanks a lot pal. Indeed. Found it meanwhile. 🙂