示例#1
0
    def initialize(self, username, addr):

        """Initialize the game engine.
        
        Set up the main window, initialize a connection to a server and
        initialize the base objects."""

        self.logger = logging.getLogger('client.gameengine.GameEngine')
        self.logger.info("Initializing client engine...")

        self.logger.info("Initializing pygame...")
        pygame.init()

        modes = pygame.display.list_modes()
        self.screen = pygame.display.set_mode(modes[1])
        pygame.display.set_caption("Haven Core")

        self.username = username
        self.connection = Connection(username, addr)

        graphics.load_sprites()

        self.terrain_data = TerrainData('client/data/terraindata.map',
                                        spritemaps['terrain'])

        self.entities = entity_container

        self.hud = hud()

        jukebox.initialize()
    def setUp(self, onlineMode=True):
        # self.world = World.World(util.WORLDBOUNDS(), util.GRAVITY, True)
        self.world = World.World(util.GRAVITY, True)
        self.world.setCamera(self.MAIN.cam)
        if self.MAIN.client:
            self.world.setGameClient(self.MAIN.client)

        self.makeWorld()
        self.MAIN.cam.setStage(util.getFile(util.IMAGES, "STAGE", self.stage.stageFile))

        xbound = ((self.stage.MINX + 200), (self.stage.MAXX - 200))
        ybound = ((self.stage.MINY + 200), (self.stage.MAXY - 200))

        self.mainChar = Character.Character(self.world, True, self.MAIN.client.charId, 1, 1, xbound, ybound)
        self.mainChar.name = "person"
        if self.MAIN.client:
            self.mainChar.setPlayerId(self.MAIN.client.playerId)
        self.hud = hud.hud()
        self.mainChar.linkHud(self.hud)
        self.controller = Controller.Controller(self.mainChar)
        self.world.setMainCharacter(self.mainChar)

        self.MAIN.cam.addOverlay(self.hud)
        self.world.addActor(self.mainChar)

        if False:  # Set True, for debugging, dangerous
            self.MAIN.cam.addActor(self.stage.getSprites())

        self.MAIN.cam.setFocus(self.mainChar)
        self.MAIN.cam.setFocusPoint((util.CANVAS_WIDTH / 2, util.CANVAS_HEIGHT / 2))
        self.MAIN.cam.setBackground(
            util.getFile(util.IMAGES, "BG", "1.jpg"), self.stage.getWidth(), self.stage.getHeight()
        )

        self.MAIN.eventManager.addHandler(self.controller)

        self.world.addContactListener(self.mainChar.getCharContact())
        self.mainChar.spawn()
        if not self.pickupsRendered:
            np = []
            for pu in self.pickups:
                npu = (self.world,) + pu[1:]
                pus = Pickup.Pickup(*npu)
                self.world.addActor(pus)
                np.append(pus)
            self.pickups = np

        if not onlineMode:
            self.pu = Pickup.Pickup(self.world, 02, 0, 40.8616, 2.16167)
            self.world.addActor(self.pu)

        if onlineMode:
            self.getOtherPlayers()
            self.network = True
            Thread(target=self.networkLoop).start()

        super(GameScene, self).setUp()
示例#3
0
def spend_phase(fuel, food, power, hull, crew, morale, g_dist, distance):
    '''
    Spends resources during the spend phase
    '''

    # phase intro message
    print("Press ENTER to begin the Spend Phase!")
    input()

    # spend food
    food = feed_crew(food, crew)

    if food > 0:

        # check for crystal burnout
        power = crystal_burn(power)

    if (food > 0) and (power > 0) and (fuel > 0):

            # display HUD
            h.hud(fuel, food, power, hull, crew, morale)

            # display distance
            h.status(distance, g_dist)

            # spend fuel
            fuel, distance_traveled = spend_fuel(fuel)

    # if player has fuel set distance traveled to 1 to avoid out of fuel loss message
    # if player has no fuel
    else:

            if fuel > 0:

                distance_traveled = 1

            else:

                distance_traveled = 0

    return fuel, food, power, hull, crew, morale, distance_traveled
示例#4
0
def event_phase(fuel, food, power, hull, crew, morale):
    '''
    Resolve event phase
    '''

    # set number of events
    num_events = 2

    # display beginning of phase
    print("Press ENTER to begin the Event Phase!")
    input()

    # get events
    for x in range(0, num_events):

        # display hud
        h.hud(fuel, food, power, hull, crew, morale)

        # resolve event
        fuel, food, power, hull, crew, morale = get_event(
            fuel, food, power, hull, crew, morale)

        # set values that are less than 0 to 0
        fuel, food, power, hull, crew, morale = less_than_zero(
            fuel, food, power, hull, crew, morale)

        # if x is not the last event press enter to get next event otherwise go to the next phase
        if x != num_events - 1:

            print("Press ENTER to continue")
            input()
            print('')

        # if any resource value is 0 stop event loop and proceed to losing message
        if ((fuel == 0) or (food == 0) or (power == 0) or (hull == 0)
                or (crew == 0) or (morale == 0)):

            break

    return fuel, food, power, hull, crew, morale
示例#5
0
 def __init__(self, w=1200, h=700):
     self.CANVAS_WIDTH = w
     self.CANVAS_HEIGHT = h
     self.pointer = Vector()
     self.initialise()
     self.score = 0
     self.state = State()
     self.waveCount = 1
     self.menu = Menu_Screen()
     self.state.startGame()
     self.waves()
     self.shop = Shop(False, self.enemies, self.player)
     self.hud = hud(True)
     self.frame = simplegui.create_frame('Debt Runners', self.CANVAS_WIDTH,
                                         self.CANVAS_HEIGHT)
     self.frame.set_draw_handler(self.draw)
     self.frame.set_keydown_handler(self.kbd.keyDown)
     self.frame.set_keyup_handler(self.kbd.keyUp)
     self.frame.set_mouseclick_handler(self.click)
     self.frame.set_canvas_background('Gray')
     self.frame.start()
示例#6
0
文件: fight.py 项目: ffists7/fbsim
    def __init__(self, B1, B2):
        self.screen = pygame.display.set_mode((1024,768))

        self.background = pygame.Surface(self.screen.get_size())
        self.background.fill((0, 0, 0))
        self.background = self.background.convert()

        self.events = []

        self.activeRound = round.round()
        #self.activeRound.setB1(B1)
        #self.activeRound.setB2(B2)
        self.activeRound.B1 = B1
        self.activeRound.B2 = B2
        self.currentRoundNumber = 1
        self.max_rounds = 3
        self.fight_winner = None

        self.message_queue_length = 10

        barWidth = self.screen.get_size()[0]/2 - 50
        self.hud = hud.hud(statusBarWidth=barWidth)
示例#7
0
    def __init__(self, profile, **kwargs):
        ss = {"Stopped":{0:[(5,19), (2,0), (11,9)]},
              "Walking":{0:[(6,19), (3,0), (12,9)],
                         1:[(5,19), (2,0), (11,9)]},
              "Jump":  {"keep_last":True,
                        0:[(5,19), (2,1), (11,10)],
                        1:[(5,19), (2,0), (11,9)],
                        2:[(5,20), (2,0), (11,9)],
                        3:[(5,20), (2,0), (11,9)]},
              "JumpFall": {"keep_last":True,
                           0:[(5,19), (2,0), (11,9)],
                           1:[(5,18), (2,0), (11,9)],
                           2:[(5,17), (2,0), (11,9)]},
              "Sitting": {0:[(12,17), (9,0), (18,8)]},
              "GetUp": {"keep_last":True,
                        0:[(12,17), (9,0), (18,8)],
                        1:[(12,17), (9,0), (18,8)],
                        2:[(12,17), (9,0), (18,8)],
                        3:[(12,17), (7,0), (16,8)],
                        4:[(12,17), (6,0), (15,8)],
                        5:[(12,18), (4,0), (13,8)],
                        6:[(12,19), (5,0), (14,8)],
                        7:[(12,19), (7,0), (16,8)]},
              "Kick": {0:[(9,19), (3,0), (12,8)]},
              "InAir": {0:[(10,17), (10,0), (18,8)]}
              }
        AnimateStates.__init__(self, "Player1", 'Stopped',
                               states_setup=ss, ticks_step=2)

        kwargs.update(reflection="player" in option("reflections"),
                      opaque=PLAYER_REFLECTION_OPAQUE,
                      bouncing=10)
        Creature.__init__(self, PLAYER_LIFE, **kwargs)

        self.sounds = {"jump": map(load_sound, aglob("player/jump*.wav")),
                       "laugh": map(load_sound, aglob("player/laugh*.wav")),
                       "scream-death": load_sound("player/scream-death.wav"),
                       "scream-hit": load_sound("player/scream-hit.wav")}

        # Some enemy related settings
        self.headshot_multiplier = 2
        self.headshot_bonus = 0
        self.bounty = 1000

        # Player profile (name, skin, keys, etc)
        self.profile = profile
        self.money = self.earned_money = 0
        self.niceshot_n08 = 0
        self.keysdown = set()

        # Player this game statistics
        self.pstats = {"kills": 0,      # total kills
                       # per enemy kills statistics
                       "enemies": {},
                       # per weapon stats
                       "weapons": {"Pistol": wpn_empty_stats()},
                       "distance": 0,   # distance move
                      }

        # Change the skin
        self.apply_skin()

        # Cross and cross info
        self.font = load_font("default.ttf", MONEY_FONT_SIZE)
        self.font_color = (255, 0, 0, 155)

        # Start position
        self.x, self.y = self.profile["start-at"]
        self.apply_position()

        # Sprites for weapon and its reflection
        self.weapons = [weapons.Pistol(self)]
        self.weapon = self.weapons[0]
        self.field.add(self.weapon)

        # Sprites for crosshair and crosshair info
        if self.profile["crosshair"]:
            self.setup_crosshair()
            self.add(self.cross)

        if self.profile["crosshair-info"]:
            self.cross_info = dirty_sprite()
            self.cross_info._layer = MID_LAYER # above everything
            self.setup_crosshair_info()
            self.add(self.cross_info)

        if self.profile["money-info"]:
            self.money_info = dirty_sprite()
            self.money_info._layer = MID_LAYER # above everything
            self.setup_money_info()
            self.add(self.money_info)

        if self.profile["show-hud"]:
            self.hud = hud(self)
            self.add(self.hud)
示例#8
0
def game_loop():
    '''
    Main game loop
    '''

    # Beginning Values
    fuel = 30
    food = 40
    power = 10
    hull = 6
    crew = 10
    morale = 100
    distance = 25
    g_dist = 20

    # begin game loop
    running = True
    starting = True
    while running:

        # give introduction if this is the first round of play
        if starting:

            fuel, food, power, hull, crew, morale = i.intro(
                fuel, food, power, hull, crew, morale)

            starting = False

        # Display Distance
        h.status(distance, g_dist)

        # Phase 1: Production Phase
        fuel, food, power, hull, crew, morale = p.production_phase(
            fuel, food, power, hull, crew, morale)

        # Display Resources
        h.hud(fuel, food, power, hull, crew, morale)

        # Phase 2: Spend Phase
        fuel, food, power, hull, crew, morale, distance_traveled = s.spend_phase(
            fuel, food, power, hull, crew, morale, g_dist, distance)

        # Check for loss conditions
        if ed.lose(fuel, food, power, hull, crew, morale, g_dist):

            break

        # Phase 3: Event Phase
        fuel, food, power, hull, crew, morale = e.event_phase(
            fuel, food, power, hull, crew, morale)

        # Check for loss conditions
        if ed.lose(fuel, food, power, hull, crew, morale, g_dist):

            break

        # phase 4: Travel Phase
        distance, g_dist = t.travel_phase(distance, distance_traveled, g_dist)

        # Check for win conditions
        if ed.win(distance):

            break

        # Check for loss conditions
        if ed.lose(fuel, food, power, hull, crew, morale, g_dist):

            break
        dinfo.current_w)

    pygame.display.set_mode((dinfo.current_w, dinfo.current_h), video_flags)
    tools.resize((dinfo.current_w, dinfo.current_h))
    tools.GlInit()
    tools.clearScreen()

    eManager = eventmanager.eventmanager()

    mausimaus = maus.maus()

    git = gitter.gitter((dinfo.current_w * FIELD_W_RATIO, dinfo.current_h),
                        eManager, mausimaus, (klick, gong, error))

    sidebar = hud.hud(
        (dinfo.current_w * FIELD_W_RATIO + 2, 2, dinfo.current_w -
         dinfo.current_w * FIELD_W_RATIO - 4, dinfo.current_h - 4), mausimaus,
        font)

    sidebar.setBgColor((0.0, 0.0, 0.5, 0.1))

    clock = pygame.time.Clock()

    curLevel = STARTLEVEL

    #Hauptschleife:
    while not sidebar.isExitClicked():
        tools.clearScreen()

        ticktime = clock.tick(40)

        if sidebar.getMode() == hud.HUD_MODE_MAINMENU:
示例#10
0
def production_phase(fuel, food, power, hull, crew, morale):
    '''
    Main function for production phase
    '''

    # number of crew assigned to each resource
    fuel_crew = 0
    food_crew = 0
    power_crew = 0
    hull_crew = 0
    morale_crew = 0

    # set additional amount subtracted from morale during prodiction test
    fuel_pen = 15
    food_pen = 0
    power_pen = 10
    hull_pen = 20
    morale_pen = 0

    # chance to produce each reasorce
    fuel_chance = (morale - fuel_pen)
    food_chance = (morale - food_pen)
    power_chance = (morale - power_pen)
    hull_chance = (morale - hull_pen)
    morale_chance = (morale - morale_pen)

    # number of resorces produced on success
    fuel_prod = 3
    food_prod = 5
    power_prod = 3
    hull_prod = 1
    morale_prod = 4

    # display information for the beginning of the production phase
    print("Press ENTER to begin the Production Phase!")
    input()

    # display resourse table
    h.hud(fuel, food, power, hull, crew, morale)

    # display chance for success when attempting to produce each resource type
    print(f"You may assign {crew} crew members to produce resources")
    print('')
    print(
        f"Each crew assigned to fuel has a {fuel_chance}% chance to produce {fuel_prod} fuel."
    )
    print(
        f"Each crew assigned to food has a {food_chance}% chance to produce {food_prod} food."
    )
    print(
        f"Each crew assigned to power has a {power_chance}% chance to produce {power_prod} power crystals."
    )
    print(
        f"Each crew assigned to hull has a {hull_chance}% chance to repair {hull_prod} damage to the hull."
    )
    print(
        f"Each crew assigned to morale has a {morale_chance}% chance to improve the crew's morale by {morale_prod}%."
    )
    print('')

    # create loop for assigning crew
    giving_orders = True
    while giving_orders:

        # assign crew to resources
        fuel_crew, food_crew, power_crew, hull_crew, morale_crew = assign_crew(
        )

        # Check for valid input and user validation
        # If input is valid and validated break loop
        # otherwise restart loop and reassign crew
        if check_crew_assignment(fuel_crew, food_crew, power_crew, hull_crew,
                                 morale_crew, crew):
            break

    # get generated resources and display them
    fuel_gen, food_gen, power_gen, hull_gen, morale_gen = generate(
        fuel_crew, food_crew, power_crew, hull_crew, morale_crew, fuel_chance,
        food_chance, power_chance, hull_chance, morale_chance, fuel_prod,
        food_prod, power_prod, hull_prod, morale_prod)

    # add generated resources to total resource
    fuel += fuel_gen
    food += food_gen
    power += power_gen
    hull += hull_gen
    morale += morale_gen

    # check for capped resources
    fuel, food, hull, power, morale = is_capped(fuel, food, hull, power,
                                                morale)

    return fuel, food, power, hull, crew, morale