Ich versuche grade mit Python ein Netzwerk basierendes Agario zu programmieren. Ich möchte für meinen Player (Also ein circle) die Maus Position benutzen, damit er sich bewegen kann. Ich frage die Position von der Maus ab, und benutze diesen beim Player:
Code: Alles auswählen
Mouse_x, Mouse_y = pygame.mouse.get_pos()
pPos = (Mouse_x, Mouse_y)
drawPlayer(pPos)
Die Funktion drawPlayer:
Code: Alles auswählen
def drawPlayer(playerPosition):
pygame.draw.circle(screen, (0, 0, 255), playerPosition, 20)
Zum genaueren Verstehen: Hier mein kompletter code:
Code: Alles auswählen
#Online Agario
import pygame
(width, height) = (400, 400)
screen = pygame.display.set_mode((width, height))
pygame.display.flip()
pygame.display.set_caption("Agario Online")
screen.fill((0, 255, 255))
programmOpen = True
#Feind
#Öffnet x.txt als temporäre Variable und tut diese dann in "px"
tfy = open("y.txt", "r")
for line in tfy:
fy = line
tfy.close()
#Öffnet x.txt als temporäre Variable und tut diese dann in "px"
tfx = open("x.txt", "r")
for line in tfx:
fx = line
tfx.close()
#Player Position
fPos = (int(fx), int(fy))
def drawGegner(gegnerPosition):
pygame.draw.circle(screen, (255, 0, 0), gegnerPosition, 20)
def drawPlayer(playerPosition):
pygame.draw.circle(screen, (0, 0, 255), playerPosition, 20)
while programmOpen:
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
programmOpen = False
pygame.quit()
drawGegner(fPos)
Mouse_x, Mouse_y = pygame.mouse.get_pos()
pPos = (Mouse_x, Mouse_y)
drawPlayer(pPos)