Original Post
[Solved - thanks to Enders!]
So I've been fiddling around with PyGame and I've started building a basic prototype of a 2D RPG. I've encountered some performance problems, however, and before I proceed, I wanted the advice of some experienced programmers on what I'm doing wrong. I'm seeing really low framerates when using a map measuring 256x256, whereas a 128x128 map is all right - and there isn't even much game logic running in the backgorund. My goal is to have maps be at least 1024x1024 in size, if not more, with a considerable amount of game logic running in the background. I'm planning on rewriting some of the code in C++ to speed up the math stuff (I am currently, slowly, learning C++) but I've got a feeling I can get some of this solved in Python simply by programming more intelligently. So here's the rundown:
I have my map divided into square tiles measuring 16 pixels. A 128-size map means 128 pixels by 128 pixels. My program scans a .png image, interprets the color of the pixels into code, and makes a game map out of that code. At any given time, roughly 32x32 tiles are on the game screen, and are part of a list (loadedTiles) that is dealt with for most of the program. All the tiles collectively belond to another list (mapTiles), with which I try to do as little as possible, to keep the workload down. Problem #1 is that more tiles = worse performance, although I don't mean to be doing much with the map tiles other than calculating their positions and checking whether they are within viewing range. One possible help would be to check whether they are in viewing range less often, say every half-tile or something, but I'm not sure what the cleverest way of doing this would be (at the moment, all tiles are being checked every cycle, which is probably not smart).
Problem #2 was with mobs, who were getting jammed at the edge of the screen whenever the avatar moved around. I disabled this by deactivating all mobs that are not in viewing range, but this isn't a great solution if I want to expand mob behavior in the future. Not critical, at the moment, but not great.
Problem #3 is just bizarre; there are three projectile types, and of the three, 2 rotate correctly - FireBlast and IceBlast. But when Arrow rotates, instead of getting an invisible, colorkey expanded rectangle for the sprite, I get a flashing white one. I don't understand this at all, since the code is otherwise the same for the three projectiles.
I've put up my code and art in the files in a link at the end (I couldn't upload it, the board wouldn't let me) and if anyone could take a look at it and give me some pointers, that'd be great. I'm a novice at best, but I'm more than willing to learn the tricks of the trade. For the prototype, controls are as follows:
Arrows or WASD - movement
M - toggles between Editing and Gameplay modes (visible in the upper right)
EDITING MODE:
Left Click - change the tile's type
Right Click - place a mob
Mouse Wheel - cycle through the available tile types
GAMEPLAY MODE
Left Click - shoot
Mouse Wheel - cycle through the available weapons (visible under the hearts)
FILES: http://www.mediafire...oou64zwuavk8b7b
Thanks for any tips or advice!
So I've been fiddling around with PyGame and I've started building a basic prototype of a 2D RPG. I've encountered some performance problems, however, and before I proceed, I wanted the advice of some experienced programmers on what I'm doing wrong. I'm seeing really low framerates when using a map measuring 256x256, whereas a 128x128 map is all right - and there isn't even much game logic running in the backgorund. My goal is to have maps be at least 1024x1024 in size, if not more, with a considerable amount of game logic running in the background. I'm planning on rewriting some of the code in C++ to speed up the math stuff (I am currently, slowly, learning C++) but I've got a feeling I can get some of this solved in Python simply by programming more intelligently. So here's the rundown:
I have my map divided into square tiles measuring 16 pixels. A 128-size map means 128 pixels by 128 pixels. My program scans a .png image, interprets the color of the pixels into code, and makes a game map out of that code. At any given time, roughly 32x32 tiles are on the game screen, and are part of a list (loadedTiles) that is dealt with for most of the program. All the tiles collectively belond to another list (mapTiles), with which I try to do as little as possible, to keep the workload down. Problem #1 is that more tiles = worse performance, although I don't mean to be doing much with the map tiles other than calculating their positions and checking whether they are within viewing range. One possible help would be to check whether they are in viewing range less often, say every half-tile or something, but I'm not sure what the cleverest way of doing this would be (at the moment, all tiles are being checked every cycle, which is probably not smart).
Problem #2 was with mobs, who were getting jammed at the edge of the screen whenever the avatar moved around. I disabled this by deactivating all mobs that are not in viewing range, but this isn't a great solution if I want to expand mob behavior in the future. Not critical, at the moment, but not great.
Problem #3 is just bizarre; there are three projectile types, and of the three, 2 rotate correctly - FireBlast and IceBlast. But when Arrow rotates, instead of getting an invisible, colorkey expanded rectangle for the sprite, I get a flashing white one. I don't understand this at all, since the code is otherwise the same for the three projectiles.
I've put up my code and art in the files in a link at the end (I couldn't upload it, the board wouldn't let me) and if anyone could take a look at it and give me some pointers, that'd be great. I'm a novice at best, but I'm more than willing to learn the tricks of the trade. For the prototype, controls are as follows:
Arrows or WASD - movement
M - toggles between Editing and Gameplay modes (visible in the upper right)
EDITING MODE:
Left Click - change the tile's type
Right Click - place a mob
Mouse Wheel - cycle through the available tile types
GAMEPLAY MODE
Left Click - shoot
Mouse Wheel - cycle through the available weapons (visible under the hearts)
FILES: http://www.mediafire...oou64zwuavk8b7b
Thanks for any tips or advice!