Untitled

 avatar
user_9733620
plain_text
a month ago
3.3 kB
1
Indexable
Never
import pygame #pip install pygame
import pygame.mixer
from pygame.locals import*
import os

from data import config as c
from data import setup
from data.components.button import Button

# Init display
pygame.init()
screen=pygame.display.set_mode((c.WIDTH,c.HEIGHT))
pygame.display.set_caption("Virtual Pet")
# Init font
pygame.font.init()
label_font = pygame.font.Font(os.path.join(setup.FONTS,c.LABEL_FONT),40)
main_font = pygame.font.Font(os.path.join(setup.FONTS,c.MAIN_FONT),30)


class Pet(pygame.sprite.Sprite):
    def __init__(self, name, hunger_level, happiness_level, needs_bathroom):
        self.name = name
        self.hunger_level = hunger_level
        self.happiness_level = happiness_level
        self.needs_bathroom = needs_bathroom

    def get_name(self):
        text = label_font.render("%s" % self.name, True, c.BLACK, 1)
        return text

    def get_hunger(self):
        text = main_font.render('%s' % self.hunger_level, True, c.BLACK, 1)
        return text

    def get_happiness(self):
        text = main_font.render('%s' % self.happiness_level, True, c.BLACK, 1)
        return text

    def get_bathroom_level(self):
        if self.needs_bathroom < 0:
            self.needs_bathroom = 0
            self.has_an_accident()

            self.happiness_level = 0
        text = main_font.render('%s' % self.needs_bathroom, True, c.BLACK, 1)
        return text

    def has_an_accident(self):
        self.happiness_level -= 1

    def feed(self):
        if self.hunger_level < 50:
            self.hunger_level = self.hunger_level + 2
            if self.hunger_level >= 50:
                self.hunger_level = 50

    def play(self):
        if self.happiness_level < 50:
            self.happiness_level = self.happiness_level + 3
            if self.happiness_level >= 50:
                self.happiness_level = 50

    def poop(self):
        if self.needs_bathroom < 50:
            self.needs_bathroom = self.needs_bathroom + 4
            if self.needs_bathroom >= 50:
                self.needs_bathroom = 50

    def reduce_hunger_level(self, by):
        if self.hunger_level > 0:
            self.hunger_level -= by
            if self.hunger_level < 0:
                self.hunger_level = 0

    def reduce_happiness_level(self, by):
        if self.happiness_level > 0:
            self.happiness_level -= by
            if self.happiness_level < 0:
                self.happiness_level = 0

    def reduce_bathroom_need(self, by):
        if self.needs_bathroom > 0:
            self.needs_bathroom -= by
            if self.needs_bathroom < 0:
                self.needs_bathroom = 0

    def display_mood(self):
        text = ''
        if self.hunger_level <= 0:
            text = 'Hungry!'
        elif self.happiness_level <= 0:
            text = 'Bored!'
        elif self.needs_bathroom <= 0:
            text = 'Pooped!'

        text = main_font.render('%s' % text, True, c.BLACK, 1)
        return text

    def get_mood(self):
        if self.hunger_level <= 0 or self.happiness_level <= 0 or self.needs_bathroom <= 0:
            mood = 1
        else:
            mood = 0
        return mood


# def main():


# if __name__ == '__main__':
Leave a Comment