Skip to content

Latest commit

 

History

History
299 lines (209 loc) · 14.6 KB

notes.md

File metadata and controls

299 lines (209 loc) · 14.6 KB

StackOverflow            reply.it reply.it



Code snippets at repl.it

replt-it-40 replt-it-32

replit.com trinket.io

Template

# GitHub:
# https://github.com/Rabbid76/PyGameExamplesAndAnswers/blob/master/documentation/pygame/pygame_event_and_application_loop.md
#
# Stack Overflow:
# https://stackoverflow.com/questions/63540062/pygame-unresponsive-display/63540113#63540113
**[![](https://i.sstatic.net/5jD0C.png) repl.it/@Rabbid76/PyGame-MinimalApplicationLoop](https://replit.com/@Rabbid76/PyGame-MinimalApplicationLoop#main.py)**
**[![][1] repl.it/@Rabbid76/PyGame-MinimalApplicationLoop](https://replit.com/@Rabbid76/PyGame-MinimalApplicationLoop#main.py)**

  [1]: https://i.sstatic.net/5jD0C.png

Investigate answered questions

How to set alpha transparency property using pygame.draw.line? How can I detect if the user has double-clicked in pygame?

Answers

Add Answers

next:

Pygame water ripple effect
Pygame water physics not working as intended

Pygame - Return collision location
How would I draw different images based on the number of adjacent tiles?
How to handle tile rotation in pytmx?

Postponed

Difference between pygame.display.update and pygame.display.flip
Basic networking with Pygame
What fonts can I use with pygame.font.Font?

Draw

Draw a circle that contains color gradient in pygame

Collision and intersection

How to know if two ellipses are colliding - Pygame
How create a simulation (pendulum, projectile motion) in pygame
How can you pre-calculate the balls trajectory and therefore its endpoint in the game Pong?
python ball physics simulation
Intersection between bezier curve and a line segment
Line collision in pygame
Pygame: Collision by Sides of Sprite
How can I rewrite my collision logic in my pygame platformer?

Questions about music and sound

pygame audio playback speed
pygame simulaton saved as a mp4 file
pygame: get the current time of the music
Is there a way to create a simple user-interactive music synth in python
Pygame: Instantiating a Mixer object
How to play sounds in two devices with pygame mixer in parallel?

Questions about video

Python Write MIDI file

Questions about size, and resizing

pygame dual monitors and fullscreen
Allowing resizing window pyGame
How to get the resolution of a monitor in Pygame?
Change display orientation with pygame

Not answered questions

Self-driving car not improving with Q-Learning
arbitrary polygon with transparency in pygame
Framerate drops from 60 fps to 30 fps when blitting texture using BLEND_RGB_MULT flag?
A-star algorithm results in weird, slow and inefficient choices
Speed up AI obstacle detection in python pygame
Why is a generated SVG image less rich than the corresponding PNG image
Why is pixel manipulation with pygame.surfarra slower than with pygame.image?

Text

Formatting text in pygame as a table

Threading

pygame multithread client socket GUI Blocking

Investigate

How to make keyboard Input into unicode/japanese characters?
Update during resize in Pygame

Transparent window

Fully transparent windows in Pygame?
pygame transparent window alpha?
How to make a pygame window transparent while still receiving and blocking mouse clicks?

URL

Convert Image from Request to Pygame Surface

Questions

Move and stay in window

Add question: How do i keep my player in the window.

Answer: 1. use clmap_ip; 2. Use modulo (%) operator

How to create rectangle centered around a point

Why is there no pygame.Rect(0, 0, w, t).get_rect(center = (x, y))

rect = pygame.Rect(x, y, 0, 0).inflate(x, h)

Examples

Fix examples

  • pygame_minimal_intersect_circle_rectangle_4.py: fix intersection of edge with circle (increase rectangle 100x100)

New examples

New Pages

Color

pygame.Color object

Combine Gray scale image color multiplier and bit mask.

New projects

Random enemies

  1. Spawn enemies (represented by a red dot) at random locations one after the other at certain intervals The enemies should not intersect and keep a minimum distance to each other.

  2. Implement a swarm movement.

Memory game

Simple 4x4 memory ga,e

Rubik's

PyGame CPU Rubik's
PyGame OpenGL Rubik's

Leap Motion

Leap Motion

Pong

Sophisticated circle and rectangle intersection

Sometimes the ball doesn't bounce off the paddle in pong game

(update question title)

Compute relative movement of sphere and rectangle. Find intersection on the way.

PyGame object library

Shapes class like circle, ellipse, triangle, polygon etc. based on pygame.Rectangle. Sprite class (SpriteShape) which can represent a shape class. Operator which can compute the intersections of the shapes.

Platform game

Intersect with lines instead of rectangles. Optionally lines can have an intersecting and a non intersecting side (normal vector). The intersection with blocks can be determined by the intersection with 1, 3 or 4 lines, where the intersection just works if the object comes from the "outside" the block and not from "inside" the block.

Collision

Triangle

Barycentric cooridnates of triangle (Drawing a triangle in OpenGL fragment shader):

--------------------------------------------------------
| s |           | (p1.a - p0.a) , (p2.a - p0.a) , p0.a |   | p.a |
| t | = inverse | (p1.b - p0.b) , (p2.b - p0.b) , p0.b | * | p.b |
| 1 |           |       0       ,       0       ,   1  |   |  1  |
------------------------------------------------------------------
in triangle = (s+t) <= 1.0 && s >= 0 && t >= 0