FAQ Database Discussion Community


'str' object has no attribute 'play' while making a random sound chooser

python,pygame
Me again, yesterday I asked this question - Choosing a random sound Pygame and have hit an issue when testing my implementation. The error message is: Traceback (most recent call last): File "F:/Source Code/Python/graphicalSlotMachine/net/Toby/GSM/Main.py", line 5, in <module> class Main: File "F:/Source Code/Python/graphicalSlotMachine/net/Toby/GSM/Main.py", line 6, in Main fruity = Machine.fruitMachine()...

Having Trouble Blitting Image From Dictionary

python,python-2.7,dictionary,pygame,sprite
So I'm trying to get into using Pygame, but all of the tutorials I can find online utilize only one file. I played around with ideas on how I can load all of the images in a single function. and decided on saving them in a Dictionary. Problem is, when...

Pygame 3D: How to and is it possible?

python,performance,dictionary,3d,pygame
So I want to program a 3d-mesh viewer in pygame, no other 3rd-party modules wanted (panda3d is perfect, but it's very complicated). My idea is: list_of_surfs = {'85 50':'70deg'} #the 85 50 and the dimensions of the #side/surf, and 70 deg of rotation to be able to see it, then...

Error while installing pygame using pip for python 3.4

python,install,pygame,pip
Sorry, thought i edited to say i am on windows 64 bit When trying to install Pygame using pip, I get the following error: "requirement 'pygame.whl' looks like a file name, but the file does not exist pygame.whl is not a valid wheel filename." I have my file paths right...

Pygame borderless opening with some offset

python,pygame
When i try to open a borderless mode window it does start in the top right corner of the screen. It looks like this: http://puu.sh/ivB4y/304018da5e.jpg The code looks like this if __name__ == "__main__": import source.Game, pygame pygame.mixer.pre_init(22050, 16, 2, 256) pygame.font.init() pygame.init() screen = pygame.display.set_mode((1920, 1080), pygame.NOFRAME) source.Game.Game().main(screen) It...

Pygame math module was not found

python,pygame
I have problem with pygame, when I try to use pygame.math it says "no math module in init.py", I have installed newest version from pygame website http://www.pygame.org/download.shtml

Pyinstaller pygame.macosx.Video_AutoInit() call FAILED

osx,python-2.7,pygame,32-bit,pyinstaller
I have a problem trying to get a one-dir python application using pyinstaller. I edited the .spec file to add some files I needed. # -*- mode: python -*- a = Analysis(['main.py'], pathex=['/Users/mazzalex02/GAME'], hiddenimports=[], hookspath=None, runtime_hooks=None) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, exclude_binaries=True, name='main', debug=False, strip=None, upx=True, console=True) font...

pygame sprite and draw method not working as expected

python,pygame
Please any help would be greatly appreciated. I am writing a game with Pygame and after creating all the classes and methods I need. When I run the game I see five alien characters of my game showing up from the left side of the screen joined together before I...

Issues with movement in pygame

python,pygame
I have my image moving correctly when I put in the inputs, but since I need the image to quit moving when I let go of the key, I naturally used pygame.KEYUP to make all movement stop. However, this leads to choppy gameplay because if you even hit a button...

Constant Animation on Pygame Sprites

python,python-3.x,pygame,sprite
I have recently been trying to make a animation where my sprite moves back and forth between 2 picture in a constantly without any pause. I was wondering how to go about doing this. Any help would be appreciated, so far what I have: import pygame import os import time...

How can i make sprites spawn on random locations using pygame?

python,pygame,sprite,game-physics
Ive been trying to make a twist on a dodger-like game, where some blocks make you grow and others make you shrink. I'm also planning to add a red one of which is supposed to make you lose a life(you will have 3 lives starting out), and various others with...

how can I add text to these rectangles?

python,text,menu,pygame,python-3.4
This is the code I have started to use to make a start menu. # we need some colours!! black = (0,0,0) white = (255,255,200) red = (200,0,0) green = (0, 200, 0) bright_red = (255, 0 ,0) bright_green = (0, 255, 0) bright_white = (255, 255, 255) def main():...

Extending pygame sprite class

python,class,pygame
So I'm writing a game in python with pygame, and I have separate classes (of the type pygame.sprite.Sprite) for my different sprites - however they all share a lot of common physics code. How can I extend the basic sprite class, so that common physics stuff is written once, and...

How to make the background of a pygame sprite transparent

python,pygame
This is supposed to just load a sprite onto the screen, but the background of the image is this black box, and i don't want to see that. How do I make the background of the image transparent? from Tkinter import * import pygame from livewires import games #Creating screen...

Need Help in Python Variable updation (Pygame module)

python,python-2.7,variables,python-3.x,pygame
I am trying to increase my speed variable in my pygame code. But as i run this piece of code the speed remain 0.1 (if i press UP key) and 0 (else case). I am unable to debug this. Any help in this would be greatly appreciated. import pygame speed...

“Invalid destination position for blit” in pygame when loading configuration from file

python,python-2.7,pygame
I am trying unsuccessfully to load a room from a file during runtime. What confuses me the most is that this line of code: ObjGlobal.instances.append(oPlayer.oPlayer(x, y)) successfully creates an object when executed in the main function, but when put not when in the file loading function: File "E:\Fun Stuff\Python Stuff\Python...

While loop executing class, then stopping rather than starting over?

python,class,python-2.7,loops,pygame
I was experimenting with Pygame, and came up with this code: import os import sys import pygame import time from random import randrange from pygame.locals import * class bedrock(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image('Bedrock.png', -1) self.rect.center = (mapx,mapy) class coalore(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image('CoalOre.png', -1)...

Pygame draw anti-aliased thick line

python,pygame,line,antialiasing
I used to draw lines (given some start and end points) at pygame like this: pygame.draw.line(window, color_L1, X0, X1, 2), where 2 was defining the thickness of the line. As, anti-aliasing is not supported by .draw, so I moved to .gfxdraw and pygame.gfxdraw.line(window, X0[0], X0[1], X1[0], X1[1], color_L1). However, this...

Unexpected syntax error while using 'blit' on pygame [closed]

python,python-3.x,pygame,python-3.4
import pygame import sys from pygame.locals import * pygame.init() white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,255,0) blue = (0,0,255) yellow = (255,255,0) cyan = (0,255,255) purple = (255,0,255) bg = black fps = 30 dispWidth = 800 dispHeight = 600 pixMove = 10 UP =...

Python/Pygame: Placing text in a specific location

python,pygame,python-3.4
In my code, I am trying to place a text box in a specific location. screen = pygame.display.set_mode((1000, 600), 0, 32) #Set the window to 1000x600 WHITE = (255, 255, 255) BLUE = (0, 0, 255) text = font.render('Start', True, BLACK) textRect = text.get_rect() What does the last line do,...

pygame error: Tuple has no attribute get_size()

python,pygame
I have tried everything I can think of to get this background to work, this is the closest I have gotten as it breaks no other bits of my code. I am unsure why get_size() doesn't work. gameDisplay = pygame.display.set_mode = ((display_width, display_height)) myFont = pygame.font.SysFont("monospace", 15) pygame.display.set_caption("Catastrophee") background =...

How to present numpy array into pygame surface?

python,numpy,pygame,pygame-surface
I'm writing a code that part of it is reading an image source and displaying it on the screen for the user to interact with. I also need the sharpened image data. I use the following to read the data and display it in pyGame def image_and_sharpen_array(file_name): #read the image...

Python ImportError: DLL load failed: The specified module could not be found

python,pygame
I recently downloaded and installed pygame. I tested it with the following code. import pygame I received the following error: C:\Python34>python test.py Traceback (most recent call last): File "test.py", line 1, in <module> import pygame File "C:\Python34\lib\site-packages\pygame\__init__.py", line 95, in <module> from pygame.base import * ImportError: DLL load failed: The...

Make a draggable black box

python,python-2.7,pygame
I'm trying to make a black box which I can click and drag but I seem to be stuck. Could anybody help me see where I'm going wrong? def main_game(): import pygame import math from time import * pygame.init() displayWidth = 268 displayHeight = 552 cyan = (0,255,255) red =...

Pygame FPS faster than what I want

python,pygame
I am trying to run a game at 80 fps but I am getting 83 fps?! What's going on? while 1: start = time() clock.tick_busy_loop(80) self.update() fps=int(1./(time()-start)) print fps, 'fps' >> 83 fps ...

QUIT pygame event is not defined

python,events,pygame
I have two for loops: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() quit() if event.type == KEYDOWN: if event.key == K_p: banana = False sportscar = True for event in pygame.event.get: if event.type == QUIT: pygame.quit() quit() Whenever I run my code, I get this error: Traceback (most...

Python PodSixNet Error

python,python-2.7,pygame,multiplayer
I'm trying to use a multiplayer module called PodSixNet to use in one of my games, but I get an error in assyncore.py when trying to run the client. However, the server works flawlessly. I developed simple test client and server programs, but I still get the same error when...

Pygame gives me TypeError: add() argument after * must be a sequence, not Ball when adding Ball to sprite group

oop,python-2.7,pygame,sprite
Recently, I have been messing around with pygame and I decided to make a pong clone. However, I am running into problems with the ball class. This is my class: class Ball(pygame.sprite.Sprite): """ This class represents the ball that bounces around. """ # Constructor function def __init__(self, x, y): #...

pygame draw lifebar with a clipping area

pygame
I'd like to draw a lifebar with pygame by using a clipping area (limit the area to a half when half of the hitpoints are gone for example.) But even though the clipping area is correct, I always get the full image. That's my lifebar class: class Lifebar(): def __init__(self,x,y,images,owner):...

Countdown timer in Pygame

python,pygame
I started using pygame and I want to do simple game. One of the elements which I need is countdown timer. How can I do the countdown time (eg 10 seconds) in PyGame?

Sending an image in python without saving it

python,image,sockets,pygame,python-imaging-library
I've just started working with PIL and Pygame and I wanted to create a screen-sharing program. In order to take a screenshot I used ImageGrab.grab() and now I want to send it to another computer and open it in Pygame without saving it on any of the computers. This is...

Getting my drawing into pygame without .blit()

python,pygame
I've got my own drawing loaded on to the screen and scaled it to the size I want, but the background of the program I used to make the drawing is still on the image. I noticed that when I move the image, the background doesn't move with the picture,...

Random movement pygame

python,random,pygame,movement
I'm trying to make a simple life simulator, and I need the "cells" to move almost randomly (with a few rules) across the screen. But the problem is, after a while they tend to bunch up in the upper-left corner of the screen. I tried to change a lot of...

Pong in PyGame, Moving paddles causes the ball to stop regenerating when hitting the side

python,pygame,pong
So I am trying to create a simple single player Pong game with pygame. The ball starts and when it hits the wall it will regenerate.... as long as I don't move the paddle. When I move the paddle the ball then just bounces off all the walls and doesn't...

Dealing with Sprites and Collisions Using Pygame

python,pygame,sprite
I am learning python using pygame and I am working on something that involves sprites and collisions. I've looked at some examples but I still don't quite understand it. What I am attempting to do is to be able to add sprites(a ball) when the user presses the "=" key...

Pygame - Printing out seconds using Time

python,time,pygame,clock
this may be something simple, yet I can't figure out a way to do this; I am trying to print the seconds. I use: r = int(pygame.time.get_ticks) print(r/1000) It prints out the seconds but what I want it to do is to print out the seconds just once. So basically...

Multiprocessing queue: pygame surface died

python,multithreading,image,pygame,pygame-surface
I want to use multiprocessing to separate two tasks in pygame: Pulling an image from a webcam and showing the image on a screen. The reason I want to do this, is because I want to have fancy image processing I want to separate the web cam polling from the...

How do i play a sound in python 3?

python,audio,pygame
I wanted to write a python script to play a sound (recorded using windows recorder)! I read pygame can do the job and installed pygame! But I don't know how to write a code that plays a sound from a specific path! I have to play an audio file located...

PyGame wont register keydowns

python,osx,pygame,osx-yosemite
I have installed pygame on my macbook and it seems to be working however it doesnt seem to be registering specific keys For example RunGame = True while RunGame: for event in pygame.event.get(): if event.type == pygame.QUIT: RunGame = False if event.type == pygame.K_LEFT: Direction = 'West' The quit code...

Pygame - Moving Sprites at Different Speeds

python,pygame
I am working on the mechanics of several sprites i am using. I am working on game that involves collecting coins. I have sprite image of a spinning coin. I created a class for the coin sprite and I wrote an update function which switches from one image sprite to...

Random invalid syntax in python

python,pygame
I am trying out some stuff in python using the pygame module. this is my code: import pygame, sys direction = " " pygame.init() try: while True: for events in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygaqme.KEYDOWN: if event.key == pygame.K_w: forward = True elif event.key ==...

Python/Pygame Trouble with Game loop/Getting code to run

python,pygame,game-loop
For the past few days I've been working on this code for pong and I've almost got it running. Everything works up to the movement of the objects. The screen just freezes when the pygame window opens. There seems to be something wrong in my main() but I am still...

How do I blit specific indexes of text to the screen in pygame

python,python-2.7,pygame
import pygame import math def StoryLine(): pygame.init() width = 1104 height = 644 white = 255,255,255 red = 255,0,0 color = 255,0,0 black = 0,0,0 cyan = 0,255,255 gameDisplay = pygame.display.set_mode((width,height)) pygame.display.set_caption('War Games 3') Map = pygame.image.load('Map3Cut.png') Map = pygame.transform.scale(Map, (1104,644)) stop = False while not stop: gameDisplay.blit(Map, (0,0)) StoryText...

Pygame: Colliding Rectangle on multiple other rectangles

python,pygame
I am attempting to create a game in which a block moves back and forth until the player presses space. Upon which, the block jumps to the next line up and stops. Currently i am having problems with the collision code. The error being thrown up by the shell is:...

How can I display an image on top of an image in PyGame?

python,python-3.x,pygame,pygame-surface
I am creating a version of Pong in Python 3, using the library PyGame. I am trying to render an image as the "table" background, then displaying the ball on top of it. My issue is that the ball is the only image showing, displaying a black background. However, if...

pygame: Stopping movement behind line

python,pygame
I am attempting to create a game that lets a block move "jump" and land on a platform above it. Then, jump again to the next platform. Unfortunately, my code currently just stops when the block touches the bottom of the platform and moves no further. I am unsure why...

Pygame nested while loop: [Errno 10054] An existing connection was forcibly closed by the remote host

python,while-loop,pygame
I am using pygame with pyscripter and pyopengl, and am trying to put a while loop inside the main while loop, but as soon as the game enters the inner loop, it repeats the loop forever and I can't get out running = True while running: keys=pygame.key.get_pressed() ## do game...

__init__() got unexpected keyword argument 'y'

python,pygame,livewires
I'm following the book, 'Python Programming For The Absolute Beginner' and decided to test some of my skills by making my own game. The game is basically "don't get hit by the flying spikes" and I have come across a problem with it. When running it with this code: class...

How to get the rect() of a dynamic circle

python,pygame,pygame-surface
I am trying to get the rect of the circle in the draw method but Pygame gives an error everytime I call the get_rect() method on my Alien instance. I want a dynamic circle surface for collision detection because my code generates different random size of circles. Please any help...

Sending Webcam feed via socket

python,sockets,pygame,webcam
I know this question came up already a couple of times and I read it all ( I hope...) But in my programm I can't display the image after I have send it through the socket no matter what I try. I am using Python 2.7 on client side and...

Installing modules in Python without command line

python,pygame,pip
Hi I am going interstate and will only have my laptop with me, I do not have admin rights on it and the use of Cmd is banned. I want to be able to use Pygame on my laptop. How can I install the module without command line?

This loop appears to not be constant, but I don't know why

python,pygame
I am trying to test a random number generator for my test game I've been working on. It is presently set to always perform the action regardless of the generated number and simply say "cheeeeeeeese" on the screen, but my issue is that it flashes that word upon input by...

Printing small rectangles to the screen in a for loop. (pygame)

python,python-3.x,for-loop,pygame
I'm trying to get a code to print small rectangles all over my screen in pygame with the help of for loops, but having trouble. I have solved parts of it with this code but it looks ugly and preforms bad: x = 0 y = 0 for y_row in...

Why isn't my pygame display displaying anything?

python,python-2.7,pygame,genetic-algorithm
I am working on a program that evolves creatures over time using a genetic algorithm. However, for some reason, my pygame display stopped working and I have absolutely no idea why. When I run the program, the window opens but then it just sits on a black screen. I have...

Pygame + OpenGL - how to draw text after glBegin()?

python,opengl,pygame
I found somewhere on StackOverflow this cross-platform way to draw text: def drawText(x, y, text): position = (x, y, 0) font = pygame.font.Font(None, 64) textSurface = font.render(text, True, (255,255,255,255), (0,0,0,255)) textData = pygame.image.tostring(textSurface, "RGBA", True) GL.glRasterPos3d(*position) GL.glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, textData) The problem is that I cannot call drawText after...

Python - How can I make this un-pickleable object pickleable?

python,save,pygame,pickle,renpy
So, I have an object that has quite a bit of non-pickleable things in it (pygame events, orderedDicts, clock, etc.) and I need to save it to disk. Thing is, if I can just get this thing to store a string that has the progress (a single integer is all...

pygame.draw.circle, still draws a square

python,python-3.x,pygame
I'm making a version of http://agar.io and i'm trying to make the circle shape for the player. I have been trying to use pygame.draw.circle to draw it, however it keeps showing a square. Thanks for help! import pygame, sys, random from pygame.locals import * # set up pygame pygame.init() mainClock...

Blurring in PyGame

python,graphics,pygame,2d
I'm working on a short intro in PyGame, and I need to blur some static lines. After two days of searching, I can't find anything. Does PyGame have a built-in method to blur a shape or surface? Will I need to do it manually? What would be the best way...

Pygame - Making a Sprite “walk” in the right direction

python,pygame,sprite
I am continuing my work using pygame. I am currently working on the enemy class. Basically, it will walk from one side to another. I can get it to walk between the set boundaries, but I cannot get the image to display the proper direction the enemy is facing. If...

How do I display a tiled map in Pygame using Tiled and pytmx?

python,python-2.7,pygame,tiled
I'm aware there is a similar question but the answers were not specific enough to be useful in my case. I am trying to create a program that can display a tiled map created in Tiled and uploaded into Pygame using pytmx. The only issue I'm having is blitting the...

Creating a countdown timer in Pygame

python,timer,pygame
I already read the post over here but it's different than my question. I'm making a game, the game's main ingredient is a countdown timer (no character moving, no map only a timer) - and I'm looking for a way that I could update the screen globally every millisecond to...

Any tips on creating a Pygame Developer Console?

python-3.x,pygame,console-application
I've been getting my feet wet with Python and Pygame, and after a few bugs in a very basic game that I have been making, I've thought to myself that having some sort of console that can deal with string input (from a developer) would be very handy. Here's an...

Pygame: Using colliderect in classes

python,python-2.7,pygame
This the the sprite class: class Minion(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.color = tuple([random.randrange(0, 256), random.randrange(0, 256), random.randrange(0, 256)]) self.x = x self.y = y self.minion = pygame.Rect(self.x, self.y, 15, 25) pygame.draw.rect(SCREEN, self.color, (self.x, self.y, 15, 25)) This is the code being used for a tower defense game. Now...

“ImportError: No module named pygame.base” - Pypy3 and pygame

python,debian,pygame,libraries,pypy
After several trials for install pygame in pypy3, I did it with the bitbucket version, cloning with mercurial and installing this way: "pypypath"/bin/pypy3 setup.py However, when I'll make the import, the following error appears: Traceback (most recent call last): File "/home/rafael/PycharmProjects/pygame-teste/__init__.py", line 3, in <module> import pygame File "/opt/pypy3-2.4.0-linux64/site-packages/pygame/__init__.py", line...

PyGame : use of pygame.sprite.LayeredUpdates()

python,pygame
I had a look at the documentation and tried to find examples online but I didn't manage to layer my sprites. Here is parts of the code: class Player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self, self.groups) ... self.layer = 2 class Tree(pygame.sprite.Sprite): def __init__(self, screen_size, tree_id): pygame.sprite.Sprite.__init__(self, self.groups) ... self.layer = 1 pygame.init()...

TypeError: must be pygame.Surface, not list

python,pygame,surface
This is my code and I was trying to make a rectangle: import pygame import sys pygame.init() color = [255,20,78] black = [0,0,0] screen = pygame.display.set_mode((800,600), 0, 32) pygame.display.set_caption("Rectangle") while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() screen.fill(color) pygame.draw.rect(color, black, [400,300,10,10]) pygame.display.update() I don't understand what...

Pygame read axis value from BU0836X HID device

python,pygame,joystick
I have a BU0836X Joystick Interface board which I want to use to read analog Joystick values. http://www.leobodnar.com/shop/index.php?main_page=product_info&products_id=180 On the computer there is a python script running capturing the joystick values using pygame's joystick module. However, it's possible to get all the information from the board, such as the name,...

Why is it disregarding the code?

python,pygame
I am trying to make an "animation" for the start of my game, but as my code goes on it is starting to feel unresponsive to change that I make. For instance, even if I make ML = 99999999 instead of starting over at ML = 1, it will still...

Pygame- detect if a key is held down?

python,pygame
So I am doing a simple thing, and have been following a tutorial on youtube. I have the ability to move the banshee (I used an image from Halo for my ship) using WASD, but I have to repetitively tap keys, whereas I want to be able to move it...

How do I get a “list” of ALL the events in real time in SDL 2.0?

c++,pygame,sdl,sdl-2
I come from Pygame, and there I had pygame.event.get(), which returned a list of all events (So, once I had that list of events inside the mainloop, I could check for multiple keypresses or whatever in real-time, since ALL possible events were available). Now here's my code: #include "init.h" #include...

Python/Pygame How to make something disappear off of screen after a set amount of time?

python,timer,pygame,startup
I was wondering if there was any sort of code to make something disappear from the screen after a set time? Something like an intro to your game?

Python / pygame error with my custom image import module (image animation)?

python,image,animation,module,pygame
I have created a custom module for importing images and be able to resize it and easily animate them (basicly you say the frames that it have the animation, and it's split the image to the amount you say). (I know that they are not perfect!) Here is the module...

How to make interactive area around boxes?

python,python-3.x,pygame
Imagine a picture of 4 boxes with different colors. Below is the code I tried. I would like to know to make other pictures pop up when I click on one of the boxes (how to mark the area and read clicking for later use). Is there an easier way...

Error using sprite module in python 3.1

python,pygame,sprite
I'm a high school student undertaking a software design and development course for my HSC, I have been trying to learn pygame, and I have been doing some work with sprites and rooms, as I finished up the code I ran into a number of errors. First off here is...

How do I make it so it goes to a new scene on keypress? (Pygame)

python,python-2.7,pygame,scene
I am very new and I cant seem to find any tutorials on how to do this. I would imagine it would be pretty simple. I am creating an Oregon Trail type game and I need it to go to the next picture when you press E, or quit the...

Only one Button is drawn on screen

python,button,pygame
When I define a button like this onebut = ButtonCPyg() onebut.giveOpt(x=0,y=0,width=400,height=200,action = helloW) # hello word onebut.changeText("Hello","coolFont.otf",25,(0,0,0)) onebut.changePic("thepic.png","thepicOver.png") It's working fine. I can display it whith .display() and the .listen()-Method works also. But the problem is, when I define the second button ... onebutt2 = ButtonCPyg() onebutt2.giveOpt(x=200,y=600,width=400,height=200,action = helloWW) onebutt2.changeText(newText="Hello",newFont="coolFont.otf",newSize=25,newColor=...

How can I install Pygame to Pycharm?

python-2.7,pygame,pycharm
I recently installed pycahrm, I installed PIP and tried to install Pygame. There wasn't a just "Pygame" but there were sound effects and other things for it. What I really want is to install Pygame onto my pycharm.

Replace Text On Pygame Window

python,text,pygame
I am making a score system on my python file. I tried using this: font = pygame.font.SysFont(None, 25) text = font.render('Score: '+str(score), True, black) gameDisplay.blit(text, [0,0]) For some reason, the new score goes on top of the old score, and you can't read it. It makes a huge blob of...

How do I get compiled python(with cxFreeze) to get the current working directory as the directory where the executable is in?

python,pygame,cx-freeze
I am working on a mac and I am writing a game in python and pygame that needs some sound files to be present in the same directory where the source code is. The thing is it works when I run the source code through the python interpreter. It doesn't...

Using Pygame's pixArray to draw a square

python,python-3.x,pygame
I'm currently creating a drawing program using pygame. Ti draw, I'm using a pixarray. I want the drawing size to be changeable, so I set up my pixarray like this: pixArray[p1+i][p2+i] = mousecolor pixArray[p1-i][p2+i] = mousecolor pixArray[p1+i][p2-i] = mousecolor pixArray[p1-i][p2-i] = mousecolor where i is coming from for i in...

Pygame: Spaceinvaders: can't shoot bullets

python,python-3.x,pygame
I am currently building a mockup of space invaders. I want to make the user shoot stuff and the invaders will die (1hit kill), but I can't seem to figure out how to do that. I have tried drawing a small rectangle, but then the background paints over it. Thanks...

Pygame webcam streaming client can't execute with python 3.4

python-3.x,pygame,video-streaming
I'm using pygame and python3.4 for stream a webcam in a Odroid board. The server is this (extracted of this post: using pygame to stream over sockets in python error ): import socket import pygame import pygame.camera import sys import time port = 5000 pygame.init() serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.bind(("",port))...

Why does a certain if statement only trigger once in a while loop?

python,while-loop,pygame,collision,pong
I'm trying to get into game programming but I'm having difficulty with the first game I'm making. I want to make a pong game, but I can't get the collision detection to work twice. It works once either way the ball goes, but the second time doesn't work. Here's my...

Pygame help: Game text constantly stuck on screen (timer not working)

python,pygame
I'm trying to make a simple submarine game in Pygame and I'm having problems displaying a piece of text called 'crashed' whenever the player hits the boundaries of the game window. The text is supposed to appear on the screen as soon as the submarine collides with the game boundary...

Pygame: Only a portion of the circle is eating things up

python,pygame
I'm trying to make a circle destroy something when it touches it. Then it will grow a little. Eventually at a certain size, I can notice that only a square area within the circle is actually eating it. import pygame, sys, random from pygame.locals import * # set up pygame...

python: langton's ant pygame first step issues

python,algorithm,python-2.7,pygame
I'm trying to make a graphic representation of the Langton's ant algorithm but I'm stuck. here's the Langton's Ant video description That's what the output should be: My code: import pygame width = 800 height = 600 display = display=pygame.display.set_mode((width,height)) pygame.init() direction = "up" pixel_width_height = 2 qg = pixel_width_height...

Not sure why If Statement is not working. (Pygame)

python,python-2.7,if-statement,pygame
Ok so now when I press E at "start.png" it jumps to "cele.png" when I would expect it to go to "new.png". I want it to start at "start.png" then when you press E it should change to "new.png" and if you press E again while background is "new.png" then...

Using pygame to play a MIDI file from stream

python,io,pygame,midi,bytesio
What I want to do is the following: Create a MIDI file, but only in memory, and feed it into pygame.mixer.music.load(). Here is what I've been trying (I'm using MidiFile from here): import pygame.mixer import MidiFile3 import io pygame.mixer.init() midi = MidiFile3.MIDIFile(1) # midi file with one track midi.addTrackName(0,0,"Track 1")...

Pygame, livewires: Attribute error: Message object has no attribute 'handle collide'

python,pygame,livewires
I'm making a game using the special 'pygame' and 'livewires' from Python Programming For The Absolute Beginner and it's working pretty well, for the most part. At the moment you can play the game, a timer will tick by and then when a spike hits you the text 'Lose! Time:'...

python pygame - how to create a drag and drop with multiple images?

python,image,drag-and-drop,pygame
So I've been trying to create a jigsaw puzzle using pygame in python.The only problem is that I'm having trouble creating the board with multiple images that i can drag along the screen (no need to connect the images like a puzzle what so ever just a simple drag and...

Adding Pygame to PYTHONPATH

python,path,pygame,pythonpath
Windows 8 64 bit Python 3.4.3 Pygame-1.9.2a0.win32-py3.4 I'm in the process of trying to install Pygame now. This computer has two hard-drives, and I'm not sure if that means anything, but when I try and install Pygame it defaults to my D:\ drive. Python itself is installed on my...

How to access a global object inside of a class?

python,pygame,livewires
I need to access a global object inside of a class to change it's image. Here's the code: import pygame from livewires import games from livewires import color import time import random games.init(screen_width = 640, screen_height = 480, fps = 50) class Cursor(games.Sprite): """The pokemon based cursor!""" def __init__(self, image,...

Python: how to bounce off the side of the screen

python,pygame
Okay, I am using inventwithpython to teach myself how to code. I am attempting to reuse the code in my own way to understand how it works, but this part is giving me trouble: in Chapter 17 There is a set of animation code where different size boxes bounce off...

A variable in my code won't define properly

python,debugging,variables,math,pygame
This is my code for a maths program I am making for high school. I am struggling at the moment because I can't figure out what I've done wrong, it says that sum1 isn't defined. If someone could please take their time to go through my code and sort it...

Bounce back animation difficulty with space invaders clone

python,pygame,python-3.4
import time import pygame import random player = pygame.image.load('player.png') BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) BLUE = (0, 0, 255) GREEN = (0, 255, 0) class enemy(pygame.sprite.Sprite): def __init__(self, color): super().__init__() self.image = pygame.Surface([10, 15]) self.image.fill(color) self.rect = self.image.get_rect() enemy_spd =...

Pygame Clamp-IP glitch?

python,python-3.x,github,pygame
I am having a problem with pygame's clamp_ip() method. I can't seem to figure out what the problem is. I have a rectangle for my camera, and called player.clamp_ip(camera) but it fails to clamp. My code is on github. I am also running the latest pygame with Python 3.4. Another...

Python(Pygame) Key Error

python,pygame
I am making a game in pygame using a tilemap, and I've encountered the follwing error "Traceback (most recent call last): File "C:\Users\Dusty\Dropbox\~MAIN FOLDER~\Projects\Sunless\game.py", line 52, in <module> surface.blit(textures[tileMap[row][column]], (column*tileSize, row*tileSize, tileSize, tileSize)) KeyError: 174" With this code: import pygame gameIsRunning = True tileSize = 32 mapHeight = 19 mapWidth...

PyGame Menu Formatting

python,visual-studio-2010,pygame
So I've been recently working on programming a game in Python as well as an external library called PyGame. If anyone is familiar with the game Hearthstone, that is sort of the feel I'm going for. However, that is besides the point. I have already researched how to display images...

Drawing pentagon,hexagon in Pygame

python,algorithm,pygame,python-3.4
I'm trying to make functions that can draw pentagon hexagon etc. Troubling on algorithm, should I compare the lines with pygame.draw.line ? It looks like too much work around the determine coords of lines. Is there an easy way to draw them? Also I don't know another library that can...

Image doesn't move in Pygame

python,pygame
Please, My Pygame image doesn't move but when I change the code to print and I press the arrow keys, it does work. Any help would be greatly appreciated. I have imported OS, random and pygame in my original code as well as set width and height to 800, 600...