Exemple #1
0
    def __init__(self, l, w, a, b, c, d, name):
        '''
        '''

        Player.__init__(self, l, w, a, b, c, d, name)
        # This retrieves each of the attribute values from the board class
        self.l = l
        self.w = w
        self.num_battleships = a
        self.num_cruisers = b
        self.num_frigates = c
        self.num_minesweepers = d
        self.name = name

        # A list of the boat's coordinates
        self.coordinates = []

        # A list of the coordinates for each random hit
        self.hitlist = []

        # A list of the opponents coordinates for the ships
        self.opp_list = []
Exemple #2
0
    def __init__(self):
        '''game constructor: create attributes, start game'''

        #initialize sprite lists
        self.all_sprites_list = pygame.sprite.Group()

        #initialize room list
        self.room_list = []
        self.room_list.append(rooms.Home())
        self.room_list.append(rooms.InsideHome())
        self.room_list.append(rooms.Beach())

        #spawn in this room
        self.current_room = self.room_list[1]

        #make a player sprite
        self.player = Player()
        self.all_sprites_list.add(self.player)
import pyxel
import random
import initialization
from ballclass import Ball
from playerclass import Player
from missileclass import Missile

pyxel.init(256, 256)
initialization.initialize()

counter = 0
player = Player()
balls = []
state = 'GAMEOVER'
hiscore = 0
missiles = []


def update():
    global state
    if state == 'GAMEOVER':
        if pyxel.btn(pyxel.KEY_ENTER):
            start_game()
            state = 'PLAYING'
    else:
        update_playing()


def start_game():
    global counter, balls, player
    counter = 0
    def __init__(self):
    # this is super long omg
    # Bye Style Points...
    # but seriously though. its bad
        BHMode.init()

        self.triedToGoHome = False

        self.hasRained = False
        self.isRaining = False
        self.rain_thresh = 4000
        self.rainCount = 0
        self.max_rainCount = 60 * 60
        self.raindrops = pygame.sprite.Group()
        Raindrop.init()

        self.inBH = False
        self.BH = None
        self.BH1 = BHMode()
        #self.BH1.completed = True #!!
        self.BH2 = BHMode2()
        #self.BH2.completed = True #!!
        self.BH3 = BHMode3()
        #self.BH3.completed = True #!!
        # these comments were for testing purposes

        self.completed = False
        self.ending_thresh = 5980

        self.worldX = 0
        self.worldX_dx = 0
        self.max_worldX = 5400
        
        self.textbox = pygame.sprite.Group()
        self.textbox.add(Textbox())

        self.player = Player()
        self.playerList = pygame.sprite.Group()
        self.playerList.add(self.player)

        # add signs
        sign1 = Sign(300, ["\"Hello, I am a sign.\"",
                           "\"Here is some important information:\"",
                           "\"West: Residential area.\"",
                           "\"East: Shopping district.\"",
                           "\"I hope you found this helpful.\""])
        sign2 = Sign(550, ["(There is a sticky note on this sign.)",
                            "\"Dear Star Town citizens:\"",
                            "\"It's me! Your mayor.\"",
                            "\"Please join me in welcoming our new residents...\"",
                            "\"Tomorrow.\"",
                            "\"I don't want to miss the supermarket sale today!\""])
        sign3 = Sign(1200, ["\"It's not 'trash CAN'T '...\"",
                            "\"It's 'trash CAN' !!\"",
                            "\"So, even if you are feeling like trash...\"",
                            "\"Please, keep doing your best!!\"",
                            "\"--Sincerely, a trash enthusiast.\""])
                            # (im the trash enthusiast) 
        sign4 = Sign(2100, ["(It seems like someone has defaced this sign...)",
                            "(Now there is a picture of a cat on it.)",
                            "\"WANTED: cat who keeps eating my food\"",
                            "\"Whoever you are, please stop...\""])
        sign5 = Sign(2710, ["\"Space enthusiast meeting --\"",
                            "\"Next Tuesday at 7pm.\"",
                            "\"BYOS (Bring Your Own Spaceship).\""])
        sign6 = Sign(3400, ["\"Star Town Tree:\"",
                            "\"This tree was planted to commemorate\"",
                            "\"the founding of our town.\"",
                            "\"The tree supports our citizens in many ways,\"",
                            "\"so please continue to support Star Town.\""])
        sign7 = Sign(4900, ["\"Warning: dog.\"",
                            "\"Very fluffy.\""])
        sign8 = Sign(5850, ["\"Supermarket -- just over to the right!\"",
                            "\"Don't miss all our PRICES and SELECTIONS.\""])
        self.signs = pygame.sprite.Group()
        self.signs.add(sign1, sign2, sign3, sign4, sign5, sign6, sign7, sign8)

        # add heal pts
        trash = HealPoint(rectY=180, worldX=1000, healthPts=10, 
            imageName="trash-chan.png", textDict=
            {False:["(It's a trash can.)",
                    "(You find a burger in the trash.)",
                    "(You eat the burger and recover some HEALTH.)",
                    "(How disgusting...)"],
            True:["(You ate the trash...)",
                  "(The trash is inside of you...)",
                  "(You feel like a trash can.)"]})

        tallPerson = HealPoint(rectY=0, worldX=2300, healthPts=30,
            imageName="tall.png", textDict=
            {False:["(It's an extremely tall individual.)",
                    "(For some reason, you feel very safe here.)",
                    "(You rest underneath the individual for a while...)",
                    "(Hopefully they didn't mind.)",
                    "(You recover some HEALTH.)"],
            True:["(This individual is so tall,",
                  "that you can't see beyond their legs.)",
                  "(But, at least they have great footwear.)"]})

        tree = HealPoint(rectY=0, worldX=3500, healthPts=30, 
            imageName="tree.png", textDict=
            {False:["(It's a great big tree.)",
                    "(You stop and take a break under it.)",
                    "(Suddenly, a piece of fruit falls in front of you!)",
                    "(You eat the fruit and regain some HEALTH.)",
                    "(Somewhere in the distance...)",
                    "(You sense that someone is greatly offended by this.)"],
            True:["(You stay under the tree for a little while.)",
                  "(You feel so refreshed! Mentally, that is.)"]})

        busStop = HealPoint(rectY=110, worldX=5500, healthPts=30,
            imageName="bus_stop.png", textDict=
            {False:["(It's a bus stop.)",
                    "(You haven't seen the bus all day...)",
                    "(But...)",
                    "(You're sure the bus is trying its best!!)",
                    "(Thinking of the bus increases your HEALTH.)"],
            True:["(You keep thinking about the bus...)",
                  "(But nothing else happens. Aw.)"]})

        self.healPoints = pygame.sprite.Group()
        self.healPoints.add(trash, tallPerson, tree, busStop)
      
        # add npc's
        egg = NPC(rectY=305, worldX=800, imageName="egg.png", 
            textDictM = {False:["\"Oh...hello...\"",
                                "\"I was just enjoying this nice sunlight.\"", 
                                "\"I'll get out of the way.\""]},
            textDictD={False: ["\"Do you see that trash can over there?\"",
                               "\"I saw someone throw something away",
                               "a few minutes ago.\"",
                               "\"Maybe you should check it out.\""],
                       True: ["\"The ground is all warm from the sun...\"",
                              "\"By the way, did you find anything in the trash?\""]})
        egg.hasBH = False

        toast = NPC(rectY=250, worldX=1500, imageName="toast.png", 
            textDictM = {False:["\"Hello, new neighbor!\"",
                                "\"You look hungry!\"", 
                                "\"Did you eat breakfast today?\"",
                                "\"It's important to have a balanced breakfast.\"",
                                "\"Let me help you out.\"",
                                "\"Please take the breakfast items",
                                "that I am about to throw at you.\"",
                                "\"Run into them as hard as you can, ok??\"",
                                "\"I'm sure your HEALTH will improve in no time.\"",
                                "\"Of course, it's totally safe.\"",
                                "\"There is no way this can hurt you.\"",
                                "(...)",
                                "(You hear a voice from above again...)",
                                "('Hey! Listen up!')",
                                "('Move around with the ARROW KEYS.')",
                                "('Try to dodge the projectiles!')",
                                "('If your HEART gets hit, you will lose HEALTH.')",
                                "('Hold down 'Z' to cry...')",
                                "('You will shoot tears at your opponent.')",
                                "('Crying will damage them...emotionally')",
                                "('They will leave you alone if they have low HP,)",
                                "('or if they run out of projectiles.')",
                                "('Hold down LEFT SHIFT to focus.')",
                                "('If you concentrate, you can slow your movements.')",
                                "('You will also cry harder.')",
                                "('Press 'X' to do something exciting.')",
                                "('If you distract your neighbor,')",
                                "('you can make them stop shooting momentarily.')",
                                "('You will also scare away the projectiles.')",
                                "('Finally, press 'P' to stop time.')",
                                "('It's fine to take a break.')",
                                "('OK, that's it! I hope you were paying attention!')",
                                "(...You carefully remember those instructions!)",
                                "(...)",
                                "\"Are you ready?\"",
                                "\"Here we go!\""]},
            textDictD={False: ["\"You didn't eat anything...\"",
                               "\"Do you not like food items...",
                               "...being hurled at you at high velocities?\"",
                               "\"Well...whatever works for you, I guess.\""],
                       True: ["\"Are you headed to the supermarket?\"",
                              "\"It's all the way to your right.\"",
                              "\"You can go buy some fruits there...\"",
                              "\"Even though, I gave some to you for free.\""]})
        toast.hasBH = True

        raindrop = NPC(rectY=255, worldX=1800, imageName="raindrop.png",
            textDictM = {False: ["\"Ah...I wish it was raining.\"",
                                 "\"I love the rain. It's my element.\"",
                                 "\"But I guess this weather is OK too.\"",
                                 "\"...Oh, am I in your way?\"",
                                 "\"I'll go stand a little bit to my right.\""]},
            textDictD= {False: ["\"Sometimes the weather here gets really bad.\"",
                                "\"It'll rain so hard that, if the rain hits you...\"",
                                "\"You might even lose some HEALTH!\"",
                                "\"If you wanted to go anywhere...\"",
                                "\"You would have to dodge all the rain!!\"",
                                "\"Doesn't that sound fun? Haha.\"",
                                "\"Don't worry, though.\"",
                                "\"It won't happen to you today.\"",
                                "\"It might rain a little bit, but,\"",
                                "\"a slight drizzle won't hurt you.\""],
                        True: ["\"It's good to stock up on food at home.\"",
                               "\"That way you won't have to go outside",
                               "when there's bad weather.\"",
                               "\"...\"",
                               "\"What do you mean, you never go outside anyway??\""]})
        raindrop.hasBH = False

        ufo = NPC(rectY=220, worldX=2900, imageName="ufo.png",
            textDictM = {False: ["\"...\"",
                                 "\".....\"",
                                 "\"....!\"",
                                 "\"! ! !\""]},
            textDictD= {False: ["\"Oh no...I'm sorry, are you hurt?\"",
                                "\"I was just so excited about space.\"",
                                "\"I just moved here from space, you see.\"",
                                "\"I wanted to show everyone here",
                                "how cool and pretty my home was...\"",
                                "\"So I bought a bunch of plastic stars...\"",
                                "\"But now they're all over the ground.\"",
                                "\"...whoops...\""],
                        True: ["\"...\"",
                               "\"......\"",
                               "\"...zzz...\"",
                               "(You look more closely at the UFO...)",
                               "(Oh! There is a very small cat inside.)",
                               "(The cat is taking a nap!)",
                               "(It must be nice and cozy in there.)"]})
        ufo.hasBH = True

        cat = NPC(rectY=210, worldX=3850, imageName="cat.png",
            textDictM= {False: ["\"Someone keeps eating all my Frisky Bitz.\"",
                                "\"It's not you, is it??\"",
                                "\"...\"",
                                "\"You don't look like a cat, so...\"",
                                "\"I guess it's someone else.\"",
                                "\"I mean, they pay me back for it, but still!\"",
                                "\"Now I have to go buy more all the time.\"",
                                "\"Sigh...\""]},
            textDictD= {False: ["\"...Have you noticed all the stuff on the ground?\"",
                                "\"Those star-shaped rocks...\"",
                                "\"No one knows where they came from.\"",
                                "\"Except maybe the mayor.\"",
                                "\"I've never seen them before, but...\"",
                                "\"Sometimes you'll hear their voice from above.\"",
                                "\"So, has the mayor said anything to you yet?\"",
                                "(...You hear something from above...)",
                                "('...*coughing noises*...')",
                                "('...Sorry, I choked on a chip.')",
                                "('Did you need something?')",
                                "(...no thanks...you're good...)"],
                        True:  ["\"I'll be waiting here until I run into",
                                "whoever keeps eating my food.\"",
                                "\"You should go on ahead!\"",
                                "\"The shopping district is not so far ahead.\""]})
        cat.hasBH = False

        dog = NPC(rectY=210, worldX=5200, imageName="dog.png",
            textDictM= {False: ["\"Woof!\"",
                                "\"Don't come any closer!\"",
                                "\"I decided to dig up all my chew toys.\"",
                                "\"But now I have too many...\"",
                                "\"I can't hold on to all of them...\"",
                                "\"...Oh no...\"",
                                "\"Oh no oh no oh no\"",
                                "\"Now they're dropping all over the place.\"",
                                "\"You'd better get out of the way!!\""]},
            textDictD= {False: ["\"Bark bark!\"",
                                "\"Are you ok??\"",
                                "\"I didn't mean for that to happen...\"",
                                "\"Oh no...\"",
                                "(The dog looks sad...)",
                                "(You reach out to pet the dog.)",
                                "(The dog is so fluffy and nice...)",
                                "(After being pet, the dog looks happy again!)"],
                        True:  ["(You pet the dog again.)",
                                "(The dog is so happy!!)",
                                "(Petting the dog makes you feel happy too.)"]})
        dog.hasBH = True

        self.NPCs = pygame.sprite.Group()
        self.NPCs.add(egg, toast, raindrop, ufo, cat, dog)

        self.currentSign = None
        self.currentHP = None
        self.currentNPC = None

        self.bg_ground = pygame.image.load("ground.png").convert_alpha()
        self.bg_bush = pygame.image.load("bushes.png").convert_alpha()
        self.bg_sky = pygame.image.load("sky.png").convert_alpha()
        self.bg_sun = pygame.image.load("sunlight.png").convert_alpha()
        self.bg_sun = pygame.transform.flip(self.bg_sun, True, False)
class RPG(object):
    ARROWKEYS = {pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN}
    def __init__(self):
    # this is super long omg
    # Bye Style Points...
    # but seriously though. its bad
        BHMode.init()

        self.triedToGoHome = False

        self.hasRained = False
        self.isRaining = False
        self.rain_thresh = 4000
        self.rainCount = 0
        self.max_rainCount = 60 * 60
        self.raindrops = pygame.sprite.Group()
        Raindrop.init()

        self.inBH = False
        self.BH = None
        self.BH1 = BHMode()
        #self.BH1.completed = True #!!
        self.BH2 = BHMode2()
        #self.BH2.completed = True #!!
        self.BH3 = BHMode3()
        #self.BH3.completed = True #!!
        # these comments were for testing purposes

        self.completed = False
        self.ending_thresh = 5980

        self.worldX = 0
        self.worldX_dx = 0
        self.max_worldX = 5400
        
        self.textbox = pygame.sprite.Group()
        self.textbox.add(Textbox())

        self.player = Player()
        self.playerList = pygame.sprite.Group()
        self.playerList.add(self.player)

        # add signs
        sign1 = Sign(300, ["\"Hello, I am a sign.\"",
                           "\"Here is some important information:\"",
                           "\"West: Residential area.\"",
                           "\"East: Shopping district.\"",
                           "\"I hope you found this helpful.\""])
        sign2 = Sign(550, ["(There is a sticky note on this sign.)",
                            "\"Dear Star Town citizens:\"",
                            "\"It's me! Your mayor.\"",
                            "\"Please join me in welcoming our new residents...\"",
                            "\"Tomorrow.\"",
                            "\"I don't want to miss the supermarket sale today!\""])
        sign3 = Sign(1200, ["\"It's not 'trash CAN'T '...\"",
                            "\"It's 'trash CAN' !!\"",
                            "\"So, even if you are feeling like trash...\"",
                            "\"Please, keep doing your best!!\"",
                            "\"--Sincerely, a trash enthusiast.\""])
                            # (im the trash enthusiast) 
        sign4 = Sign(2100, ["(It seems like someone has defaced this sign...)",
                            "(Now there is a picture of a cat on it.)",
                            "\"WANTED: cat who keeps eating my food\"",
                            "\"Whoever you are, please stop...\""])
        sign5 = Sign(2710, ["\"Space enthusiast meeting --\"",
                            "\"Next Tuesday at 7pm.\"",
                            "\"BYOS (Bring Your Own Spaceship).\""])
        sign6 = Sign(3400, ["\"Star Town Tree:\"",
                            "\"This tree was planted to commemorate\"",
                            "\"the founding of our town.\"",
                            "\"The tree supports our citizens in many ways,\"",
                            "\"so please continue to support Star Town.\""])
        sign7 = Sign(4900, ["\"Warning: dog.\"",
                            "\"Very fluffy.\""])
        sign8 = Sign(5850, ["\"Supermarket -- just over to the right!\"",
                            "\"Don't miss all our PRICES and SELECTIONS.\""])
        self.signs = pygame.sprite.Group()
        self.signs.add(sign1, sign2, sign3, sign4, sign5, sign6, sign7, sign8)

        # add heal pts
        trash = HealPoint(rectY=180, worldX=1000, healthPts=10, 
            imageName="trash-chan.png", textDict=
            {False:["(It's a trash can.)",
                    "(You find a burger in the trash.)",
                    "(You eat the burger and recover some HEALTH.)",
                    "(How disgusting...)"],
            True:["(You ate the trash...)",
                  "(The trash is inside of you...)",
                  "(You feel like a trash can.)"]})

        tallPerson = HealPoint(rectY=0, worldX=2300, healthPts=30,
            imageName="tall.png", textDict=
            {False:["(It's an extremely tall individual.)",
                    "(For some reason, you feel very safe here.)",
                    "(You rest underneath the individual for a while...)",
                    "(Hopefully they didn't mind.)",
                    "(You recover some HEALTH.)"],
            True:["(This individual is so tall,",
                  "that you can't see beyond their legs.)",
                  "(But, at least they have great footwear.)"]})

        tree = HealPoint(rectY=0, worldX=3500, healthPts=30, 
            imageName="tree.png", textDict=
            {False:["(It's a great big tree.)",
                    "(You stop and take a break under it.)",
                    "(Suddenly, a piece of fruit falls in front of you!)",
                    "(You eat the fruit and regain some HEALTH.)",
                    "(Somewhere in the distance...)",
                    "(You sense that someone is greatly offended by this.)"],
            True:["(You stay under the tree for a little while.)",
                  "(You feel so refreshed! Mentally, that is.)"]})

        busStop = HealPoint(rectY=110, worldX=5500, healthPts=30,
            imageName="bus_stop.png", textDict=
            {False:["(It's a bus stop.)",
                    "(You haven't seen the bus all day...)",
                    "(But...)",
                    "(You're sure the bus is trying its best!!)",
                    "(Thinking of the bus increases your HEALTH.)"],
            True:["(You keep thinking about the bus...)",
                  "(But nothing else happens. Aw.)"]})

        self.healPoints = pygame.sprite.Group()
        self.healPoints.add(trash, tallPerson, tree, busStop)
      
        # add npc's
        egg = NPC(rectY=305, worldX=800, imageName="egg.png", 
            textDictM = {False:["\"Oh...hello...\"",
                                "\"I was just enjoying this nice sunlight.\"", 
                                "\"I'll get out of the way.\""]},
            textDictD={False: ["\"Do you see that trash can over there?\"",
                               "\"I saw someone throw something away",
                               "a few minutes ago.\"",
                               "\"Maybe you should check it out.\""],
                       True: ["\"The ground is all warm from the sun...\"",
                              "\"By the way, did you find anything in the trash?\""]})
        egg.hasBH = False

        toast = NPC(rectY=250, worldX=1500, imageName="toast.png", 
            textDictM = {False:["\"Hello, new neighbor!\"",
                                "\"You look hungry!\"", 
                                "\"Did you eat breakfast today?\"",
                                "\"It's important to have a balanced breakfast.\"",
                                "\"Let me help you out.\"",
                                "\"Please take the breakfast items",
                                "that I am about to throw at you.\"",
                                "\"Run into them as hard as you can, ok??\"",
                                "\"I'm sure your HEALTH will improve in no time.\"",
                                "\"Of course, it's totally safe.\"",
                                "\"There is no way this can hurt you.\"",
                                "(...)",
                                "(You hear a voice from above again...)",
                                "('Hey! Listen up!')",
                                "('Move around with the ARROW KEYS.')",
                                "('Try to dodge the projectiles!')",
                                "('If your HEART gets hit, you will lose HEALTH.')",
                                "('Hold down 'Z' to cry...')",
                                "('You will shoot tears at your opponent.')",
                                "('Crying will damage them...emotionally')",
                                "('They will leave you alone if they have low HP,)",
                                "('or if they run out of projectiles.')",
                                "('Hold down LEFT SHIFT to focus.')",
                                "('If you concentrate, you can slow your movements.')",
                                "('You will also cry harder.')",
                                "('Press 'X' to do something exciting.')",
                                "('If you distract your neighbor,')",
                                "('you can make them stop shooting momentarily.')",
                                "('You will also scare away the projectiles.')",
                                "('Finally, press 'P' to stop time.')",
                                "('It's fine to take a break.')",
                                "('OK, that's it! I hope you were paying attention!')",
                                "(...You carefully remember those instructions!)",
                                "(...)",
                                "\"Are you ready?\"",
                                "\"Here we go!\""]},
            textDictD={False: ["\"You didn't eat anything...\"",
                               "\"Do you not like food items...",
                               "...being hurled at you at high velocities?\"",
                               "\"Well...whatever works for you, I guess.\""],
                       True: ["\"Are you headed to the supermarket?\"",
                              "\"It's all the way to your right.\"",
                              "\"You can go buy some fruits there...\"",
                              "\"Even though, I gave some to you for free.\""]})
        toast.hasBH = True

        raindrop = NPC(rectY=255, worldX=1800, imageName="raindrop.png",
            textDictM = {False: ["\"Ah...I wish it was raining.\"",
                                 "\"I love the rain. It's my element.\"",
                                 "\"But I guess this weather is OK too.\"",
                                 "\"...Oh, am I in your way?\"",
                                 "\"I'll go stand a little bit to my right.\""]},
            textDictD= {False: ["\"Sometimes the weather here gets really bad.\"",
                                "\"It'll rain so hard that, if the rain hits you...\"",
                                "\"You might even lose some HEALTH!\"",
                                "\"If you wanted to go anywhere...\"",
                                "\"You would have to dodge all the rain!!\"",
                                "\"Doesn't that sound fun? Haha.\"",
                                "\"Don't worry, though.\"",
                                "\"It won't happen to you today.\"",
                                "\"It might rain a little bit, but,\"",
                                "\"a slight drizzle won't hurt you.\""],
                        True: ["\"It's good to stock up on food at home.\"",
                               "\"That way you won't have to go outside",
                               "when there's bad weather.\"",
                               "\"...\"",
                               "\"What do you mean, you never go outside anyway??\""]})
        raindrop.hasBH = False

        ufo = NPC(rectY=220, worldX=2900, imageName="ufo.png",
            textDictM = {False: ["\"...\"",
                                 "\".....\"",
                                 "\"....!\"",
                                 "\"! ! !\""]},
            textDictD= {False: ["\"Oh no...I'm sorry, are you hurt?\"",
                                "\"I was just so excited about space.\"",
                                "\"I just moved here from space, you see.\"",
                                "\"I wanted to show everyone here",
                                "how cool and pretty my home was...\"",
                                "\"So I bought a bunch of plastic stars...\"",
                                "\"But now they're all over the ground.\"",
                                "\"...whoops...\""],
                        True: ["\"...\"",
                               "\"......\"",
                               "\"...zzz...\"",
                               "(You look more closely at the UFO...)",
                               "(Oh! There is a very small cat inside.)",
                               "(The cat is taking a nap!)",
                               "(It must be nice and cozy in there.)"]})
        ufo.hasBH = True

        cat = NPC(rectY=210, worldX=3850, imageName="cat.png",
            textDictM= {False: ["\"Someone keeps eating all my Frisky Bitz.\"",
                                "\"It's not you, is it??\"",
                                "\"...\"",
                                "\"You don't look like a cat, so...\"",
                                "\"I guess it's someone else.\"",
                                "\"I mean, they pay me back for it, but still!\"",
                                "\"Now I have to go buy more all the time.\"",
                                "\"Sigh...\""]},
            textDictD= {False: ["\"...Have you noticed all the stuff on the ground?\"",
                                "\"Those star-shaped rocks...\"",
                                "\"No one knows where they came from.\"",
                                "\"Except maybe the mayor.\"",
                                "\"I've never seen them before, but...\"",
                                "\"Sometimes you'll hear their voice from above.\"",
                                "\"So, has the mayor said anything to you yet?\"",
                                "(...You hear something from above...)",
                                "('...*coughing noises*...')",
                                "('...Sorry, I choked on a chip.')",
                                "('Did you need something?')",
                                "(...no thanks...you're good...)"],
                        True:  ["\"I'll be waiting here until I run into",
                                "whoever keeps eating my food.\"",
                                "\"You should go on ahead!\"",
                                "\"The shopping district is not so far ahead.\""]})
        cat.hasBH = False

        dog = NPC(rectY=210, worldX=5200, imageName="dog.png",
            textDictM= {False: ["\"Woof!\"",
                                "\"Don't come any closer!\"",
                                "\"I decided to dig up all my chew toys.\"",
                                "\"But now I have too many...\"",
                                "\"I can't hold on to all of them...\"",
                                "\"...Oh no...\"",
                                "\"Oh no oh no oh no\"",
                                "\"Now they're dropping all over the place.\"",
                                "\"You'd better get out of the way!!\""]},
            textDictD= {False: ["\"Bark bark!\"",
                                "\"Are you ok??\"",
                                "\"I didn't mean for that to happen...\"",
                                "\"Oh no...\"",
                                "(The dog looks sad...)",
                                "(You reach out to pet the dog.)",
                                "(The dog is so fluffy and nice...)",
                                "(After being pet, the dog looks happy again!)"],
                        True:  ["(You pet the dog again.)",
                                "(The dog is so happy!!)",
                                "(Petting the dog makes you feel happy too.)"]})
        dog.hasBH = True

        self.NPCs = pygame.sprite.Group()
        self.NPCs.add(egg, toast, raindrop, ufo, cat, dog)

        self.currentSign = None
        self.currentHP = None
        self.currentNPC = None

        self.bg_ground = pygame.image.load("ground.png").convert_alpha()
        self.bg_bush = pygame.image.load("bushes.png").convert_alpha()
        self.bg_sky = pygame.image.load("sky.png").convert_alpha()
        self.bg_sun = pygame.image.load("sunlight.png").convert_alpha()
        self.bg_sun = pygame.transform.flip(self.bg_sun, True, False)
        # all the shadows were on the wrong side OOPS LOLOLOL its fixed now

    def setPlayerHealth(self, health):
        self.player.health = health

    def keyPressed(self, keyCode, modifier):
    # first part: if player is reading, advance text
        if self.player.displayingText:
            if keyCode == pygame.K_z:
                self.player.advanceText()
        elif (self.currentSign != None and self.currentSign.displayingText
            and not self.currentSign.doneReading):
            if keyCode == pygame.K_z:
                self.currentSign.advanceText()
                if self.currentSign.doneReading:
                    self.currentSign = None
        elif (self.currentHP != None and self.currentHP.displayingText 
            and not self.currentHP.doneReading):
            if keyCode == pygame.K_z:
                self.currentHP.advanceText()
                if self.currentHP.doneReading:
                    self.currentHP.healPlayer(self.player)
                    self.currentHP = None
        elif (self.currentNPC != None and self.currentNPC.displayingText 
            and not self.currentNPC.doneReading):
            if keyCode == pygame.K_z:
                self.currentNPC.advanceText()
                if self.currentNPC.doneReading:
                    if self.currentNPC.placated == False:
                        # trigger BH mode if possible
                        # otherwise move out of way
                        if self.currentNPC.hasBH:
                            if not self.BH1.completed:
                                self.BH = self.BH1
                            elif not self.BH2.completed:
                                self.BH = self.BH2 
                            elif not self.BH3.completed:
                                self.BH = self.BH3
                            self.BH.setPlayerHealth(self.player.health)
                            self.inBH = True
                        else:
                            self.currentNPC.becomeNice()
                            self.currentNPC.moveOutOfWay()
                    if self.currentNPC.placated == True:
                        self.currentNPC = None
        # second part: let player interact with stuff
        elif keyCode == pygame.K_z:
            collidedSigns = pygame.sprite.spritecollide(self.player, self.signs, False)
            collidedHPs = pygame.sprite.spritecollide(self.player, self.healPoints, False)
            collidedNPCs = pygame.sprite.spritecollide(self.player, self.NPCs, False)
            if collidedSigns != []:
                self.currentSign = collidedSigns[0]
                self.currentSign.displayingText = True
                self.currentSign.doneReading = False
            elif collidedHPs != []:
                self.currentHP = collidedHPs[0]
                self.currentHP.textToDisplay = self.currentHP.text[self.currentHP.talkedTo]
                self.currentHP.displayingText = True
                self.currentHP.doneReading = False  
            elif collidedNPCs != []:
                self.currentNPC = collidedNPCs[0]
                self.currentNPC.textToDisplay = self.currentNPC.text[self.currentNPC.talkedTo]
                self.currentNPC.displayingText = True
                self.currentNPC.doneReading = False
            self.stopMoving()
        # third part: move player
        else:
            if keyCode == pygame.K_LEFT:
                self.player.facingRight = False
                self.player.moving = True
                if (self.player.rect.x > Player.left_thresh or self.worldX <= 0):
                    self.player.changeSpeed(-1, 0)
            elif keyCode == pygame.K_RIGHT:
                self.player.facingRight = True
                self.player.moving = True
                if (self.player.rect.x < Player.right_thresh or 
                        self.worldX >= self.max_worldX):
                    self.player.changeSpeed(+1, 0)
            elif keyCode == pygame.K_UP:
                self.player.unsquish()
            elif keyCode == pygame.K_DOWN:
                self.player.squish()

    def keyReleased(self, keyCode, modifier):
        if keyCode in RPG.ARROWKEYS:
            self.stopMoving()

    def stopMoving(self):
        self.player.moving = False
        self.player.unanimate()
        self.player.dx = 0
        self.worldX_dx = 0

    def timerFired(self, dt):
        # first part: move player & scroll
        if self.player.moving:
            if self.player.facingRight and self.player.rect.x > Player.right_thresh: 
                if self.worldX >= self.max_worldX:
                    self.worldX_dx = 0
                elif self.worldX < self.max_worldX:
                    self.player.dx = 0
                    self.worldX_dx = +1*self.player.speed
            elif (not self.player.facingRight) and self.player.rect.x < Player.left_thresh: 
                if self.worldX <= 0:
                    self.worldX_dx = 0
                elif self.worldX > 0:
                    self.player.dx = 0
                    self.worldX_dx = -1*self.player.speed
        
        player_worldX = self.worldX + self.player.rect.x
        
        # do stuff if player reaches ends of map
        if player_worldX > self.ending_thresh:
            self.completed = True
        elif player_worldX < 0:
            self.triedToGoHome = True

        # make it rain
        if (player_worldX >= self.rain_thresh and not self.isRaining and 
            not self.hasRained):
            self.isRaining = True

        if self.isRaining:
            self.rainCount += 1
            if self.rainCount % 2 == 0:
                self.raindrops.add(Raindrop())
            if self.rainCount >= self.max_rainCount:
                self.isRaining = False
                self.hasRained = True

        # trigger flavor text
        if (player_worldX in Player.FLAVORTEXT and
                player_worldX not in Player.SEENTEXT):
            self.stopMoving()
            self.player.displayingText = True
            self.player.textToDisplay = Player.FLAVORTEXT[player_worldX]
            Player.SEENTEXT.add(player_worldX)

        # automatic npc interaction
        collidedNPCs = pygame.sprite.spritecollide(self.player, self.NPCs, False)
        if collidedNPCs != [] and collidedNPCs[0].placated == False:
            self.stopMoving()
            self.currentNPC = collidedNPCs[0]
            self.currentNPC.textToDisplay = self.currentNPC.text[self.currentNPC.talkedTo]
            self.currentNPC.displayingText = True
            self.currentNPC.doneReading = False        

        # update everything
        self.worldX += self.worldX_dx
        self.player.animate()
        self.playerList.update()
        self.signs.update(self.worldX)
        self.healPoints.update(self.worldX)
        self.NPCs.update(self.worldX)
        self.raindrops.update(self.worldX_dx)

    def redrawAll(self, screen):
        # draw background (parallax..whee)
        screen.blit(self.bg_sky, (0, 0), (self.worldX//2, 0, 600, 450))
        screen.blit(self.bg_bush, (0, 0), (int(self.worldX*0.75), 0, 600, 450))
        screen.blit(self.bg_ground, (0, 0), (self.worldX, 0, 600, 450))
        # draw player & other things
        self.signs.draw(screen)
        self.healPoints.draw(screen)
        self.NPCs.draw(screen)
        self.playerList.draw(screen)
        # draw more background..or..foreground??
        screen.blit(self.bg_sun, (0, 0), (self.worldX*1.2, 0, 600, 450))
        # draw rain
        self.raindrops.draw(screen)
        # draw health
        self.player.displayHealth(screen)
        # display some text
        text = None
        if self.player.displayingText:
            text = self.player.textToDisplay[self.player.text_index]
        elif self.currentSign != None and self.currentSign.displayingText:
            text = self.currentSign.text[self.currentSign.text_index]
        elif self.currentHP != None and self.currentHP.displayingText:
            text = self.currentHP.textToDisplay[self.currentHP.text_index]
        elif self.currentNPC != None and self.currentNPC.displayingText:
            text = self.currentNPC.textToDisplay[self.currentNPC.text_index]
        if text != None:
            Textbox.displayTextBox(screen, self.textbox, text)
    def __init__(self):
        # this is super long omg
        # Bye Style Points...
        # but seriously though. its bad
        BHMode.init()

        self.triedToGoHome = False

        self.hasRained = False
        self.isRaining = False
        self.rain_thresh = 4000
        self.rainCount = 0
        self.max_rainCount = 60 * 60
        self.raindrops = pygame.sprite.Group()
        Raindrop.init()

        self.inBH = False
        self.BH = None
        self.BH1 = BHMode()
        #self.BH1.completed = True #!!
        self.BH2 = BHMode2()
        #self.BH2.completed = True #!!
        self.BH3 = BHMode3()
        #self.BH3.completed = True #!!
        # these comments were for testing purposes

        self.completed = False
        self.ending_thresh = 5980

        self.worldX = 0
        self.worldX_dx = 0
        self.max_worldX = 5400

        self.textbox = pygame.sprite.Group()
        self.textbox.add(Textbox())

        self.player = Player()
        self.playerList = pygame.sprite.Group()
        self.playerList.add(self.player)

        # add signs
        sign1 = Sign(300, [
            "\"Hello, I am a sign.\"",
            "\"Here is some important information:\"",
            "\"West: Residential area.\"", "\"East: Shopping district.\"",
            "\"I hope you found this helpful.\""
        ])
        sign2 = Sign(550, [
            "(There is a sticky note on this sign.)",
            "\"Dear Star Town citizens:\"", "\"It's me! Your mayor.\"",
            "\"Please join me in welcoming our new residents...\"",
            "\"Tomorrow.\"",
            "\"I don't want to miss the supermarket sale today!\""
        ])
        sign3 = Sign(1200, [
            "\"It's not 'trash CAN'T '...\"", "\"It's 'trash CAN' !!\"",
            "\"So, even if you are feeling like trash...\"",
            "\"Please, keep doing your best!!\"",
            "\"--Sincerely, a trash enthusiast.\""
        ])
        # (im the trash enthusiast)
        sign4 = Sign(2100, [
            "(It seems like someone has defaced this sign...)",
            "(Now there is a picture of a cat on it.)",
            "\"WANTED: cat who keeps eating my food\"",
            "\"Whoever you are, please stop...\""
        ])
        sign5 = Sign(2710, [
            "\"Space enthusiast meeting --\"", "\"Next Tuesday at 7pm.\"",
            "\"BYOS (Bring Your Own Spaceship).\""
        ])
        sign6 = Sign(3400, [
            "\"Star Town Tree:\"", "\"This tree was planted to commemorate\"",
            "\"the founding of our town.\"",
            "\"The tree supports our citizens in many ways,\"",
            "\"so please continue to support Star Town.\""
        ])
        sign7 = Sign(4900, ["\"Warning: dog.\"", "\"Very fluffy.\""])
        sign8 = Sign(5850, [
            "\"Supermarket -- just over to the right!\"",
            "\"Don't miss all our PRICES and SELECTIONS.\""
        ])
        self.signs = pygame.sprite.Group()
        self.signs.add(sign1, sign2, sign3, sign4, sign5, sign6, sign7, sign8)

        # add heal pts
        trash = HealPoint(
            rectY=180,
            worldX=1000,
            healthPts=10,
            imageName="trash-chan.png",
            textDict={
                False: [
                    "(It's a trash can.)", "(You find a burger in the trash.)",
                    "(You eat the burger and recover some HEALTH.)",
                    "(How disgusting...)"
                ],
                True: [
                    "(You ate the trash...)",
                    "(The trash is inside of you...)",
                    "(You feel like a trash can.)"
                ]
            })

        tallPerson = HealPoint(
            rectY=0,
            worldX=2300,
            healthPts=30,
            imageName="tall.png",
            textDict={
                False: [
                    "(It's an extremely tall individual.)",
                    "(For some reason, you feel very safe here.)",
                    "(You rest underneath the individual for a while...)",
                    "(Hopefully they didn't mind.)",
                    "(You recover some HEALTH.)"
                ],
                True: [
                    "(This individual is so tall,",
                    "that you can't see beyond their legs.)",
                    "(But, at least they have great footwear.)"
                ]
            })

        tree = HealPoint(
            rectY=0,
            worldX=3500,
            healthPts=30,
            imageName="tree.png",
            textDict={
                False: [
                    "(It's a great big tree.)",
                    "(You stop and take a break under it.)",
                    "(Suddenly, a piece of fruit falls in front of you!)",
                    "(You eat the fruit and regain some HEALTH.)",
                    "(Somewhere in the distance...)",
                    "(You sense that someone is greatly offended by this.)"
                ],
                True: [
                    "(You stay under the tree for a little while.)",
                    "(You feel so refreshed! Mentally, that is.)"
                ]
            })

        busStop = HealPoint(
            rectY=110,
            worldX=5500,
            healthPts=30,
            imageName="bus_stop.png",
            textDict={
                False: [
                    "(It's a bus stop.)",
                    "(You haven't seen the bus all day...)", "(But...)",
                    "(You're sure the bus is trying its best!!)",
                    "(Thinking of the bus increases your HEALTH.)"
                ],
                True: [
                    "(You keep thinking about the bus...)",
                    "(But nothing else happens. Aw.)"
                ]
            })

        self.healPoints = pygame.sprite.Group()
        self.healPoints.add(trash, tallPerson, tree, busStop)

        # add npc's
        egg = NPC(rectY=305,
                  worldX=800,
                  imageName="egg.png",
                  textDictM={
                      False: [
                          "\"Oh...hello...\"",
                          "\"I was just enjoying this nice sunlight.\"",
                          "\"I'll get out of the way.\""
                      ]
                  },
                  textDictD={
                      False: [
                          "\"Do you see that trash can over there?\"",
                          "\"I saw someone throw something away",
                          "a few minutes ago.\"",
                          "\"Maybe you should check it out.\""
                      ],
                      True: [
                          "\"The ground is all warm from the sun...\"",
                          "\"By the way, did you find anything in the trash?\""
                      ]
                  })
        egg.hasBH = False

        toast = NPC(
            rectY=250,
            worldX=1500,
            imageName="toast.png",
            textDictM={
                False: [
                    "\"Hello, new neighbor!\"", "\"You look hungry!\"",
                    "\"Did you eat breakfast today?\"",
                    "\"It's important to have a balanced breakfast.\"",
                    "\"Let me help you out.\"",
                    "\"Please take the breakfast items",
                    "that I am about to throw at you.\"",
                    "\"Run into them as hard as you can, ok??\"",
                    "\"I'm sure your HEALTH will improve in no time.\"",
                    "\"Of course, it's totally safe.\"",
                    "\"There is no way this can hurt you.\"", "(...)",
                    "(You hear a voice from above again...)",
                    "('Hey! Listen up!')",
                    "('Move around with the ARROW KEYS.')",
                    "('Try to dodge the projectiles!')",
                    "('If your HEART gets hit, you will lose HEALTH.')",
                    "('Hold down 'Z' to cry...')",
                    "('You will shoot tears at your opponent.')",
                    "('Crying will damage them...emotionally')",
                    "('They will leave you alone if they have low HP,)",
                    "('or if they run out of projectiles.')",
                    "('Hold down LEFT SHIFT to focus.')",
                    "('If you concentrate, you can slow your movements.')",
                    "('You will also cry harder.')",
                    "('Press 'X' to do something exciting.')",
                    "('If you distract your neighbor,')",
                    "('you can make them stop shooting momentarily.')",
                    "('You will also scare away the projectiles.')",
                    "('Finally, press 'P' to stop time.')",
                    "('It's fine to take a break.')",
                    "('OK, that's it! I hope you were paying attention!')",
                    "(...You carefully remember those instructions!)", "(...)",
                    "\"Are you ready?\"", "\"Here we go!\""
                ]
            },
            textDictD={
                False: [
                    "\"You didn't eat anything...\"",
                    "\"Do you not like food items...",
                    "...being hurled at you at high velocities?\"",
                    "\"Well...whatever works for you, I guess.\""
                ],
                True: [
                    "\"Are you headed to the supermarket?\"",
                    "\"It's all the way to your right.\"",
                    "\"You can go buy some fruits there...\"",
                    "\"Even though, I gave some to you for free.\""
                ]
            })
        toast.hasBH = True

        raindrop = NPC(
            rectY=255,
            worldX=1800,
            imageName="raindrop.png",
            textDictM={
                False: [
                    "\"Ah...I wish it was raining.\"",
                    "\"I love the rain. It's my element.\"",
                    "\"But I guess this weather is OK too.\"",
                    "\"...Oh, am I in your way?\"",
                    "\"I'll go stand a little bit to my right.\""
                ]
            },
            textDictD={
                False: [
                    "\"Sometimes the weather here gets really bad.\"",
                    "\"It'll rain so hard that, if the rain hits you...\"",
                    "\"You might even lose some HEALTH!\"",
                    "\"If you wanted to go anywhere...\"",
                    "\"You would have to dodge all the rain!!\"",
                    "\"Doesn't that sound fun? Haha.\"",
                    "\"Don't worry, though.\"",
                    "\"It won't happen to you today.\"",
                    "\"It might rain a little bit, but,\"",
                    "\"a slight drizzle won't hurt you.\""
                ],
                True: [
                    "\"It's good to stock up on food at home.\"",
                    "\"That way you won't have to go outside",
                    "when there's bad weather.\"", "\"...\"",
                    "\"What do you mean, you never go outside anyway??\""
                ]
            })
        raindrop.hasBH = False

        ufo = NPC(rectY=220,
                  worldX=2900,
                  imageName="ufo.png",
                  textDictM={
                      False:
                      ["\"...\"", "\".....\"", "\"....!\"", "\"! ! !\""]
                  },
                  textDictD={
                      False: [
                          "\"Oh no...I'm sorry, are you hurt?\"",
                          "\"I was just so excited about space.\"",
                          "\"I just moved here from space, you see.\"",
                          "\"I wanted to show everyone here",
                          "how cool and pretty my home was...\"",
                          "\"So I bought a bunch of plastic stars...\"",
                          "\"But now they're all over the ground.\"",
                          "\"...whoops...\""
                      ],
                      True: [
                          "\"...\"", "\"......\"", "\"...zzz...\"",
                          "(You look more closely at the UFO...)",
                          "(Oh! There is a very small cat inside.)",
                          "(The cat is taking a nap!)",
                          "(It must be nice and cozy in there.)"
                      ]
                  })
        ufo.hasBH = True

        cat = NPC(
            rectY=210,
            worldX=3850,
            imageName="cat.png",
            textDictM={
                False: [
                    "\"Someone keeps eating all my Frisky Bitz.\"",
                    "\"It's not you, is it??\"", "\"...\"",
                    "\"You don't look like a cat, so...\"",
                    "\"I guess it's someone else.\"",
                    "\"I mean, they pay me back for it, but still!\"",
                    "\"Now I have to go buy more all the time.\"",
                    "\"Sigh...\""
                ]
            },
            textDictD={
                False: [
                    "\"...Have you noticed all the stuff on the ground?\"",
                    "\"Those star-shaped rocks...\"",
                    "\"No one knows where they came from.\"",
                    "\"Except maybe the mayor.\"",
                    "\"I've never seen them before, but...\"",
                    "\"Sometimes you'll hear their voice from above.\"",
                    "\"So, has the mayor said anything to you yet?\"",
                    "(...You hear something from above...)",
                    "('...*coughing noises*...')",
                    "('...Sorry, I choked on a chip.')",
                    "('Did you need something?')",
                    "(...no thanks...you're good...)"
                ],
                True: [
                    "\"I'll be waiting here until I run into",
                    "whoever keeps eating my food.\"",
                    "\"You should go on ahead!\"",
                    "\"The shopping district is not so far ahead.\""
                ]
            })
        cat.hasBH = False

        dog = NPC(rectY=210,
                  worldX=5200,
                  imageName="dog.png",
                  textDictM={
                      False: [
                          "\"Woof!\"", "\"Don't come any closer!\"",
                          "\"I decided to dig up all my chew toys.\"",
                          "\"But now I have too many...\"",
                          "\"I can't hold on to all of them...\"",
                          "\"...Oh no...\"", "\"Oh no oh no oh no\"",
                          "\"Now they're dropping all over the place.\"",
                          "\"You'd better get out of the way!!\""
                      ]
                  },
                  textDictD={
                      False: [
                          "\"Bark bark!\"", "\"Are you ok??\"",
                          "\"I didn't mean for that to happen...\"",
                          "\"Oh no...\"", "(The dog looks sad...)",
                          "(You reach out to pet the dog.)",
                          "(The dog is so fluffy and nice...)",
                          "(After being pet, the dog looks happy again!)"
                      ],
                      True: [
                          "(You pet the dog again.)",
                          "(The dog is so happy!!)",
                          "(Petting the dog makes you feel happy too.)"
                      ]
                  })
        dog.hasBH = True

        self.NPCs = pygame.sprite.Group()
        self.NPCs.add(egg, toast, raindrop, ufo, cat, dog)

        self.currentSign = None
        self.currentHP = None
        self.currentNPC = None

        self.bg_ground = pygame.image.load("ground.png").convert_alpha()
        self.bg_bush = pygame.image.load("bushes.png").convert_alpha()
        self.bg_sky = pygame.image.load("sky.png").convert_alpha()
        self.bg_sun = pygame.image.load("sunlight.png").convert_alpha()
        self.bg_sun = pygame.transform.flip(self.bg_sun, True, False)
class RPG(object):
    ARROWKEYS = {pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN}

    def __init__(self):
        # this is super long omg
        # Bye Style Points...
        # but seriously though. its bad
        BHMode.init()

        self.triedToGoHome = False

        self.hasRained = False
        self.isRaining = False
        self.rain_thresh = 4000
        self.rainCount = 0
        self.max_rainCount = 60 * 60
        self.raindrops = pygame.sprite.Group()
        Raindrop.init()

        self.inBH = False
        self.BH = None
        self.BH1 = BHMode()
        #self.BH1.completed = True #!!
        self.BH2 = BHMode2()
        #self.BH2.completed = True #!!
        self.BH3 = BHMode3()
        #self.BH3.completed = True #!!
        # these comments were for testing purposes

        self.completed = False
        self.ending_thresh = 5980

        self.worldX = 0
        self.worldX_dx = 0
        self.max_worldX = 5400

        self.textbox = pygame.sprite.Group()
        self.textbox.add(Textbox())

        self.player = Player()
        self.playerList = pygame.sprite.Group()
        self.playerList.add(self.player)

        # add signs
        sign1 = Sign(300, [
            "\"Hello, I am a sign.\"",
            "\"Here is some important information:\"",
            "\"West: Residential area.\"", "\"East: Shopping district.\"",
            "\"I hope you found this helpful.\""
        ])
        sign2 = Sign(550, [
            "(There is a sticky note on this sign.)",
            "\"Dear Star Town citizens:\"", "\"It's me! Your mayor.\"",
            "\"Please join me in welcoming our new residents...\"",
            "\"Tomorrow.\"",
            "\"I don't want to miss the supermarket sale today!\""
        ])
        sign3 = Sign(1200, [
            "\"It's not 'trash CAN'T '...\"", "\"It's 'trash CAN' !!\"",
            "\"So, even if you are feeling like trash...\"",
            "\"Please, keep doing your best!!\"",
            "\"--Sincerely, a trash enthusiast.\""
        ])
        # (im the trash enthusiast)
        sign4 = Sign(2100, [
            "(It seems like someone has defaced this sign...)",
            "(Now there is a picture of a cat on it.)",
            "\"WANTED: cat who keeps eating my food\"",
            "\"Whoever you are, please stop...\""
        ])
        sign5 = Sign(2710, [
            "\"Space enthusiast meeting --\"", "\"Next Tuesday at 7pm.\"",
            "\"BYOS (Bring Your Own Spaceship).\""
        ])
        sign6 = Sign(3400, [
            "\"Star Town Tree:\"", "\"This tree was planted to commemorate\"",
            "\"the founding of our town.\"",
            "\"The tree supports our citizens in many ways,\"",
            "\"so please continue to support Star Town.\""
        ])
        sign7 = Sign(4900, ["\"Warning: dog.\"", "\"Very fluffy.\""])
        sign8 = Sign(5850, [
            "\"Supermarket -- just over to the right!\"",
            "\"Don't miss all our PRICES and SELECTIONS.\""
        ])
        self.signs = pygame.sprite.Group()
        self.signs.add(sign1, sign2, sign3, sign4, sign5, sign6, sign7, sign8)

        # add heal pts
        trash = HealPoint(
            rectY=180,
            worldX=1000,
            healthPts=10,
            imageName="trash-chan.png",
            textDict={
                False: [
                    "(It's a trash can.)", "(You find a burger in the trash.)",
                    "(You eat the burger and recover some HEALTH.)",
                    "(How disgusting...)"
                ],
                True: [
                    "(You ate the trash...)",
                    "(The trash is inside of you...)",
                    "(You feel like a trash can.)"
                ]
            })

        tallPerson = HealPoint(
            rectY=0,
            worldX=2300,
            healthPts=30,
            imageName="tall.png",
            textDict={
                False: [
                    "(It's an extremely tall individual.)",
                    "(For some reason, you feel very safe here.)",
                    "(You rest underneath the individual for a while...)",
                    "(Hopefully they didn't mind.)",
                    "(You recover some HEALTH.)"
                ],
                True: [
                    "(This individual is so tall,",
                    "that you can't see beyond their legs.)",
                    "(But, at least they have great footwear.)"
                ]
            })

        tree = HealPoint(
            rectY=0,
            worldX=3500,
            healthPts=30,
            imageName="tree.png",
            textDict={
                False: [
                    "(It's a great big tree.)",
                    "(You stop and take a break under it.)",
                    "(Suddenly, a piece of fruit falls in front of you!)",
                    "(You eat the fruit and regain some HEALTH.)",
                    "(Somewhere in the distance...)",
                    "(You sense that someone is greatly offended by this.)"
                ],
                True: [
                    "(You stay under the tree for a little while.)",
                    "(You feel so refreshed! Mentally, that is.)"
                ]
            })

        busStop = HealPoint(
            rectY=110,
            worldX=5500,
            healthPts=30,
            imageName="bus_stop.png",
            textDict={
                False: [
                    "(It's a bus stop.)",
                    "(You haven't seen the bus all day...)", "(But...)",
                    "(You're sure the bus is trying its best!!)",
                    "(Thinking of the bus increases your HEALTH.)"
                ],
                True: [
                    "(You keep thinking about the bus...)",
                    "(But nothing else happens. Aw.)"
                ]
            })

        self.healPoints = pygame.sprite.Group()
        self.healPoints.add(trash, tallPerson, tree, busStop)

        # add npc's
        egg = NPC(rectY=305,
                  worldX=800,
                  imageName="egg.png",
                  textDictM={
                      False: [
                          "\"Oh...hello...\"",
                          "\"I was just enjoying this nice sunlight.\"",
                          "\"I'll get out of the way.\""
                      ]
                  },
                  textDictD={
                      False: [
                          "\"Do you see that trash can over there?\"",
                          "\"I saw someone throw something away",
                          "a few minutes ago.\"",
                          "\"Maybe you should check it out.\""
                      ],
                      True: [
                          "\"The ground is all warm from the sun...\"",
                          "\"By the way, did you find anything in the trash?\""
                      ]
                  })
        egg.hasBH = False

        toast = NPC(
            rectY=250,
            worldX=1500,
            imageName="toast.png",
            textDictM={
                False: [
                    "\"Hello, new neighbor!\"", "\"You look hungry!\"",
                    "\"Did you eat breakfast today?\"",
                    "\"It's important to have a balanced breakfast.\"",
                    "\"Let me help you out.\"",
                    "\"Please take the breakfast items",
                    "that I am about to throw at you.\"",
                    "\"Run into them as hard as you can, ok??\"",
                    "\"I'm sure your HEALTH will improve in no time.\"",
                    "\"Of course, it's totally safe.\"",
                    "\"There is no way this can hurt you.\"", "(...)",
                    "(You hear a voice from above again...)",
                    "('Hey! Listen up!')",
                    "('Move around with the ARROW KEYS.')",
                    "('Try to dodge the projectiles!')",
                    "('If your HEART gets hit, you will lose HEALTH.')",
                    "('Hold down 'Z' to cry...')",
                    "('You will shoot tears at your opponent.')",
                    "('Crying will damage them...emotionally')",
                    "('They will leave you alone if they have low HP,)",
                    "('or if they run out of projectiles.')",
                    "('Hold down LEFT SHIFT to focus.')",
                    "('If you concentrate, you can slow your movements.')",
                    "('You will also cry harder.')",
                    "('Press 'X' to do something exciting.')",
                    "('If you distract your neighbor,')",
                    "('you can make them stop shooting momentarily.')",
                    "('You will also scare away the projectiles.')",
                    "('Finally, press 'P' to stop time.')",
                    "('It's fine to take a break.')",
                    "('OK, that's it! I hope you were paying attention!')",
                    "(...You carefully remember those instructions!)", "(...)",
                    "\"Are you ready?\"", "\"Here we go!\""
                ]
            },
            textDictD={
                False: [
                    "\"You didn't eat anything...\"",
                    "\"Do you not like food items...",
                    "...being hurled at you at high velocities?\"",
                    "\"Well...whatever works for you, I guess.\""
                ],
                True: [
                    "\"Are you headed to the supermarket?\"",
                    "\"It's all the way to your right.\"",
                    "\"You can go buy some fruits there...\"",
                    "\"Even though, I gave some to you for free.\""
                ]
            })
        toast.hasBH = True

        raindrop = NPC(
            rectY=255,
            worldX=1800,
            imageName="raindrop.png",
            textDictM={
                False: [
                    "\"Ah...I wish it was raining.\"",
                    "\"I love the rain. It's my element.\"",
                    "\"But I guess this weather is OK too.\"",
                    "\"...Oh, am I in your way?\"",
                    "\"I'll go stand a little bit to my right.\""
                ]
            },
            textDictD={
                False: [
                    "\"Sometimes the weather here gets really bad.\"",
                    "\"It'll rain so hard that, if the rain hits you...\"",
                    "\"You might even lose some HEALTH!\"",
                    "\"If you wanted to go anywhere...\"",
                    "\"You would have to dodge all the rain!!\"",
                    "\"Doesn't that sound fun? Haha.\"",
                    "\"Don't worry, though.\"",
                    "\"It won't happen to you today.\"",
                    "\"It might rain a little bit, but,\"",
                    "\"a slight drizzle won't hurt you.\""
                ],
                True: [
                    "\"It's good to stock up on food at home.\"",
                    "\"That way you won't have to go outside",
                    "when there's bad weather.\"", "\"...\"",
                    "\"What do you mean, you never go outside anyway??\""
                ]
            })
        raindrop.hasBH = False

        ufo = NPC(rectY=220,
                  worldX=2900,
                  imageName="ufo.png",
                  textDictM={
                      False:
                      ["\"...\"", "\".....\"", "\"....!\"", "\"! ! !\""]
                  },
                  textDictD={
                      False: [
                          "\"Oh no...I'm sorry, are you hurt?\"",
                          "\"I was just so excited about space.\"",
                          "\"I just moved here from space, you see.\"",
                          "\"I wanted to show everyone here",
                          "how cool and pretty my home was...\"",
                          "\"So I bought a bunch of plastic stars...\"",
                          "\"But now they're all over the ground.\"",
                          "\"...whoops...\""
                      ],
                      True: [
                          "\"...\"", "\"......\"", "\"...zzz...\"",
                          "(You look more closely at the UFO...)",
                          "(Oh! There is a very small cat inside.)",
                          "(The cat is taking a nap!)",
                          "(It must be nice and cozy in there.)"
                      ]
                  })
        ufo.hasBH = True

        cat = NPC(
            rectY=210,
            worldX=3850,
            imageName="cat.png",
            textDictM={
                False: [
                    "\"Someone keeps eating all my Frisky Bitz.\"",
                    "\"It's not you, is it??\"", "\"...\"",
                    "\"You don't look like a cat, so...\"",
                    "\"I guess it's someone else.\"",
                    "\"I mean, they pay me back for it, but still!\"",
                    "\"Now I have to go buy more all the time.\"",
                    "\"Sigh...\""
                ]
            },
            textDictD={
                False: [
                    "\"...Have you noticed all the stuff on the ground?\"",
                    "\"Those star-shaped rocks...\"",
                    "\"No one knows where they came from.\"",
                    "\"Except maybe the mayor.\"",
                    "\"I've never seen them before, but...\"",
                    "\"Sometimes you'll hear their voice from above.\"",
                    "\"So, has the mayor said anything to you yet?\"",
                    "(...You hear something from above...)",
                    "('...*coughing noises*...')",
                    "('...Sorry, I choked on a chip.')",
                    "('Did you need something?')",
                    "(...no thanks...you're good...)"
                ],
                True: [
                    "\"I'll be waiting here until I run into",
                    "whoever keeps eating my food.\"",
                    "\"You should go on ahead!\"",
                    "\"The shopping district is not so far ahead.\""
                ]
            })
        cat.hasBH = False

        dog = NPC(rectY=210,
                  worldX=5200,
                  imageName="dog.png",
                  textDictM={
                      False: [
                          "\"Woof!\"", "\"Don't come any closer!\"",
                          "\"I decided to dig up all my chew toys.\"",
                          "\"But now I have too many...\"",
                          "\"I can't hold on to all of them...\"",
                          "\"...Oh no...\"", "\"Oh no oh no oh no\"",
                          "\"Now they're dropping all over the place.\"",
                          "\"You'd better get out of the way!!\""
                      ]
                  },
                  textDictD={
                      False: [
                          "\"Bark bark!\"", "\"Are you ok??\"",
                          "\"I didn't mean for that to happen...\"",
                          "\"Oh no...\"", "(The dog looks sad...)",
                          "(You reach out to pet the dog.)",
                          "(The dog is so fluffy and nice...)",
                          "(After being pet, the dog looks happy again!)"
                      ],
                      True: [
                          "(You pet the dog again.)",
                          "(The dog is so happy!!)",
                          "(Petting the dog makes you feel happy too.)"
                      ]
                  })
        dog.hasBH = True

        self.NPCs = pygame.sprite.Group()
        self.NPCs.add(egg, toast, raindrop, ufo, cat, dog)

        self.currentSign = None
        self.currentHP = None
        self.currentNPC = None

        self.bg_ground = pygame.image.load("ground.png").convert_alpha()
        self.bg_bush = pygame.image.load("bushes.png").convert_alpha()
        self.bg_sky = pygame.image.load("sky.png").convert_alpha()
        self.bg_sun = pygame.image.load("sunlight.png").convert_alpha()
        self.bg_sun = pygame.transform.flip(self.bg_sun, True, False)
        # all the shadows were on the wrong side OOPS LOLOLOL its fixed now

    def setPlayerHealth(self, health):
        self.player.health = health

    def keyPressed(self, keyCode, modifier):
        # first part: if player is reading, advance text
        if self.player.displayingText:
            if keyCode == pygame.K_z:
                self.player.advanceText()
        elif (self.currentSign != None and self.currentSign.displayingText
              and not self.currentSign.doneReading):
            if keyCode == pygame.K_z:
                self.currentSign.advanceText()
                if self.currentSign.doneReading:
                    self.currentSign = None
        elif (self.currentHP != None and self.currentHP.displayingText
              and not self.currentHP.doneReading):
            if keyCode == pygame.K_z:
                self.currentHP.advanceText()
                if self.currentHP.doneReading:
                    self.currentHP.healPlayer(self.player)
                    self.currentHP = None
        elif (self.currentNPC != None and self.currentNPC.displayingText
              and not self.currentNPC.doneReading):
            if keyCode == pygame.K_z:
                self.currentNPC.advanceText()
                if self.currentNPC.doneReading:
                    if self.currentNPC.placated == False:
                        # trigger BH mode if possible
                        # otherwise move out of way
                        if self.currentNPC.hasBH:
                            if not self.BH1.completed:
                                self.BH = self.BH1
                            elif not self.BH2.completed:
                                self.BH = self.BH2
                            elif not self.BH3.completed:
                                self.BH = self.BH3
                            self.BH.setPlayerHealth(self.player.health)
                            self.inBH = True
                        else:
                            self.currentNPC.becomeNice()
                            self.currentNPC.moveOutOfWay()
                    if self.currentNPC.placated == True:
                        self.currentNPC = None
        # second part: let player interact with stuff
        elif keyCode == pygame.K_z:
            collidedSigns = pygame.sprite.spritecollide(
                self.player, self.signs, False)
            collidedHPs = pygame.sprite.spritecollide(self.player,
                                                      self.healPoints, False)
            collidedNPCs = pygame.sprite.spritecollide(self.player, self.NPCs,
                                                       False)
            if collidedSigns != []:
                self.currentSign = collidedSigns[0]
                self.currentSign.displayingText = True
                self.currentSign.doneReading = False
            elif collidedHPs != []:
                self.currentHP = collidedHPs[0]
                self.currentHP.textToDisplay = self.currentHP.text[
                    self.currentHP.talkedTo]
                self.currentHP.displayingText = True
                self.currentHP.doneReading = False
            elif collidedNPCs != []:
                self.currentNPC = collidedNPCs[0]
                self.currentNPC.textToDisplay = self.currentNPC.text[
                    self.currentNPC.talkedTo]
                self.currentNPC.displayingText = True
                self.currentNPC.doneReading = False
            self.stopMoving()
        # third part: move player
        else:
            if keyCode == pygame.K_LEFT:
                self.player.facingRight = False
                self.player.moving = True
                if (self.player.rect.x > Player.left_thresh
                        or self.worldX <= 0):
                    self.player.changeSpeed(-1, 0)
            elif keyCode == pygame.K_RIGHT:
                self.player.facingRight = True
                self.player.moving = True
                if (self.player.rect.x < Player.right_thresh
                        or self.worldX >= self.max_worldX):
                    self.player.changeSpeed(+1, 0)
            elif keyCode == pygame.K_UP:
                self.player.unsquish()
            elif keyCode == pygame.K_DOWN:
                self.player.squish()

    def keyReleased(self, keyCode, modifier):
        if keyCode in RPG.ARROWKEYS:
            self.stopMoving()

    def stopMoving(self):
        self.player.moving = False
        self.player.unanimate()
        self.player.dx = 0
        self.worldX_dx = 0

    def timerFired(self, dt):
        # first part: move player & scroll
        if self.player.moving:
            if self.player.facingRight and self.player.rect.x > Player.right_thresh:
                if self.worldX >= self.max_worldX:
                    self.worldX_dx = 0
                elif self.worldX < self.max_worldX:
                    self.player.dx = 0
                    self.worldX_dx = +1 * self.player.speed
            elif (not self.player.facingRight
                  ) and self.player.rect.x < Player.left_thresh:
                if self.worldX <= 0:
                    self.worldX_dx = 0
                elif self.worldX > 0:
                    self.player.dx = 0
                    self.worldX_dx = -1 * self.player.speed

        player_worldX = self.worldX + self.player.rect.x

        # do stuff if player reaches ends of map
        if player_worldX > self.ending_thresh:
            self.completed = True
        elif player_worldX < 0:
            self.triedToGoHome = True

        # make it rain
        if (player_worldX >= self.rain_thresh and not self.isRaining
                and not self.hasRained):
            self.isRaining = True

        if self.isRaining:
            self.rainCount += 1
            if self.rainCount % 2 == 0:
                self.raindrops.add(Raindrop())
            if self.rainCount >= self.max_rainCount:
                self.isRaining = False
                self.hasRained = True

        # trigger flavor text
        if (player_worldX in Player.FLAVORTEXT
                and player_worldX not in Player.SEENTEXT):
            self.stopMoving()
            self.player.displayingText = True
            self.player.textToDisplay = Player.FLAVORTEXT[player_worldX]
            Player.SEENTEXT.add(player_worldX)

        # automatic npc interaction
        collidedNPCs = pygame.sprite.spritecollide(self.player, self.NPCs,
                                                   False)
        if collidedNPCs != [] and collidedNPCs[0].placated == False:
            self.stopMoving()
            self.currentNPC = collidedNPCs[0]
            self.currentNPC.textToDisplay = self.currentNPC.text[
                self.currentNPC.talkedTo]
            self.currentNPC.displayingText = True
            self.currentNPC.doneReading = False

        # update everything
        self.worldX += self.worldX_dx
        self.player.animate()
        self.playerList.update()
        self.signs.update(self.worldX)
        self.healPoints.update(self.worldX)
        self.NPCs.update(self.worldX)
        self.raindrops.update(self.worldX_dx)

    def redrawAll(self, screen):
        # draw background (parallax..whee)
        screen.blit(self.bg_sky, (0, 0), (self.worldX // 2, 0, 600, 450))
        screen.blit(self.bg_bush, (0, 0),
                    (int(self.worldX * 0.75), 0, 600, 450))
        screen.blit(self.bg_ground, (0, 0), (self.worldX, 0, 600, 450))
        # draw player & other things
        self.signs.draw(screen)
        self.healPoints.draw(screen)
        self.NPCs.draw(screen)
        self.playerList.draw(screen)
        # draw more background..or..foreground??
        screen.blit(self.bg_sun, (0, 0), (self.worldX * 1.2, 0, 600, 450))
        # draw rain
        self.raindrops.draw(screen)
        # draw health
        self.player.displayHealth(screen)
        # display some text
        text = None
        if self.player.displayingText:
            text = self.player.textToDisplay[self.player.text_index]
        elif self.currentSign != None and self.currentSign.displayingText:
            text = self.currentSign.text[self.currentSign.text_index]
        elif self.currentHP != None and self.currentHP.displayingText:
            text = self.currentHP.textToDisplay[self.currentHP.text_index]
        elif self.currentNPC != None and self.currentNPC.displayingText:
            text = self.currentNPC.textToDisplay[self.currentNPC.text_index]
        if text != None:
            Textbox.displayTextBox(screen, self.textbox, text)
Exemple #8
0
            print "\n"
        elif menu_val == 3:
            sys.exit("Thank you for playing.")

    game = playerorcomputer()
    l = inputlength()
    w = inputwidth()
    a = space_occupied(num_bs(), num_cru(), num_frig(), num_mine(), l, w)
    b, c, d, e = a[0], a[1], a[2], a[3]
    name1 = raw_input('Enter the name of player 1: ')
    name2 = raw_input('Enter the name of player 2: ')

    g = Board(l, w, a, b, c, d, game)

    if game == 'c':
        a = Player(l, w, b, c, d, e, name1)
        f = ComputerPlayer(l, w, b, c, d, e, name2)
        a.place_ships()
        a.draw_board()
        f.place_ships()
        a.opp_coord_copy(f.coordinates)
        f.opp_coord_copy(a.coordinates)
        g = Board(l, w, a, b, c, d, game)
        g.player_vs_computer(a, f, a.coordinates, f.coordinates)

    elif game == 'p':
        a = Player(l, w, b, c, d, e, name1)
        f = Player(l, w, b, c, d, e, name2)
        a.place_ships()
        a.draw_board()
        f.place_ships()