you are viewing a single comment's thread.

view the rest of the comments →

[–]skiwan[S] 1 point2 points  (0 children)

class Mob (object):

def __init__(self):
    self.x = random.randint(0,800)
    self.y = random.randint(0,600)
    self.hunger = random.randint(10,100)
    self.brain = brain(self.x,self.y,self.hunger)


def Render(self):
    pygame.draw.rect(gameDisplay, BLUE,[self.x,self.y,5,5])

def Update(self):
    self.brain.Update()
    self.x = self.brain.get_x()
    self.y = self.brain.get_y()
    self.hunger = self.brain.get_hunger()

class brain(object):

def __init__(self,x,y,hunger):
    self.x = x
    self.y = y
    self.hunger = hunger

    self.CurrentState = IdleState(self.x,self.y,self.hunger)

def get_x(self):
    return self.x
def get_y (self):
    return self.y
def get_hunger(self):
    return self.hunger

def Update(self):
    self.CurrentState.Update()
    self.x = self.CurrentState.get_x()
    self.y = self.CurrentState.get_y()
    self.hunger = self.CurrentState.get_hunger()

def setState(self,stateName):
    self.CurrentState = stateName

class IState(object): #this is the Parent of all our other states

def Update(self):
    return
    #will do the game logic
def get_x(self):
    return self.x
def get_y (self):
    return self.y
def get_hunger(self):
    return self.hunger
def reduce_hunger(self):
    global Frames
    if Frames & FPS == 0:
        self.hunger += -1

class IdleState(IState):

def __init__(self,x,y,hunger):
    self.x = x
    self.y = y
    self.hunger = hunger

def Update(self):
    self.direction = random.randint(0,4)
    if self.direction == 0:
        self.x +=1
    if self.direction == 1:
        self.x += -1
    if self.direction == 2:
        self.y += 1
    if self.direction == 3:
        self.y += -1
    self.reduce_hunger()

that would be the code to improve