Hot answers tagged

8 votes

How can I make the player "look" to the mouse direction? (Pygame / 2D)

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: ...
Ted Klein Bergman's user avatar
6 votes

Pygame for python 3.5?

This site showed me how to do it: https://skellykiernan.wordpress.com/2015/01/04/python-pygame-install/ Note that the site uses Python 3.4.2 and pygame version 34cp, but I did it with Python 3.5 and ...
EdinsonC's user avatar
  • 161
6 votes
Accepted

How to get rid of the white border/background on my png image?

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
Bálint's user avatar
  • 14.8k
4 votes

Collision detection with PyGame

The Pygame Rect already comes with a few collision detection functions that may just do what you need: pygame.Rect.contains: ...
Lucas Siqueira's user avatar
4 votes

Too slow for cycle in Pygame

Your problem here is that this does not work for CPU, it should be done using GPU, probably you can access it in pygame. It's the work of pixel shader and it works on very low level, with thousands of ...
Candid Moon _Max_'s user avatar
3 votes

Rotating hitboxes in PyGame?

Building on Tyyppi_77's answer above, there are a few approaches you can take: 1) Resizing the hit box (as he suggests) - although you can do it much much easier just by using image.get_rect(), which ...
Chris's user avatar
  • 191
3 votes

PYGAME: When I release two directional keys together the player keep moving

In pygame (and many other frameworks like it), events are received in an event queue. Multiple events can arrive per frame, for example when you press or release two buttons together. You need to ...
congusbongus's user avatar
  • 14.8k
3 votes

Locking the frame rate in pygame?

clock.tick() only sets the loops at intervals of milliseconds, so at 60 fps, it will make each game loop at 16 milliseconds, not 16.6666 (which is what you need) ...
William Hou's user avatar
3 votes

Pygame time.get_fps() value

Looking at the implementation of clock.tick() and where in that module the FPS value is set (search for _clock->fps =), the documentation seems to be correct ...
Thomas Perl's user avatar
3 votes

Doing an SNES Mode 7 (affine transform) effect in pygame

Here is the code to make it. I is the same code of the tutorial that I made on my blog. Check there to learn the Mode 7 method and the RayCasting. Basically, the pseudo code is it: ...
Vinícius Biavatti's user avatar
3 votes
Accepted

Implementing Story and Quests in RPG

As far as I see it the Shop class (for example) needs dependencies on at least two classes: The current status of the player-character (things like available money,...
Philipp's user avatar
  • 118k
3 votes
Accepted

2d MMO world generation?

I couldn't tell from your question if your world is top down or side on. But I'm going to assume top down for my answer. If you just want the blocks to be totally random, all you'd need to is go ...
Grady's user avatar
  • 415
3 votes

How to make an object move outside the map and appear on the other side with a tilemap?

Your set_target() method currently chooses the next tile to move your player. You will need to know the bounds of your tilemap to move the player to the other side when reaching a wall. A simple way ...
Simon N.'s user avatar
  • 186
3 votes
Accepted

Performance drawing in Pygame

I resolved the issue I was facing severe fps drops using my background image and blocks. Though I changed it so when I loaded them into my program, I used .convert() at the end. The .convert() made a ...
Kyle's user avatar
  • 69
3 votes
Accepted

What is the difference between Pygames, Pyglet and Kivy and how each helps python game development?

The difference between the three frameworks/engines is the abstraction level. Pyglet is low level compared to the other two and is based on SDL, a popular C++ multimedia library. You'll have to use ...
Bálint's user avatar
  • 14.8k
3 votes

Separate objects for hitbox and sprite?

Instead of making your player object inherit from the sprite class you could use member variables for the sprite and rect. Your player class can then stand alone, and have separate sprite and rect ...
Jay's user avatar
  • 800
3 votes
Accepted

How do I port a game which uses print-output to pygame font rendering with the least amount of work?

This sounds like a pretty classic abstraction problem, general to all programming and not just games. I'll provide some explanation in terms of a text game though to suit your question. Absolutely ...
Sean Middleditch's user avatar
3 votes
Accepted

Ensure that random enemies don't spawn just near the player

The simplest system I can think of consists in testing the position of the new enemy before your screen.blit(), like so: ...
Sisyphe's user avatar
  • 66
3 votes

How to properly set up a lives system for a side-scroller in pygame

The player loses many lives because you don't tell your game to ignore collisions after the first frame there is a collision. Since there is a collision detected each frame, another life will be ...
Vaillancourt's user avatar
  • 16.3k
2 votes

RPG movement holding down button

I believe that this is what you were looking for: ...
Ethan McRae's user avatar
2 votes

Pygame wall collision is acting very odd

You might need to look into axis separation. When it comes to collision detection in 2d with rects, you need to split up your movement and collision detection into separate x- and y-axis. In other ...
mbzdkc's user avatar
  • 91
2 votes
Accepted

What Is A Good Way To Make A Self Updating Game? (Python)

Create two separate applications: Your actual game and a launcher. Configure your installer to create shortcuts for the launcher, not the actual game. When the launcher is executed, it first goes ...
Philipp's user avatar
  • 118k
2 votes

Pygame freezing on QUIT

...
Flutterguy135's user avatar
2 votes

How to program destructibles?

A rational approach might be to simplify your problem. This is a game, so most of the time there is no need for 100% accurate physics. Instead of tracking every single component that makes your ship, ...
rlam12's user avatar
  • 380
2 votes
Accepted

How to integrate Tiled maps and collision detection with pygame?

Since no other solution to this question has been posted - and I now know a solution - I figured I would answer my own question so it may be useful for others. Consider the Tiled map that looks like ...
James's user avatar
  • 183
2 votes
Accepted

How to figure out which tiles are within view, and where to draw them in the grid?

To make the camera move when the player gets near the edge of the screen, you're going to need to set up a collision for the player to hit. In the image, as the player moves closer to the displays ...
Flutterguy135's user avatar

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