Am trying to get neural network (NEAT) to learn and control a game,so far the sprite is controlled using keyboard.
I tried pyautogui
,it did not work.
pygame.event.post
on the other hand can click letters if passed from within Game class, for instance, I set m is for music within the Game class, which it dealt with successfully but not LEFT or RIGHT, because they are from the Player class.
Lastly,I tried some inheritances but that gave me a never ending iteration/loading.
I understand the pygame class is quite complicated, I would like help of any sort on how I can solve the problem.
Here is a sample of my atempt to solve the problem.
class Game(pygame.sprite.Sprite):
def __init__(self, scrn_width,scrn_height,score,..):
super().__init__()
'reponsible for game enviroment'
'inits screen,inits group sprite, keeps increments score'
self.player = Player()
self.enemy = Enemy()
self.player_group.add(self.player)
self.enemy_group.add(self.enemy)
self.score...
def run(self):
pass
class Player(pygame.sprite.Sprite):
def __init__(self, path = r'..\player.png'):
super().__init__(self)
..
self.image = pygame.image.load(path)
self.rect.center = [0,0]
def move(self):
'allows'
class Controller(Player,Game):
def __init__(self):
super().__init__()
def begin(self):
Start_Game._run(self)
if self.score == 1:
pyautogui.press['Left','Left','Left'] #try 1
self.rect.top = 0 #try 2
newevent = pygame.event.Event(pygame.locals.KEYDOWN, key=pygame.locals.K_LEFT) #try 3
pygame.event.post(newevent)
"""
I would like this class to pass coordinates to update player sprite's position
based on information from Game such as score,collision,enemy.
"""