Okay so im making a rogue platformer and i want the player to be able to click the J key and it will swing a item then disappear and return back to the original location. This is done by the item rotating 180 degrees around a specific point. This point is determined with my detect pixel function. This finds the first non white pixel of an image in the bottom left, by moving across the x then moving the y down toward the top. Once this pixel is found i then use it to place the image next to the sprite. My question is how can i keep this invisible until the J key is pushed, then it appears and rotates clockwise on the detected pixel 180 degrees. Then this image will disappear and go back to the original position. THANK YOU!
def detect_pixel(item):
global weapon_x
global weapon_y
weapon = PIL.Image.open(item)
width, height = weapon.size
rgb_weapon = weapon.convert('RGB')
weapon = pygame.image.load(item)
got_pixel = False
for y in range(height):
for x in range(width):
r, g, b = rgb_weapon.getpixel((x, height - (y + 1)))
if r == 0 and g == 0 and b == 0:
continue
else:
got_pixel = True
weapon_x = x
weapon_y = height - (y + 1)
break
if got_pixel:
break
return weapon
while running:
screen.fill('White')
draw_floors()
draw_walls()
player.draw()
chort.draw()
#Key/event detection
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
run = False
if event.key == pygame.K_a:
player.moving_left = True
player.idle = False
if event.key == pygame.K_d:
player.moving_right = True
player.idle = False
if event.key == pygame.K_w:
player.moving_up = True
player.idle = False
if event.key == pygame.K_s:
player.moving_down = True
player.idle = False
if event.key == pygame.K_j:
pass
if event.type == pygame.KEYUP:
player.idle = True
player.moving_left = False
player.moving_right = False
player.moving_down = False
player.moving_up = False
screen.blit(weapon, (player.rect.x + player.rect.width - 8 , player.rect.y + (player.rect.height / 2) - weapon_y + 3))
pygame.transform.rotate(weapon, 15)
player.move()
chort.ai_move(player.rect.x, player.rect.y)
pygame.display.flip()
player.update()
chort.update()
clock.tick(12)
pygame.quit