#🔒 Pygame Balistic Simulation
205 messages · Page 1 of 1 (latest)
@bright garden
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
now i can
did u understand what i mean in unzooming the screen
not really
like
you can just be a little more clear
i am launching my simulation and if the ball goes high and fast
so you need to keep a scale
and multiply it to your objects
but basicly i have ti scale my ball and my background yeah?
listen for VIDEORESIZE events
yea
i dont think you need to scale your bg
but the objects fr sure
wait i can show what happens when it launches far away
1 sec
that how it looks
was the window resized
i just clicked here
so that's a resize
now i get it
yea the bg has to be resized
but im not sure how you are drawing the line
yea i get it now
i had an idea like before it launches it calculates were it lands can i do something with that maybe it will be easier?
yea it would help
maybe should i try to make the ball appear always in the middle of the screen
or idk
if i know where it lands
but 3d is very difficult nah?
no its not if you are using the right library
and obviously not dealing with shaders
god damit not shaders hahaha
but you dont have to
it s the most difficult thing
basicly it is 3d
but i will still see in 2d
or
and if i switch to 3d i have add an axis y
that would be defaulted to zero
true
but your physics should handle an additional dimension too
don't you have another solution how to do it without adding an additional library
because i really want to get it done
i think
you can rescale the objects
when you detect your object is hitting the edge of the screen
in function of unzoomig
because i have this thing
look
it multiplies by 100
all the ball movement
so like 100 pixel is 1 meter
so it goes fast away
idk if i explained it clearly
yea i get it
so you wanna play with that scale
so that it reaches the end of the screen everytime
for realism, you can scale the background to match that scale in x-axis
its not a lot
if you dont mind
!rule ads
The rules and guidelines that apply to this community can be found on our rules page. We expect all members of the community to have read and understood these.
the screen you are using is a pygame.surface?
i think yes
can you just push me
what is my first step?
since you want the ball to land in the screen
because i am a begginer in python
and you know the velocity of the ball
you can fix a point where the ball would land on the screen (viewport)
and only scale the background
what do you mean with that
like before the ball start it 's trajectory it draws the point on the screen where it lands
so if the full background is the same size as the screen what would you see when the ball goes off screen exactly?
it starts directly in this size of window \
I know but what do you see behind the ball when it goes off screen (theoretically if you can recenter it, what do you want drawn behind the ball)
i ll show you one sec
i don't want to look stupid but i don't really understand your question, i am really sorry
if i understood it right, it's the ball trajectory from it start to end
he means behind the trajectory
do u want the background to scale and become bigger
to fill the black void
or something else
yes thank you, technically your picture shows the ball going off the background... so what's the new background
also, why don't you just figure out the max distance the ball can go and divide it by the size of your screen and make the max distance 5 pixels from the right edge of the screen?
ohhh okey i understand now, i wanted that when the ball reaches the edge the screen strats unzooming so the ball stays visible the whole time, and speaking of black void i want that just my main background takes the size of resized window
idk if i wrote it clearly
bcs english is not my native language and sometimes for me thing that i wright are understandable but in fact they re not
and for the max distance it's interesant but still with 100px/m the ball still goes fast away from the window
if you do 100px per meter you can only go 34 meter on a widescreen...
yeah i know
say max distance is 1000, why not just make 1 = 0.96 meter (since you made the window 960 width)
but if i do it less the ball moves like a snail
I'm not sure this will help at al
i made it just for the begining
i want that it opens automaticly full windowed
but one trick I learned way back when I tried learning programming is, you might get better mileage by moving the background
like flappy bird
or
essentially, I made a crappy flappy bird clone in unity several years ago
then I quit programming and had to learn it all over
here is some code that I have that maybe will help you:
main_initial_size = ((SCREEN_WIDTH, SCREEN_HEIGHT))
#create the main screen and subscreens
main_screen = pygame.display.set_mode(main_initial_size, pygame.RESIZABLE)
....(snip)....
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.VIDEORESIZE:
main_new_size = event.size
ratio_increase = (main_new_size[0]/main_initial_size[0],
main_new_size[1]/main_initial_size[1])
main_initial_size = main_new_size
for window in window_list:
window.recalculate_window_param()
manager.get_resized_window_data()
here is my code for my window class so you can see what the window.recalculate_window_param() does:
is this for a game or a project? I would get annoyed if I had a game in half screen mode and it decided to resize itself on me
it's a project
that i am doing to improve
in python
and at school we had balistics and stuff
and i was thinking why not
if event.type == pygame.VIDEORESIZE:
main_new_size = event.size
ratio_increase = (main_new_size[0]/main_initial_size[0],
main_new_size[1]/main_initial_size[1])
main_initial_size = main_new_size
for window in window_list:
window.recalculate_window_param()
manager.get_resized_window_data()
can you explain what exacly these line of code does
if event.type == pygame.VIDEORESIZE: - if the user resized the window
main_new_size = event.size - event.size is the size that the screen becomes, it's from the event
the ratio takes the new size[0] (width) and [1] (height) and divides it by the original size to get a ratio for x,y and puts it in a tuple
it then sets the initial size to the new size (in case the user resizes the window several times you need to calculate from the new size)
I store all windows in my program in a list called window_list so it recalculates all their sizes and new locations based on the main display size
don't worry about manager.get_resized_window_data(). manager is a instance of a class that needs the window size of the screen
okey thanks a lot
wow an active thread
hi
hi
wanna join?
@obtuse delta so what would be the first step
to reach the right goal
I actually don't know how to resize the window
the main display that is
with code
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
pygame.display.set_mode((1200, 1200))
ok this works, so what you can do is check is the balls x position is > width and if so pygame.display.set_mode((new_width, new_height))
i see yeah
but here i have to put limits on how far the ball can go
and the lims are pretty small
i think
yes because your moving the ball and you have limited screen space
depends what effect you really want.
I recommend drawing out to yourself what exactly each item needs to do first and then learn each step.
starting with vague generalities can't be implemented in code so you need steps for each item
I also just started coding python a few weeks ago so I'm also new and stuggle with design
well for me the disign is not the most important part, i just want that it works
yea but what do you want to happen when the ball reaches the end of the screen exactly?
well i have a code that calculates where the ball will land
I'm working on a 34 inch screen, so when it gets to width pixel 3399, what do you want to happen
this still seems to me like scrolling the background might be easier
well your solution needs to be independent of screen size
if you scroll and reach the end of your picture, reload the picture at the end and start over
just need to make sure there is no obvious seam
it is but you are going to want to create 2 surfaces, in this example the blue surface with the road tha doesn't change in size, and then the cannon/arcs which are what's changing in size
yeah i see
so they solve your problem by making a static size background and then making everything else bigger or smaller to look like a zoom in or out. It won't work if they can measure the size of something against your background
so basicly i can just make the ball bigger or smaller in fact
to have the same effect
?
and the background just stays the same
no because the clouds and the sun will show it's just the ball size
you also aren't changing the size of the ball. you need to change the size of the surface the ball is on
tbh, I'm not the right person for art style effects, I just noticed what they were doing
welcome, good luck
what I figure with programining is computer needs each step. Where we think we take several steps for granted, computers know nothing and need each step spelled out for them
if you tell them rules they are better at calculating at following, but they need 5 steps for things we think of as one
thats true
i was thinking of a solution
and what i found
if i know where it lands i just can make the same screen size as the posion where it lands
- ball_size
so the ball is exactly visible
what do you think
its worth trying any idea u come with
if it goes wrong, u'll understand how to fix it
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.