Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cube3d.py #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srivamsidandu
Copy link

In this modified version, I removed the elif event.type == hapi.pygame.MOUSEBUTTONUP block and the draging = False line from that block. Additionally, I removed the try, except, else, and finally blocks, as they weren't necessary for the suggested modification.

Now, the pygame.QUIT event is directly handled in the event loop, and if that event is detected, it sets hapi.is_running to False and breaks out of the loop. This should provide a cleaner and more direct exit mechanism when the quit button is pressed.

In this modified version, I removed the elif event.type == hapi.pygame.MOUSEBUTTONUP block and the draging = False line from that block. Additionally, I removed the try, except, else, and finally blocks, as they weren't necessary for the suggested modification.

Now, the pygame.QUIT event is directly handled in the event loop, and if that event is detected, it sets hapi.is_running to False and breaks out of the loop. This should provide a cleaner and more direct exit mechanism when the quit button is pressed.
@Abdur-rahmaanJ
Copy link
Owner

@TheBigKahuna353 Is it fixed?

@srivamsidandu
Copy link
Author

Yes i have changed it you can check it in the commits
And i have also pull requested for this please merge it if you find no errors


pmouseX = hapi.mouseX()
pmouseY = hapi.mouseY()

for event in hapi.pygame.event.get():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooman handles events itself and it is bad in pygame to call this function twice in the same loop. What you can do is create a function called def handle_event(event) or similar and then update hooman of this by hapi.handle_events = handle_event.

for event in hapi.pygame.event.get():
if event.type == hapi.pygame.QUIT:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using above comment, this becomes unnecessary as hooman does this

see hooman.event_loop() to see the actual hooman code so you know what i mean.

# for i in range(8):
# hapi.ellipse( 50+ points[i].x, 50+ points[i].y, 5, 5)

pmouseX = hapi.mouseX()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot to keep these 2 lines, very crucial as this variable is the previous mouse position

for event in hapi.pygame.event.get():
if event.type == hapi.pygame.QUIT:
hapi.is_running = False
break

if event.type == hapi.pygame.KEYDOWN:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this, it doesnt do anything

break

elif event.type == hapi.pygame.MOUSEBUTTONUP:
draging = False

elif event.type == hapi.pygame.MOUSEMOTION:
if dragging:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using MOUSEBUTTONUP and MOUSEBUTTONDOWN events to see if the mouse is dragging, you could change this line to if hapi.pygame.mouse.get_pressed()[0]:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants