We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

45

Mode 7 is a very simple effect. It projects a 2D x/y texture (or tiles) to some floor/ceiling. Old SNES use hardware to do this, but modern computers are so powerful that you can do this realtime (and no need of ASM as you mention). Basic 3D math formula to project a 3D point (x, y, z) to a 2D point (x, y) is : x' = x / z; y' = y / z; When you think ...


43

tl;dr don't mix your event loop with your game loop. When you move your mouse, the game receives a load of pygame.MOUSEMOTION events. You don't actually use these events to update your mouse position though, you are getting the current state of the mouse using pygame.mouse.get_pos(). That's inefficient, but it's not the problem. The problem is you are ...


20

I've recently implemented an algorithm for a procedural city layout. It's still very much a work in progress, but seems promising to me. Take a look: The algorithm used to create this layout is loosely based on L-Systems. I have a base Element class, that has a rectangle marking its place on map and a method Grow, which creates other Elements inside the ...


11

Conceptually you've got it, just think of the rectangle as a helper for you to deal with position and collision detection of your image. To implement it you could use: mySprite.image = pygame.transform.rotate(Surface, angle) This will give you a rotated Surface (image), then you can use: mySprite.rect = mySprite.image.get_rect() To give you your new ...


9

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 ...


9

If I understand right, your map stores whether something is dirt or air, and the simplest thing would be to have dirt and air tiles. However, to make things look better, you have separate images for air above dirt, dirt above air, dirt left of air, and so on. So you're trying to figure out which image to use, given a tile and its neighbors. Is that right? ...


9

Isn't the code supposed to be analyzed from top to bottom like in regular Python so that the enemyTurn() is called just once and then the game goes back to waiting for user input? The code is executed just like normal code; your assertion here is correct except that your code doesn't have anywhere that "waits for user input." The function pygame.event....


8

Back in January, 2011, I looked at five GUI toolkits for pygame, and tried to get all of them working with Python 3. The five were: Albow, GooeyPy, PGU, pqGUI, and sgc. I didn't succeed with GooeyPy, but I did get the other four to work with Python 3. (I wanted to also try poutine, by Shandy Brown, but I couldn't find it, and I entirely overlooked Ocemp.) ...


8

There's this GDC talk on procedural building generation from a couple of years ago. It's for creating individual buildings based on a set of templates, but not for creating whole cities (laying out streets and so forth). There isn't any free code to go with it, unfortunately. The system described in the talk is implemented in Unreal although I'm not clear ...


8

convert() is used to convert the pygame.Surface to the same pixel format as the one you use for final display, the same one created from pygame.display.set_mode(). If you don't call it, then every time you blit a surface to your display surface, a pixel conversion will be needed - this is a per pixel operation, very slow - instead of a series of memory ...


7

Let me list some general compared optimizations related to Blitting pixels to a surface(from my experience). 1)Usually palette images(indexed images) when blitted, will under go one extra level of redirection (to get the color).So they will be slow when blitting when compared to true color images. 2)True color pixel data (assume With out Alpha - say24 bit ...


7

If you read the pygame.time.Clock.tick() and pygame.time.Clock.get_fps() documents, you'll find that: tick() works with milliseconds - it returns the number of milliseconds since the last call get_fps() returns an average of the last 10 calls to tick(). If you do the math, that's pretty damn good that you're getting 59.8 most of the time, since with 60 FPS ...


6

Just separate the events from the drawing. The normal method is to redraw all the time, not to wait for something to change. Normally your loop should be like this: while loop: check events: # find routes, block path, whatever update things: # change the state of the game draw() You shouldn't be thinking in terms of drawing one ...


6

It's only randomized the first time because you're only calling the random function one time (when you create the monster object). When you have ma=random.randmint(5, 20) in your class then you are creating that variable with a random amount at that time, but you are not altering it. In order to get a random value every time you need to reset the value every ...


6

In a game, music would be the a way to play background music and sound the way to play sound effects (ej. jumping, firing, etc). Music is a special streaming channel of the Mixer. This means the file is streamed from disk in small chuncks and not loaded at once. Pygame only supports one Music at a time but you can have several Sound objects playing at once,...


6

You can use the size method size() size(text) -> (width, height) Returns the dimensions needed to render the text. This can be used to help determine the positioning needed for text before it isrendered. It can also be used for wordwrapping and other layout effects. Here is an example myFont = pygame.font.Font(None, fontSize) width = myFont....


6

You could look at Skulpt.org which provides a completely brower-based implementation of PyGame. However I do not know what external APIs PyGame uses and which are supported by Skulpt. Edit: it seems Skulpt also has WebGL bindings so this should be very possible!


6

Use a file format that supports alpha (png), an editor that can save it with a transparent background (gimp2, photoshop, basically not paint) and make sure you load the sprite correctly


5

however there is not an awful lot of commercial games using PyGame, and I'd like to invest my time in the best way and ideally to make an extra buck in the future. And who cares? The toolchain is not what makes a game commercial or not, it's not what makes it a AAA title or not. PyGame will not prevent you from realizing your goal of creating a ...


5

sprite.convert() doesn't do what you think it does. sprite = sprite.convert() is what you need.


5

Here's how I'd approach it: There is always a single open area, represented by a polygon. All other areas are irrelevant. A line starts when you move from the perimeter of the polygon into the polygon's interior. A line stops when you move from the polygon's interior back onto the perimeter. When you stop the line, you have divided the polygon into two ...


5

It would be faster to store all the tiles in a array and then simply check the tile at the players position. That would eliminate the loop (pseudo code): TileDataClass[500,500] arr = mapdata arr[playerposx,playerposy].color = red


5

First we need to clarify what "smooth movement" is. Let's first talk about smooth movement in a pixelated space. Not taking into account motion blur and sub-pixel movement, the smoothest amount of movement you can have on a pixel screen is one pixel. So your code pygame.draw.circle(SCREEN, (255, 255, 255), (newx, SCREENRECT.centery), 30) pygame.display....


5

I suggest you implement some flocking behavior principles on the movement method. If you don't know about flocking algorithms, here are some useful links and tutorials: http://harry.me/blog/2011/02/17/neat-algorithms-flocking/ http://www.lalena.com/AI/Flock/ The trick would be the following: 1- The movement and its direction each frame will be controlled ...


5

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 (...


5

PyGame itself, being a wrapper around SDL, is unable to directly use hardware acceleration. You can, however, use PyGame to create an OpenGL context and then render into that via an OpenGL library like pyglet or PyOpenGL, which will let you then also use GLSL vertex and fragment shaders. This blog post does a good job of explaining the basics of using ...


5

First you need to calculate the vector pointing from your player to the current mouse position. This can be done by subtracting the player's position with the mouse's position: mouse_x, mouse_y = pygame.mouse.get_pos() rel_x, rel_y = mouse_x - self.x, mouse_y - self.y Then calculate the angle: angle = math.atan2(rel_y, rel_x) This will calculate the ...


4

I want to be a game developer... now what? This is a pretty comprehensive guide to starting out in game development, covering what languages are available, then a list of the most popular tools and libraries, as well as free and commercial book suggestions. Most of what is inside is completely free and provides direct download links. However, it is a ...


4

A couple of things that I do when debugging games: Use a console to output relevant information. Output debug data directly on top of your game screen. Since you are dealing with a game loop, breakpoints are sometimes quite difficult to use when debugging such things as character movement. Displaying the data you want to verify on screen while you are ...


4

Like Tetrad said, it's a really good idea to constrain all of your conversions to a single place on your code. This will ensure consistency across the game. I'm not familiar with Python, but in C# I'd create a small helper class to help me with this. For instance: public static class UnitsConverter { public static float M2P(float meters) { return ...


Only top voted, non community-wiki answers of a minimum length are eligible