pygame

How can i make a block follow another block in pygame [duplicate]

余生长醉 提交于 2021-02-13 17:32:59
问题 This question already has answers here : How to make smooth movement in pygame (2 answers) Closed 4 months ago . I have two blocks, one is controlled by the user. When i move my block, i want the other block to follow me. I tried doing something like this def follow(): distance = math.hypot(abs(m.x - p.x), abs(m.y - p.y)) angle_radians = math.atan2(abs(m.y - p.y), abs(m.x - p.x)) if distance != 0: p.y += math.sin(angle_radians) p.x += math.cos(angle_radians) However, the block ends up moving

How do i properly rescale an image on PyGame without it being badly cropped?

我怕爱的太早我们不能终老 提交于 2021-02-13 17:31:49
问题 I'm trying to rescale an image on pygame but it instead crops the image, I'm just looking to change the pixel width and height of the image. I used pygame.transform.scale and used 1900, 600 as the parameters, the original image is a 1920x1080 mainmenu = pygame.image.load("Main_Menu.png") mainmenu = pygame.transform.scale(mainmenu, (1900,600)) screen.blit(background, (0, 0)) I expected the image to be rescaled to a 1900x600 image but it instead output a badly cropped image in the 1900x600

Scale Everything On Pygame Display Surface

孤街浪徒 提交于 2021-02-13 17:31:15
问题 So I'm making a 2D pixel art game in pygame and as you could assume, all my sprite textures appear very small. I'm wondering if there's a way I can globally scale everything up in my game without either having to scale each sprite up individually or messing up the coordinates. Every sprite will move on a grid: one unit is 16x16 pixels and when my player sprite moves, for example, it will just move over in a direction 16 pixels. Here's my main script: import sys from pygame.locals import *

Is there a better way to spawn enemy locations?

狂风中的少年 提交于 2021-02-13 17:31:15
问题 I'm making a pygame, survive the hord type game. I have it set up to where enemy's will walk towards the player. If they hit the player, they take some of his health. if the player shoots them, they die/disappear, and the player gets a point or two. I want the enemy's to all spawn off screen within a certain distance, and then walk onto screen so that you don't start the game with enemy's 5 pixels away, or on top of you. I thought of trying to create an if statement, that only adds the enemy

How do i properly rescale an image on PyGame without it being badly cropped?

ぃ、小莉子 提交于 2021-02-13 17:31:11
问题 I'm trying to rescale an image on pygame but it instead crops the image, I'm just looking to change the pixel width and height of the image. I used pygame.transform.scale and used 1900, 600 as the parameters, the original image is a 1920x1080 mainmenu = pygame.image.load("Main_Menu.png") mainmenu = pygame.transform.scale(mainmenu, (1900,600)) screen.blit(background, (0, 0)) I expected the image to be rescaled to a 1900x600 image but it instead output a badly cropped image in the 1900x600

Is there a better way to spawn enemy locations?

放肆的年华 提交于 2021-02-13 17:31:11
问题 I'm making a pygame, survive the hord type game. I have it set up to where enemy's will walk towards the player. If they hit the player, they take some of his health. if the player shoots them, they die/disappear, and the player gets a point or two. I want the enemy's to all spawn off screen within a certain distance, and then walk onto screen so that you don't start the game with enemy's 5 pixels away, or on top of you. I thought of trying to create an if statement, that only adds the enemy

Pygame Enemys Wont Move Down - Tower Defense Game

女生的网名这么多〃 提交于 2021-02-13 17:30:01
问题 my problem here is that for my last 2 check points for my enemy for my tower defense game the enemys wont move down for the second last go untile they damage the tower video they just move forward idk why they just move out from there its the same for the last one to # move the enemy for spider in spiders: if spider.x < 230: spider.x += spider.speed elif spider.y < 160: spider.x += spider.speed elif spider.x > 540: spider.y -= spider.speed elif spider.y < 566: spider.y += spider.speed elif

How do I change the Pygame coordinate system so that the center of the window is (0,0)?

杀马特。学长 韩版系。学妹 提交于 2021-02-13 17:27:58
问题 I want to change pygame coordinate system so that the center of the window is (0,0) and has negative values as in the image. Is there a possible way to convert the coordinates? https://i.stack.imgur.com/sGPFt.gif 回答1: PyGame uses a coordinate system where the top left corner is (0,0). That cannot be changed. If you want to move the origin of the coordinate system to the center of the screen, then you have to translate the coordinates by yourself. For instance write a function that translates

Pygame Enemys Wont Move Down - Tower Defense Game

£可爱£侵袭症+ 提交于 2021-02-13 17:27:06
问题 my problem here is that for my last 2 check points for my enemy for my tower defense game the enemys wont move down for the second last go untile they damage the tower video they just move forward idk why they just move out from there its the same for the last one to # move the enemy for spider in spiders: if spider.x < 230: spider.x += spider.speed elif spider.y < 160: spider.x += spider.speed elif spider.x > 540: spider.y -= spider.speed elif spider.y < 566: spider.y += spider.speed elif

Pygame: problems with shooting in Space Invaders [duplicate]

混江龙づ霸主 提交于 2021-02-13 17:03:14
问题 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,