Tag Info

New answers tagged

2

The error is likely the typo in the line: pygame.sprite.Sprite.__init(self) The __init__ function in python is special, and should be called as such. That being said, your code would be cleaner and you could avoid these issues if you used new-style class inheritance: class bullet(pygame.sprite.Sprite): def __init__(self, bullet_vel): ...


4

The concept of a surface in this situation is simply describing a texture. To understand this better, you should also understand the rendering process. When rendering anything using modern graphics API's, the end result is always going to be the same, a buffer (texture) of color data that is presented to the screen. How you get to that buffer can vary quite ...


0

The event VIDEORESIZE is triggered from windowing system, not from pygame. In response to event, program should update display with calling pygame.display.set_mode(newsize, sameoptions)


2

Ensure your worker threads aren't sitting there spinning and forcing unnecessary time sharing across your CPU. This can be solved using manual resets and signals, rather than a spin lock. Additionally, consider profiling major portions of your code to identify hot spots, my research brings up the fact that python itself includes a respectable profiler ...


3

Bresenham's algorithm is specifically built to draw circles with fixed-point mathematics; that is, to rasterize circles. For what you're doing you're almost certainly better off with a much more abstract representation of your circular motion — that is, you want to keep track of your character's angular velocity and to simply move it with constant ...


0

I managed to solve this myself and the method I used was probably not the best but it was really really easy. First I define "enloop" outside of the main loop. enloop = 0 Then inside the loop every time the loop runs: if enloop < 10: enloop = enloop + 1 else: enloop = 0 And later also in the loop: if enloop == 10: enx_speed = ...


3

Don't know python, but here is a basic arbitrary-language example. You should only have one game loop that updates all other entities. You can determine how much time has passed between each running of the loop and pass that information on to the entities who can use this information. For Example: main() { lastSystemTime = currentSystemTime; while ...


1

You only need one infinite loop running very fast to do what you're after. Inside the loop you calculate time elapsed since last run. If it's greater than X, then you call function1. If it's greater than Y, then you call function2.


2

Look here: http://www.nongnu.org/pygsear/doc/api_html/private/pygame.sprite.Sprite-class.html When you subclass Sprite, you must call this pygame.sprite.Sprite.__init__(self) before you add the sprite to any groups, or you will get an error. That seems to be what is missing in order to make Paddle a proper subclass of Sprite.


0

For actually randomly generating a platform, you define the: x = max horizontal distance away from last platform y = max vertical distance away from last platform Use these values along with a random number generator to figure out the new distance. And like I stated in the previous post, you want to change this as the game proceeds. For instance the max ...


0

I actually made a game like this in cocos2d. I chose something similar to a GDC talk about the making of Jetpack Joyride. Which is: Randomly generate about 1000 pixels of platforms at a time. Let's call this a section. When the players starts to get close to the top of this section, go generate another section. This allows you to maybe kind of add some ...


2

You are probably looking for the absolute value! You can implement it like this: def abs(value): if value < 0: return -value else: return value You can use it like this: radius = 20 if abs(playerPositionX - enemyPositionX) < radius: enemyCollidesWithPlayer() However, if your game is in 2D, and you wish to find the ...


3

Your problem is the fact that you're only looking at KEYDOWN events. What you need to do is toggle a boolean value when a key is pressed or released. Something like this would work: # event loop for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: # check for key ...


1

I asked a question here that's very similar, and received the following answer: The way to deal with this is to set a timer once the person taps the phone. The most user friendly scenario that you'd implement would look something like this: When you detect a tap, set a timer (t = timeToRepeat) On each frame, decrease the timer by dt If the ...


2

I don't know python or pygame, but assuming you're using a game library there should be a way to poll the state of the key, such as if it's currently down or not instead of if it was pressed since last update. Use that for checking and updating movement. The next problem you will run into is it will update movement as fast as your logic update interval is ...


3

I don't know python, but have you tried setting a bool to true when the key is pressed, and changing the speed in an if statement based on that bool. When the key gets released you just have to set the bool back to false.


0

I GOT IT WORKING!! I'm going to put all the info here that you need to know, as it's incredibly simple once you get it working. First i'll explain my directory setup: So i have: src\game\main.py. in source, i have a music, graphics, game and data folder. I have all my .py files in the game folder, and the others are self explanatory. Also inside the source ...



Top 50 recent answers are included