i have glitching when pressing buttons with the turtle library - python

I have a pong game that uses a while loop to constantly move the ball to the new co-ordinates through out the game. a move of a few pixels each time. my issue is that when I press buttons to move the pong player paddle, the ball is glitching.
I know that when I press a button the code goes to the function I created to move up. In the split second this is happening, my ball stops moving though.
I was looking for a solution to this problem.
I didn't include my code as I think its a known problem but I was looking for a work around.
Thanks for any help. I can also post my code if needed

Related

How do I trick the app into thinking the mouse movement is really me?

I am attempting to get my script to open up a game through steam and then start a world. This all works fine up until the part where I need to navigate the game. I'm assuming that the modules that let you control the mouse just move to points rather than actually moving the mouse which the game doesn't pick up. The game only becomes responsive when I myself move the mouse around IRL.
I've tried using pyautogui, mouse, pynput, and a couple of more but have had no luck. The game doesn't respond until I intervene. I'd love any help ya'll could give me. Thanks.
Here's some of my code, if it helps.
import pyautogui
import time
def openWorld():
#pyautogui.moveTo(230, 530, 1)
pyautogui.click(x=230, y=530)

How to ignore all pending events? `pygame.event.clear()` does not seem to do anything [duplicate]

I'm coding a little game for a school project: a basket game.
When the user clicks somewhere in the screen, the script gives an initial speed and angle to the ball and the ball starts its path.
I've got a problem: if the user starts to click while the ball has not ended its path yet, pygame saves the click and automatically launches a second path when the first one is over.
I'm looking for a method or anything to clear the event's cache while the path isn't ended.
The pygame.event cache seems to be active whatever...
That's what I already did :
if clic==False : #bool who blocks
if event.type==MOUSEBUTTONDOWN and event.button==1:
clic=True
ball move
...
clic=False
I could have misplaced the bool, but when clic is Flase again all the clicks stocked in the pygame.event start their paths.
If you want I can share with you the whole code but It's written with French comments and there are a lot of pictures that need to be with the script file.
I'm looking for cleaning the cache or just pausing the saving process while my ball is in the air.
I've found the answer sorry for disturbing you.
For the one looking for it, there it is :
if event.type==MOUSEBUTTON ...
ball move
...
pygame.event.clear()
I can help you with the code becasue you havent included any but here is the basic idea. Make a boolean called can_shoot to keep track of what the ball is doing. Once the player shoots set it to False. Keep checking if the ball has completed its path every single frame and as soon as it does, set can_shoot to true again.
if can_shoot:
#code to move the ball
#condition to change can_shoot to False

Check if mouse is outside pygame window

I was running a game in pygame, and I discovered a flaw. The way I coded it, if the mouse went outside of the window, the game started to go around in circles. When you get pygame.mouse.get_pos(), it will return the last value the mouse was detected in the window, but other wise no indication that the mouse has left the window. So, is there any way to check if the mouse has stopped hovering over the pygame window, and has left it?
A simple answer to this would be to use the pygame.mouse.get_focused() function. This returns 0 when the mouse isn't focused on the screen. So if you wanted to check if the mouse was outside the window, you could simply do
mouseFocus = pygame.mouse.get_focused()
During the main loop and have an if statement checking if the mouse has left the screen.
if mouseFocus == 0:
print("mouse is out of screen.")
Hope this helps

How to focus on a window with pygame?

I made a Python game using Pygame. I try to make it so when it starts, it loads the shell, and entering a raw input would display the pygame window and start the game so that I can make the game playable without having to close the shell. It works, however, the window starts minimized. The game is a simple "dodge the object" and has no pause what so ever. The game still runs in the background, possibly having the player hit multiple projectiles before the user realizes it. Is there a way to focus on the window?
For anyone in the future who stumbles across this question:
As of 2022, pygame v2.1.2 has an experimental module ._sdl2 where: Window.focus() is used to make a window to be moved at the top and set focus. Windows.focus() supports optional input_only bool parameter for whenever the window should be moved at the top (False), or just collect input (True).
As I understood you, you don't want the game to start, before the window is in fullscreen-mode, right?
When I try you attempt (starting through rawinput), my display is fullscreen from the start. Have you set everything correctly?
I suggest that you stop the game until there is an actual key-input (whatever controls you have set). Like this the player has the time to arrange everything to his liking before starting the game. Because, even if you figure out how to analyse the focus-issue: When the game starts, the window HAS focus, therefore this approach wouldn't work anyway.

Pygame - first person shooter "look" with mouse

I am not writing a game but a scientific renderer using Pygame. I'd like the controls to work just like in a first-person shooter, so that a user can navigate using a familiar set of controls.
I have tried to write the code to have the same properties as the 'look' feature in e.g. Skyrim or Half-Life but the mouse doesn't move the cursor - it lets you look around and around, in infinite circles. Clicking should have no effect.
The first attempt for the controls:
(code inside a game loop)
delta_y, delta_x = pygame.mouse.get_rel()
rotation_direction.x = float(delta_x)
rotation_direction.y = float(delta_y)
(don't ask me why, but y and x need to be reversed like this to get the expected look directions; must be something to do with the camera transform implementation, which isn't mine.)
This, however, leads to a cursor sitting on top of the window, and when the cursor gets to the edge of the screen the window stops rotating; i.e. the code is reporting the actual position on the screen.
I tried to 'reset' the mouse position every game loop (and, incidentally, hide the mouse):
pygame.mouse.set_pos([150, 150])
pygame.mouse.set_visible(False)
But this generates a symmetrical 'move back to start' delta in the next loop, meaning that you couldn't 'look' anywhere.
To summarize, I want to:
detect actual mouse motion reported from the device
not move/show any OS cursor
not clip at the 'edge of a screen'
What is the best way to do this, using Pygame or other Python hacks?
http://www.pygame.org/docs/ref/mouse.html :
If the mouse cursor is hidden, and input is grabbed to the current display the mouse will enter a virtual input mode, where the relative movements of the mouse will never be stopped by the borders of the screen. See the functions pygame.mouse.set_visible - hide or show the mouse cursor and pygame.event.set_grab (docs) - control the sharing of input devices with other applications to get this configured.
Try calling pygame.mouse.get_rel() once more immediately after the set_pos call to 'throw away' whatever relative movement the set_pos call has performed.
Since you are using pyOpenGL, try gluLookAt() example: How do I use gluLookAt properly?

Categories

Resources