pygame

Opinion on GUI for a Battleship game in Python

…衆ロ難τιáo~ 提交于 2020-01-16 11:27:09
问题 I am making a battleship game for a project. While I have completed the logic and the game works with text input. I was hoping make a (very basic) GUI while still use the methods created for the text. The two options I've been looking at are PyGame and Tkinter. PyGame does not seem to have a text output/label function. Tkinter does, but it doesn't seem as easy (i feel) as PyGame is. Though I would love to give either of these frameworks the time they deserve, I have just over 60hrs before

easy SublimeText question regarding pygame module

谁说我不能喝 提交于 2020-01-16 08:07:10
问题 I've been using SublimeText on OSX without issue... until I tried to import pygame. A simple few lines of code like: print("Hello") import sys import pygame gets the following output: Hello Traceback (most recent call last): File "/Users/andrewjmiller/Desktop/python_work/new_file.py", line 5, in <module> import pygame ImportError: No module named pygame [Finished in 0.0s with exit code 1] [shell_cmd: python -u "/Users/andrewjmiller/Desktop/python_work/new_file.py"] [dir: /Users/andrewjmiller

Segmentation Fault with opening and closing Pygame WIndows

二次信任 提交于 2020-01-16 01:48:25
问题 I'm working on a project where I am trying to alternate between the camera preview on a picamera, and some text on screen using pygame windows. I have gotten to the point where I can open the picamera, then some text, then the picamera again, but when I try to open a pygame window for more text, I get a segmentation fault. I think the main problem is quitting the pygame window, without quitting the other things I need to open up another pygame window. The commands like sys.exit, and pygame

Pygame installation on Windows - error: Unable to find vcvarsall.bat

烂漫一生 提交于 2020-01-15 09:20:52
问题 I have a Win7 64 bit dev machine. I've downloaded and installed Python 2.6.6 32bit. I've also downloaded pygame 1.9.1 for python 2.6 and tried to install it. I got: C:\pygame-1.9.1release>setup.py install .... running build_ext building 'pygame._numericsurfarray' extension error: Unable to find vcvarsall.bat What should I do? (I don't have any compiler or visual studio or anything installed, if it's relevant) 回答1: On PyGame's download page - use the msi file which is a dedicated Windows

Update text in real time by calling two functions Pygame

假如想象 提交于 2020-01-15 09:04:29
问题 I have program that takes input from the user and displays multiple variations of the input using the Population() function. The store_fit function adds these different variations to a list then deletes them so that the list is only populated with one variation at a time. I want to be able to get the variation from the list and use it to update my text. However, my program only updates the text after the Population function is completed. How could I run the Population function and update my

How to create a global variable from a local and store it's previous value?

大憨熊 提交于 2020-01-15 07:55:06
问题 In my pygame game, I want the bullet to be able to detect when it's within the given hitbox. To do this I need to create a global variable from a local. However, the global variable is updated to the new hitbox every time a new object appears. That doesn't let me track the previous hitbox and detect when a bullet is within the old objects that are still on the screen. How do I prevent this? How should I store the previous value of a? Here is the class where I'm defining the hitbox and the

Close multi threaded application with KeyboardInterrupt

丶灬走出姿态 提交于 2020-01-15 07:07:16
问题 I have an app with two threads. One is a pygame thread which runs a simple game, the other thread is a listening server which accepts messages which are used to control the game. Here is the stripped down pseudo code: class ServerThread(threading.Thread): def run(self): class SingleTCPHandler(SocketServer.BaseRequestHandler): try: while(1): ... #Receive messages from socket. Add them to pygame event queue ... except KeyboardInterrupt: sys.exit(0) ... ... class PygameThread(threading.Thread):

Close multi threaded application with KeyboardInterrupt

送分小仙女□ 提交于 2020-01-15 07:05:08
问题 I have an app with two threads. One is a pygame thread which runs a simple game, the other thread is a listening server which accepts messages which are used to control the game. Here is the stripped down pseudo code: class ServerThread(threading.Thread): def run(self): class SingleTCPHandler(SocketServer.BaseRequestHandler): try: while(1): ... #Receive messages from socket. Add them to pygame event queue ... except KeyboardInterrupt: sys.exit(0) ... ... class PygameThread(threading.Thread):

pygame.time.wait() makes the window freez

大兔子大兔子 提交于 2020-01-15 06:23:31
问题 I have a simple animation to handle where I draw a rectangle and when I click on the surface, the rectangle slid left and wait for 2 seconds and then redraw it with a slid motion to the right, but if I reduce or move the window and make a try the window freezes on the waiting moment. Here is the code: import sys, pygame from pygame.locals import * pygame.init() FPS = 30 BGCOLOR = (255, 255, 255) RECTCOLOR = (10, 0, 199) DS = pygame.display.set_mode( (200,200) ) CLOCK = pygame.time.Clock()

How to delay a part of my program without affecting the rest?

此生再无相见时 提交于 2020-01-15 05:25:49
问题 I have a program in which I utilize a score counter. That score counter is initially 100 and stays like that until a certain threshold is crossed. The threshold variable is called shipy and my score is called score . I implemented something that subtracts 1 from my score every 0.1s once shipy is over 400, but doing it like that causes my whole program to run slower. Here a snippet of my code: shipy = 0 score = 100 # some code here doing something, eg. counting shipy up if shipy > 400: time