pygame

Undo colour Blending in Pygame

余生长醉 提交于 2019-12-24 10:27:55
问题 In a game that I'm working on using pygame, I'm trying add hitflash. To those who are unfamiliar with what this is, hitflash is an effect where an enemy flashes a colour - usually white - for about half a second (Don't quote me on that, that's my way of describing it). This can be done with the Surface.fill() function by passing in an additional argument. In order to achieve the hitflash effect, I fill the image with white and blend it. However, I am unaware of how I can revert the image to

How do you fix: “AttributeError: 'Boundary' object has no attribute 'rect'”?

泄露秘密 提交于 2019-12-24 10:01:05
问题 I am making a platformer game where there is a boundary in the beginning of the level, so the player can't just keep going to the left for no reason. I decided to make a class called boundary and add it into a list where the rules are you can't pass it. However, I keep getting this error: "AttributeError: 'Boundary' object has no attribute 'rect'". Can anybody fix this? Also, a better way to do this would also be accepted. Thanks! class Boundary(pygame.sprite.Sprite): def __init__(self):

pygame: What is the difference between an image and a sprite?

旧街凉风 提交于 2019-12-24 09:26:15
问题 What is the difference between importing a rocket sprite (for example) and setting it as an image vs importing a rocket sprite and setting it as a sprite in pygame? 回答1: I think you're just getting confused about the terminology: Image An image is just a collection of pixels. You're using "sprite" to refer to an image on the disk, but that's just an image file. To use your rocket example, you would load the image like this: rocket_img = pygame.image.load('rocket.png').convert_alpha() You can

Creating a Auto targeting bullet

早过忘川 提交于 2019-12-24 08:59:27
问题 I have been creating a typical type of space invader game using Python and pygame sprites. I have done most of the things and it's working fine. But actually in my game, the bullet always shoots straight, but I want it to target the enemy and always shoot where the enemy is. In my player update I am just doing that whenever space is hit, it fires the bullet. if (keys[pygame.K_SPACE]): self.fire() This below is my fire method which is just calling the Handgun (which is my bullet class): def

TypeError: Cannot interpret feed_dict key as Tensor: The name 'save/Const:0' refers to a Tensor which does not exist

一世执手 提交于 2019-12-24 08:47:43
问题 From this file: https://github.com/llSourcell/pong_neural_network_live/blob/master/RL.py I've updated the lines #first convolutional layer. bias vector #creates an empty tensor with all elements set to zero with a shape W_conv1 = tf.Variable(tf.zeros([8, 8, 4, 32]) , name='W_conv1') b_conv1 = tf.Variable(tf.zeros([32]), name='b_conv1') W_conv2 = tf.Variable(tf.zeros([4, 4, 32, 64]), name='W_conv2') b_conv2 = tf.Variable(tf.zeros([64]), name='b_conv2') W_conv3 = tf.Variable(tf.zeros([3, 3, 64,

How do I add enemies in pygame?

匆匆过客 提交于 2019-12-24 08:28:33
问题 I am making a simply game with pygame, and the objective is to dodge the incoming enemies. I want a tie fighter image to come down randomly, and the xwing has to dodge them or you will die. How do I implement random tie fighters into my script? In my code I get an error that says x is not defined. import pygame import time import random pygame.init() display_width = 1280 display_height= 800 pygame.display.set_mode((display_width, display_height), pygame.FULLSCREEN) gameDisplay= pygame.display

Python says pygames has no attribute 'init()' but lib is installed correctly

ぃ、小莉子 提交于 2019-12-24 08:18:21
问题 I'm using Python 2.7 with pygame-1.9.2pre.win32-py2.7.‌exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame I've run this script: import pygame print 'PyGame Version: %s ' % pygame.__version__ to see if my module was installed correctly and I got: PyGame Version: 1.9.2pre As far as I know, it means that pygame is working correctly. In Python IDLE i try to run interactively: import pygame pygame.init() # Set the height and width of the screen size=[700,500] screen=pygame.display.set_mode

Pygame font not working after py2exe

拟墨画扇 提交于 2019-12-24 08:17:44
问题 I have this code that works fine when I convert it to an .exe with py2exe, except when it tries to load text on the screen. It comes up with the error: C:\Users\Slinky\Desktop\dist\FlappyBat.exe:120: RuntimeWarning: use font: DLL load failed: The specified module could not be found. (ImportError: DLL load failed: The specified module could not be found.) Traceback (most recent call last): File "FlappyBat.py", line 176, in <module> File "FlappyBat.py", line 120, in main File "pygame\__init__

Python & Pygame: Can't get out of paused state

馋奶兔 提交于 2019-12-24 08:00:00
问题 I'm new to Python and Pygame and I programmed a little game and tried to implement a pause menu. While I can get to the pause menu I can't get out of it. I followed a tutorial by sentdex and changed the code a bit to my liking. I'm working with Python-Idle but I don't get any error messages there either so I have no idea what I'm doing wrong. import pygame import time import random import shelve pygame.init() display_width = 800 display_height = 600 black = (0,0,0) white = (255,255,255)

How to display text from a pickled .txt file in a pygame window

陌路散爱 提交于 2019-12-24 07:49:16
问题 I have built a game that logs and saves the users score, using pickle, to a text file. When their lives are used up, they enter their name and their name and score are saved to a text file. Currently, if the "High Scores" section is selected on the main menu the high scores are simply printed in the python shell (or CMD if they're using that). I would like to create a separate window for just displaying the high scores. The window would simply display the scores and would refresh every time