pygame

Pygame: problems with shooting in Space Invaders [duplicate]

為{幸葍}努か 提交于 2021-02-13 17:01:47
问题 This question already has answers here : How can i shoot a bullet with space bar? (1 answer) How do I stop more than 1 bullet firing at once? (1 answer) Closed 26 days ago . I've been attempting to make a Space Invaders clone in pygame. I decided to write it so that the bullet shot from the player's ship can only be fired again when it leaves the screen but I've not been capable of doing so. How do I do it? import pygame pygame.init() screen_size = (500, 500) ship_size = (50, 50) x, y = 250,

How can I make the ball move instead of stretch in pygame?

雨燕双飞 提交于 2021-02-13 05:42:25
问题 I'm building a pong game trying to get better at programming but Im having trouble moving the ball. When the move_right method is called the ellipse stretches to the right instead of moving to the right. I've tried putting the ball variable in the init method but that just makes it not move at all even though the variables should be changing on account of the move_right method. I have also tried setting the x and y positions as parameters in the Ball class,but that just stretches it also. I

How to rotate a triangle to a certain angle in pygame?

让人想犯罪 __ 提交于 2021-02-13 05:42:18
问题 I need to rotate a triangle (Not an image) around at the center of the screen. I have seen other people answer this question, but the triangle could not point upwards. I have tried to use other peoples functions, but they see to only work partly, like the function I mentioned above. import pygame disp=pygame.display.set_mode((200,200)) import math def rotate_triange(mouse_pos,triangle_pos): #The code here import time while True: time.sleep(1) pygame.Surface.fill(disp,(255,255,255)) center =

How to rotate a triangle to a certain angle in pygame?

╄→尐↘猪︶ㄣ 提交于 2021-02-13 05:42:02
问题 I need to rotate a triangle (Not an image) around at the center of the screen. I have seen other people answer this question, but the triangle could not point upwards. I have tried to use other peoples functions, but they see to only work partly, like the function I mentioned above. import pygame disp=pygame.display.set_mode((200,200)) import math def rotate_triange(mouse_pos,triangle_pos): #The code here import time while True: time.sleep(1) pygame.Surface.fill(disp,(255,255,255)) center =

How to rotate a triangle to a certain angle in pygame?

你离开我真会死。 提交于 2021-02-13 05:41:47
问题 I need to rotate a triangle (Not an image) around at the center of the screen. I have seen other people answer this question, but the triangle could not point upwards. I have tried to use other peoples functions, but they see to only work partly, like the function I mentioned above. import pygame disp=pygame.display.set_mode((200,200)) import math def rotate_triange(mouse_pos,triangle_pos): #The code here import time while True: time.sleep(1) pygame.Surface.fill(disp,(255,255,255)) center =

Is there a way to place number on the center of the screen in pygame?

走远了吗. 提交于 2021-02-13 05:41:25
问题 I am working with pygame, to display the score I have images from 0 to 9 and need to place them centralized, but i can't just put it in the middle because the size of the score can change, the only solution I found until now is to hardcode it for scores up to 9, then up to 99 etc like in the code below if len(str(self.value)) == 1: win.blit(self.imgs[self.value], ((x - self.imgs[self.value].get_width(), y))) elif len(str(self.value)) == 2: win.blit(self.imgs[int(str(self.value)[0])], (x -

How to make instances spawn automatically around the player?

 ̄綄美尐妖づ 提交于 2021-02-13 05:29:20
问题 So I want to have the Zombies spawn around the player (the number of Zombies should increase as time passes). Since I don't want the player to die instantly I need the Zombies to spawn away from the player at a certain distance but other than that a random location. import pygame import turtle import time import math import random import sys import os pygame.init() WHITE = (255,255,255) GREEN = (0,255,0) RED = (255,0,0) BLUE = (0,0,255) BLACK = (0,0,0) BGColor = (96,128,56) ZColor = (221,194

How to make an imported module blit onto a surface from the main script?

久未见 提交于 2021-02-12 11:44:27
问题 In my main file I have a surface called win . I import a module like so from draw import * . def draw(image,x,y): win.blit(image,(x,y)) This is a function from draw . It doesn't work because win is not defined. How to make it defined? 回答1: Add an additional parameter for the target surface to the function: def draw(target, image, x, y): target.blit(image, (x, y)) Pass win to the draw function: draw(win, image, x, y) Alternatively, you can create a variable in the module's global namespace:

Moving forward after angle change. Pygame

吃可爱长大的小学妹 提交于 2021-02-12 11:41:25
问题 I've been working on this project about tanks (based on game Tank Trouble) and I'm wondering how I can move forward after I change angle of the sprite. Also if you know how I can make my bullets ricochet from the walls. I will really appreciate any help given. Thank you! Here is my tank and bullet: Here is code of the game: import sys import pygame class Game: def __init__(self): self.run = True self.screen_width = 1060 self.screen_height = 798 self.image = pygame.image.load("sprites

How to make an imported module blit onto a surface from the main script?

女生的网名这么多〃 提交于 2021-02-12 11:40:29
问题 In my main file I have a surface called win . I import a module like so from draw import * . def draw(image,x,y): win.blit(image,(x,y)) This is a function from draw . It doesn't work because win is not defined. How to make it defined? 回答1: Add an additional parameter for the target surface to the function: def draw(target, image, x, y): target.blit(image, (x, y)) Pass win to the draw function: draw(win, image, x, y) Alternatively, you can create a variable in the module's global namespace: