pygame

Pack program *and* dynamically loaded files into single executable? (python + pygame, or language agnostic)

南楼画角 提交于 2019-12-30 14:40:07
问题 There are plenty of great answers to questions about making a standalone executable, but I can't figure out how to pack art assets (or dynamically loaded files) into it as well. Why would I want to do this? Because it would be great to distribute a simple (throw away) game that lives entirely in a single executable with no installer. As far as I can tell from searching, there are two basic approaches. 1) Avoid art assets in favor of content generation. I could have a program that turns a

Pygame.init() not working [duplicate]

爱⌒轻易说出口 提交于 2019-12-30 14:29:41
问题 This question already has answers here : i keep getting the error 'module' object has no attribute 'init' [duplicate] (2 answers) Closed last year . I downloaded pygame successfully but now when I do: import pygame pygame.init() size = [400, 400] pygame.display.set_mode(size) it gives errors: Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> pygame.init AttributeError: 'module' object has no attribute 'init' And nothing is working for me. Please help me use init and

Making a C extension to Python that requires another extension

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 09:33:08
问题 I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to use functions from Pygame, and I'm not sure if this is possible. Pygame installs some header files, but they don't seem to have C versions of the Python functions. Maybe I'm

Screen displays only in top left corner of window

谁说我不能喝 提交于 2019-12-30 09:32:34
问题 I'm starting to explore Python and Pygame, however I am running into a problem. Everything I draw to the screen is only displayed in the top left quarter of the window. I thought it was my code but any demo programs I tried also display the same way. Demo code from thenewboston on youtube import pygame, sys from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640,360),0,32) background = pygame.image.load("Background.jpg").convert() mouse_c = pygame.image.load("ball.png"

Making a C extension to Python that requires another extension

假如想象 提交于 2019-12-30 09:32:19
问题 I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to use functions from Pygame, and I'm not sure if this is possible. Pygame installs some header files, but they don't seem to have C versions of the Python functions. Maybe I'm

Screen displays only in top left corner of window

血红的双手。 提交于 2019-12-30 09:32:10
问题 I'm starting to explore Python and Pygame, however I am running into a problem. Everything I draw to the screen is only displayed in the top left quarter of the window. I thought it was my code but any demo programs I tried also display the same way. Demo code from thenewboston on youtube import pygame, sys from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640,360),0,32) background = pygame.image.load("Background.jpg").convert() mouse_c = pygame.image.load("ball.png"

In Pygame, normalizing game-speed across different fps values

狂风中的少年 提交于 2019-12-30 08:59:31
问题 I'm messing around with Pygame, making some simple games just to learn it. However, I'm having a hard time implementing fps the way that I want. From what I understand, fps is generally set with: import pygame ... clock = pygame.time.Clock() while True: clock.tick(60) And then throughout the program, I make sure that every loop/frame is written to take 1/60th of a second, so I can, for example, make objects move at the speed I want them too. Increasing the tick to 120 fps will make the game

Separating Axis Theorem and Python

百般思念 提交于 2019-12-30 06:56:30
问题 This is what I am currently doing: Creating 4 axis that are perpendicular to 4 edges of 2 rectangles. Since they are rectangles I do not need to generate an axis (normal) per edge. I then loop over my 4 axes. So for each axis: I get the projection of every corner of a rectangle on to the axis. There are 2 lists (arrays) containing those projections. One for each rectangle. I then get the dot product of each projection and the axis. This returns a scalar value that can be used to to determine

python ball physics simulation

北战南征 提交于 2019-12-30 06:30:32
问题 I have seen the great tutorial by Peter Colling Ridge on http://www.petercollingridge.co.uk/pygame-physics-simulation/ and I am extending the PyParticles script The code is available on the site(for free), I am using PyParticles4.py Classes used in the tutorial The Particle Class Circular 2d objects with radius,mass,velocity,location The Spring Class A spring that binds 2 objects (Particles) and uses the Hooke's law (F = -kx) to determine the interaction between them The Environment Class The

How can I randomly place several non-colliding rects?

落花浮王杯 提交于 2019-12-30 03:20:09
问题 I'm working on some 2D games with Pygame. I need to place several objects at the same time randomly without them intersecting . I have tried a few obvious methods but they didn't work. Obvious methods follow (in pseudo): create list of objects for object in list: for other object in list: if object collides with other object: create new list of objects That method took forever. Other method I tried: create list of objects for object in list: for other object in list: if object collides with