def generateplatforms(self, initial): y = 900 # Generate from bottom of the screen start = -100 if (initial == True): self.startY = -100 # Fill starting screen with platforms while (y > -70): p = Platform.Platform() p.getKind(self.score) p.y = y p.startY = start self.platforms.append(p) y -= 30 # Generate every 30 pixels start += 30 self.startY = start else: # Creates a platform based on current score p = Platform.Platform() if (self.score <= 2500): difficulty = 50 elif (self.score < 4000): difficulty = 60 else: difficulty = 70 p.y = self.platforms[-1].y - difficulty self.startY += difficulty p.startY = self.startY p.getKind(self.score) self.platforms.append(p)
def new(self): self.result = 0 self.objects = pg.sprite.Group() self.platforms = pg.sprite.Group() self.players = pg.sprite.Group() self.player = Player(self) self.player.set_image("p1_front.png") self.players.add(self.player) self.objects.add(self.player) p1 = Platform(0, 560, WIDTH, 40) p2 = Platform(200, 464, 100, 20) p3 = Platform(125, 348, 80, 20) p4 = Platform(350, 232, 90, 20) p5 = Platform(175, 116, 110, 20) self.objects.add(p1) self.objects.add(p2) self.objects.add(p3) self.objects.add(p4) self.objects.add(p5) self.platforms.add(p1) self.platforms.add(p2) self.platforms.add(p3) self.platforms.add(p4) self.platforms.add(p5) self.run()
def initPlatforms(self): """Create and add platforms to platformList""" myPlatform = Platform.Platform((255, 0, 0), 10) self.platformList.append(myPlatform) myPlatform = Platform.Platform((255, 255, 0), 115) self.platformList.append(myPlatform) myPlatform = Platform.Platform((0, 0, 255), 220) self.platformList.append(myPlatform)
def update(self): # game loop - update self.all_sprites.update() # check collision only when falling downwards if self.player.velocity.y > 0: collision = pg.sprite.spritecollide(self.player, self.platforms, False) if collision: self.player.position.y = collision[0].rect.top + 1 self.player.velocity.y = 0 self.player.jump() # if player reaches top of the screen if self.player.rect.top <= HEIGHT / 4: self.player.position.y += abs(self.player.velocity.y) for platform in self.platforms: platform.rect.y += abs(self.player.velocity.y) # delete platform if goes off the screen if platform.rect.top >= HEIGHT: platform.kill() # spawn new platforms while len(self.platforms) < 6: plat_width = random.randrange(50, 100) platform = Platform(random.randrange(0, WIDTH - plat_width), random.randrange(-30, -20), plat_width, 15) self.platforms.add(platform) self.all_sprites.add(platform)
def add_rotating_platform(self, position, radius=2, platform_width=1, T=600, color=(50, 50, 50)): height = 10 * S R = radius * box_size * 2 width = platform_width * box_size * 2 # top will be at same level as floor for position[1] = 0 pos = np.array(position, dtype='float') * (box_size * 2.0) + [ 0, floor + height ] path = [ np.array([ pos[0] + R * math.cos(2 * math.pi * x / T), pos[1] + R * math.sin(2 * math.pi * x / T) ]) for x in range(T) ] self.master_platform_list.append( Platform.Moving_Platform([width, height], copy.copy(path), color=color)) self.master_platform_list.append( Platform.Moving_Platform([width, height], path[int(T / 2):] + path[:int(T / 2)], color=color)) self.background_list.append(Platform.Platform(pos, [height, height]))
def __init__(self, name, time_stamp, header=None): self._platform = Platform.Platform() self._os = OS.OS() self._name = name self._ERR_FILE_EXIST = "ERROR: Log file '%s' already exists" % name self._ERR_FILE_OPEN = "ERROR: Unable to open log file '%s'" % name if self._os.is_file(name): raise Error.Error(msg=self._ERR_FILE_EXIST) else: try: f = open(name, 'w') except IOError: raise Error.Error(msg=self._ERR_FILE_OPEN) if header != None: f.write("%s\n" % header) line = "Generated %s" % time_stamp.as_string() f.write(line+"\n\n") line = "System: %s" % self._platform.system() f.write(line+"\n") line = "Python version: %s" % self._platform.python_version() f.write(line+"\n") line = ("Python implementation: %s" % self._platform.python_implementation()) f.write(line+"\n\n") f.close()
def addPlatforms(self, platforms): for platform in platforms: block = Platform(platform[0]) block.rect.x = platform[1] block.rect.y = platform[2] block.player = self.player self.platform_list.add(block)
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.background = pygame.image.load("background_01.png").convert() self.background.set_colorkey(constants.WHITE) self.level_limit = -2500 # Array with type of platform, and x, y location of the platform. level = [[500, 500, Platform.GRASS_LEFT]] # Go through the array above and add platforms for platform in level: block = Platform.Platform(platform[0], platform[1], platform[2], "tiles_spritesheet.png") block.player = self.player self.platform_list.add(block) # Add a custom moving platform block = Platform.Moving_Platform(1350, 280, Platform.STONE_PLATFORM_MIDDLE, "tiles_spritesheet.png") block.boundary_left = 1350 block.boundary_right = 1600 block.change_x = 1 block.player = self.player block.level = self self.platform_list.add(block)
def new(self): # start a new game self.all_sprites = pg.sprite.Group() self.platforms = pg.sprite.Group() self.player = Player(self) for plat in PLATFORM_LIST: Platform(plat[0], plat[1], plat[2], plat[3], self) self.run()
def map_level_5(self):# 5번 맵 로딩 함수 self.coin = 5 #몬스터 self.monster.append(Monster.Monster("mouse",1900,300, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 300, 2400)) self.monster.append(Monster.Monster("wormGreen",2400,300, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 300, 2400)) self.monster.append(Monster.Monster("bee",1100,450, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 300, 1200)) self.monster.append(Monster.Monster("bee",600,450, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 1200, 2400)) self.monster.append(Monster.Monster("bee",500,1000, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 600, 1200)) self.monster.append(Monster.Monster("bee",800,1000, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 1200, 2400)) #플랫폼 self.platform.append(Platform.Platform("thunder",1080,900, CHARACTER_SCALING * 0.5,fall = True, die = True)) #2층에서 내리는 번개 self.platform.append(Platform.Platform("doorClosed_mid",2400,290, CHARACTER_SCALING * 0.5, teleport = True)) #아래 텔레포트 self.platform.append(Platform.Platform("doorClosed_mid",50,610, CHARACTER_SCALING * 0.5, teleport = False)) #윗 텔레포트 #3층 번개 for i in range(1): self.platform.append(Platform.Platform("thunder",288+ (i*128),800, CHARACTER_SCALING * 0.5, fall = True, die = True)) for i in range(1): self.platform.append(Platform.Platform("thunder",358+ ( (14 + i)*64),800, CHARACTER_SCALING * 0.5, fall = True, die = True)) self.platform.append(Platform.Platform("thunder",1900,820, CHARACTER_SCALING, fall = True, die = True)) self.platform.append(Platform.Platform("bridgeA",400,930, CHARACTER_SCALING * 0.5,PLATFORM_MOVEMENT_SPEED*4, 400, 2200, hard_platform = True)) #몬스터 for i in range(len(self.monster)): self.monster_sprite.append(self.monster[i].newMonster()) self.monster_list.append(self.monster_sprite[i]) #플랫폼 for i in range(len(self.platform)): self.platform_sprite.append(self.platform[i].newPlatform()) self.platform_list.append(self.platform_sprite[i])
def map_level_2(self):# 2번 맵 로딩 함수 self.coin = 4 self.monster.append(Monster.Monster("bee",800,420, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED, 800, 930)) for i in range(len(self.monster)): self.monster_sprite.append(self.monster[i].newMonster()) self.monster_list.append(self.monster_sprite[i]) self.platform.append(Platform.Platform("rock",690,700, CHARACTER_SCALING * 0.5, fall = True, die = True)) for i in range(len(self.platform)): self.platform_sprite.append(self.platform[i].newPlatform()) self.platform_list.append(self.platform_sprite[i])
def add_floor(self, start, stop, color=platform_color, line_color=(0, 0, 0), line_width=2): self.master_platform_list.append( Platform.Platform([(start + stop) * box_size, floor + 50 * S], [(stop - start + 1) * box_size, 50 * S], color, line_color, line_width))
def map_level_3(self):# 3번 맵 로딩 함수 self.coin = 4 self.monster.append(Monster.Monster("bee",400,150, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*2, 300, 1000)) self.platform.append(Platform.Platform("bridgeA",400,50, CHARACTER_SCALING * 0.5,PLATFORM_MOVEMENT_SPEED, 300, 1200, hard_platform = True)) for i in range(len(self.platform)): self.platform_sprite.append(self.platform[i].newPlatform()) self.platform_list.append(self.platform_sprite[i]) for i in range(len(self.monster)): self.monster_sprite.append(self.monster[i].newMonster()) self.monster_list.append(self.monster_sprite[i])
def new(self): # start new game self.all_sprites = pg.sprite.Group() self.platforms = pg.sprite.Group() self.player = Player(self) self.all_sprites.add(self.player) for platform in PLATFORM_LIST: platform_to_add = Platform(*platform) self.all_sprites.add(platform_to_add) self.platforms.add(platform_to_add) self.run()
def add_platform(self, start, stop, y_pos, color=platform_color, line_color=(0, 0, 0), line_width=2): self.master_platform_list.append( Platform.Platform([(start + stop) * box_size, -y_pos * 2.0 * box_size + floor + 10 * S], [(stop - start + 1) * box_size, 10 * S], color, line_color, line_width))
def add_scenery(self, theme='clouds'): if theme == 'clouds': for k in range(0, 100, 10): for j in range(2): p = Platform.Platform( [((k - 50) * 100 * S + 50 * randint(-10, 10)) * S, 40 * S + (j * 40 + randint(-15, 15)) * S], [4 * randint(5, 20) * S, randint(5, 20) * S], color=white) p.solid = False p.corporeal = False self.scenery.append(p)
def map_level_4(self):# 4번 맵 로딩 함수 self.coin = 6 self.monster.append(Monster.Monster("bee",156,430, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 156, 348)) self.monster.append(Monster.Monster("bee",1000,430, CHARACTER_SCALING * 0.5, MONSTER_MOVEMENT_SPEED*3, 800, 1000)) self.platform.append(Platform.Platform("rock",1050, 1160, CHARACTER_SCALING * 0.5,fall = True, die = True)) #몬스터 for i in range(len(self.monster)): self.monster_sprite.append(self.monster[i].newMonster()) self.monster_list.append(self.monster_sprite[i]) #플랫폼 for i in range(len(self.platform)): self.platform_sprite.append(self.platform[i].newPlatform()) self.platform_list.append(self.platform_sprite[i])
def randomMap(): platform_sources = [('./resources/graphicals/stage_bottom.png', (0, 0))] h = random.randint(220, 275) while h + 130 < HEIGHT: pic, wth = random.choice(sources) x = random.randint(0, WIDTH - wth) platform_sources.append((pic, (x, h))) h += random.randint(80, 240) index = 0 for i, (x, y) in platform_sources: img = pygame.image.load(i) obj = Platform(index, img, x, y) index += 1 list_platform.append(obj) mapping()
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) # Array with width, height, x, and y of platform level = [[210, 70, 500, 500], [210, 70, 200, 400], [210, 70, 600, 300], [250, 70, 500, 300], [100, 100, 250, 250], [50, 50, 100, 100]] # Go through the array above and add platforms for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block)
def createObstaclePlatforms(x): '''rows = random.randint(2, 5) rowspacing = 720 / rows rowoffset = rowspacing / 3 - 360 maxwidth = random.randint(300, 600) for r in range(rows): cols = random.randint(1, 2) colspacing = random.randint(25, 50) colwidth = (maxwidth - 2 * colspacing) / cols y = r * rowspacing + rowoffset if r == 0 or random.randint(0, 1) == 0: for c in range(cols): Platform.instances.append(Platform(x + (colspacing * (c + 1)) + ((colwidth - colspacing) * c), y, colwidth, 50)) ''' '''rows = random.randint(2, 4) rowspacing = 720 / rows rowoffset = rowspacing / 3 - 360 maxwidth = random.randint(500, 700) count = 0 for r in range(rows): if random.randint(0, 2) < 2: y = r * rowspacing + rowoffset colwidth = random.randint(maxwidth / 2, maxwidth) Platform.instances.append(Platform(x + maxwidth / 2, y, colwidth, 25)) count += 1 if count == 0: y = random.randint(-360, 220) Platform.instances.append(Platform(x + maxwidth / 2, y, maxwidth, 25)) return maxwidth + random.randint(20, 50)''' #width = random.randint(350, 500) width = noise.pnoise1( (ObstacleFactory.seed1 + x + 0.5) / 1000) * 150 + 300 spacing = random.randint(140, 240) y = noise.pnoise1((ObstacleFactory.seed2 + x + 0.5) / 1) * 330 Platform.instances.append(Platform(x + width / 2, y, width, 25)) return width + spacing
def create(self, platforms, buttons, spikes, goals, clones): # Adds clones that aren't part of the spawn point as platforms clone_list = pygame.sprite.Group() for platform in clones: block = Clone.Clone(platform[4], platform[5]) block.rect.x = platform[2] block.rect.y = platform[3] clone_list.add(block) pygame.sprite.spritecollide(self.player, clone_list, True) for clone in clone_list: self.platform_list.add(clone) # Go through the array above and add platforms for platform in platforms: block = plat.Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] self.platform_list.add(block) for button in buttons: if platform == button[1]: but = bt.Button(self.player, clone_list, block, self) but.rect.x = button[0][0] but.rect.y = button[0][1] self.button_list.add(but) for spike in spikes: block = sp.Spike(spike[2]) block.rect.x = spike[0] block.rect.y = spike[1] self.spike_list.add(block) for goal in goals: block = gl.Goal(goal[0], goal[1]) block.rect.x = goal[2] block.rect.y = goal[3] self.goal_list.add(block)
def update(self): # rekurencja self.objects.update(self.dt) if (self.player.pos_y - 20) <= HEIGHT / 4: self.player.pos_y += abs(self.player.velocity_y) for platforma in self.platforms: platforma.rect.y += abs(self.player.velocity_y) if platforma.rect.top >= HEIGHT: platforma.kill() self.result += 1 if self.player.pos_y > HEIGHT: for obiekt in self.objects: obiekt.rect.y -= self.player.velocity_y if obiekt.rect.bottom < 0: obiekt.kill() if len(self.platforms) == 0: self.playing = False while len(self.platforms) < 6: p = Platform(random.randrange(70, 400), -30, 90, 20) self.platforms.add(p) self.objects.add(p)
#if not gm.is_done(): gm.update() #elif not mm.is_done(): # gm.clear() # mm.update() #___________ '''ADD ALL''' #IKE = Ike() #link2 = Link() #Player1 = Player() Player1 = Bex() Plat = Platform((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2), 30, 20, "platform") all_sprites = pygame.sprite.Group() playing_char = pygame.sprite.Group() platforms = pygame.sprite.Group() playing_char.add(Player1) all_sprites.add(Player1) platforms.add(Plat) all_sprites.add(Plat) #- - - - - Test - - - - - counter = 1 lst = []
import RPi.GPIO as GPIO import time import Platform if __name__ == "__main__": GPIO.setwarnings(False) movement = Platform.Platform() # FORWARD print "FORWARD" movement.state(1) movement.setVelocity(75) time.sleep(2) # STOP print "STOP" movement.state(0) time.sleep(2) # BACKWARD print "BACKWARD" movement.state(2) movement.setVelocity(75) time.sleep(2) # STOP print "STOP" movement.state(0)
def __init__(self): pyxel.init(WIDTH, HEIGHT, caption="Pyxel Lemmings") pyxel.load("assets/SPRITES.pyxres") #pyxel.playm(0,loop=True) # PLAYING BACKGROUND MUSIC self.cursorX, self.cursorY = 0, 32 # INITIAL VALUES OF USER POINTER # GOD MODE: WHEN ACTIVATED, YOU CAN ADD PLATFORMS WHILE THE GAME IS RUNNING # AND YOU CAN STOP TIME OF LEMMINGS (stopping time variable is called ZAWARUDO) self.god_mode = False self.zawarudo = False # FIRST STEP: CREATING THE BOARD: we use the method of filling # a list with lists and creating a matrix self.cellrow = int(WIDTH / 16) self.cellcolumn = int(HEIGHT / 16) self.boardmatrix = [] for i in range(self.cellrow): self.boardmatrix.append([]) for j in range(self.cellcolumn): cell = Cell(i, j) ## using Cell from Cell module self.boardmatrix[i].append(cell) #INITIALIZING SCORE CLASS self.myscore = Score() ## using Score from Score module ## CREATING SUPERFLOOR: this is for ensuring lemmings that fall to the bottom ## of the board dont crash the game. If you want the lemmings to die when ## reaching the bottom of the board, you can activate this code ## commented below, creating lava cells at the bottom of the board ## (see lava module for further info): """ for i in range(self.cellcolumn): cellcheck=self.boardmatrix[i][int(self.cellcolumn) - 1] cellcheck.cellclass= Lava(i, (int(self.cellcolumn) - 1)) """ for i in range(self.cellcolumn): cellcheck = self.boardmatrix[i][int(self.cellcolumn) - 1] cellcheck.cellclass = Platform(i, (int(self.cellcolumn) - 1)) # SECOND STEP: CREATING THE PLATFORMS ## fixed values for starting platform x pos self.available_column_positions = (48, 80, 112, 144, 176, 208, 240) ## fixed values for starting platform y pos self.available_row_positions = (0, 16, 32, 48, 64, 80, 96, 112) ## list with all the platforms self.platforms = [] for i in range(0, TOTAL_PLATFORMS): ##first we create a start platform of 16x16 and then we extend it xposition = self.available_row_positions[random.randint(0, 7)] yposition = self.available_column_positions[i] boardplatform_start = Platform(xposition, yposition) ###assigning the platform to the cell self.boardmatrix[int(xposition / 16)][int( yposition / 16)].cellclass = Platform(xposition, yposition) self.platforms.append(boardplatform_start) length_of_floor = random.randint(4, 7) ###EXTENDING THE PLATFORMS for i in range(0, length_of_floor): xposition += 16 boardplatform_prolong = Platform(xposition, yposition) self.boardmatrix[int(xposition / 16)][int( yposition / 16)].cellclass = Platform( xposition, yposition) self.platforms.append(boardplatform_prolong) # THIRD STEP: CREATE ENTRANCE AND EXIT GATES FOR THE LEMMINGS platcounter = len(self.platforms) ##ENTRY GATE self.entrygate_platform = self.platforms[random.randint( 0, platcounter - 1)] entrygate_final_xpos = self.entrygate_platform.platform_x entrygate_final_ypos = self.entrygate_platform.platform_y self.entrygate = Entrygate(entrygate_final_xpos, entrygate_final_ypos - 16) ### assigning the gate to a cell self.boardmatrix[int(entrygate_final_xpos / 16)][int( (entrygate_final_ypos - 16) / 16)].cellclass = Entrygate( entrygate_final_xpos, entrygate_final_ypos - 16) ##EXITGATE self.exitgate_platform = self.platforms[random.randint( 0, platcounter - 1)] ### HERE WE ENSURE THAT THE GATES DON'T OVERLAP THEMSELVES AND THAT THEY ARE IN DIFFERENT FLOORS while (self.exitgate_platform == self.entrygate_platform or self.exitgate_platform.platform_y == self.entrygate_platform.platform_y): self.exitgate_platform = self.platforms[random.randint( 0, platcounter)] exitgate_final_xpos = self.exitgate_platform.platform_x exitgate_final_ypos = self.exitgate_platform.platform_y self.exitgate = Exitgate(exitgate_final_xpos, exitgate_final_ypos - 16) ### assigning the gate to a cell self.boardmatrix[int(exitgate_final_xpos / 16)][int( (exitgate_final_ypos - 16) / 16)].cellclass = Exitgate( exitgate_final_xpos, exitgate_final_ypos - 16) # INITIALIZING THE LEMMINGS LISTS: self.list_of_lemmings = [] self.list_of_appeared_lemmings = [] pyxel.run(self.update, self.draw)
def setUp(self): self.options, self.args = Options.parseCommandLine([]) self.config = Config.Config() self.platform = Platform.Platform(self.config, "symbian")
a4 = Agent(r4, q_init, q_goal) # # agent 5 # r5 = HyQ('aunty') # r5.setInit(9, 2) # q_init = r5.getCurrentConfig() # q_goal = q_init[::] # q_goal[0] = -18 # q_goal[1] = -1.7 # q_goal[2] = 0 # q_goal[3] = -1 # a5 = Agent(r5, q_init, q_goal) # platform pl = Platform([a1, a2, a3, a4]) air = Airplane("air") pl.setEnvironment(air) pl.start() pl.r.client.gui.addLight('0_scene_hpp_/x', pl.r.windowId, 0.1, [1, 1, 1, 1]) pl.r.client.gui.applyConfiguration('0_scene_hpp_/x', [-3, 0, 7, 1, 0, 0, 0]) pl.r.client.gui.setColor('air', [1, 1, 1, 0.5]) pl.r.client.gui.refresh() print 'start the searching with ', pl.tree.getAgentsRemained(), ' remained' (result, plans) = pl.construct_tree(100) a1.setPermittedPlan(plans[0])
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # """ Generic interface for handling compatibility issues between python 2 and python3 """ import abc import Error import Platform platform = Platform.Platform() if platform.is_python2(): import __builtin__ as builtins ABC = abc.ABCMeta('ABC', (), {}) if platform.is_python3(): import builtins ABC = abc.ABC def range(*args): """ Wrapper for range usage, returning an iterator regardless of if python 2 or python 3 is used """
def build_level(self, Level): # build the level self.player_list.empty() self.player = Level().player self.player_list.add(self.player) self.player.ball_list = pygame.sprite.Group() self.invincible_enemy_list.empty() self.jump_blocks_list.empty() self.exit_blocks_list.empty() self.kill_blocks_list.empty() self.fake_blocks_list.empty() self.coin_list.empty() self.enemy_list.empty() self.platform_list.empty() self.enemy_platform_list.empty() self.enemy_list.add(Level().enemies) self.invincible_enemy_list.add(Level().invincible_enemies) x = y = 0 for row in Level().level: for col in row: if col == "P": p = Platform(x, y) self.platform_list.add(p) #self.enemy_platform_list.add(p) if col == "R": r = EnemyPlatform(x, y) self.platform_list.add(r) self.enemy_platform_list.add(r) if col == "X": e = ExitBlock(x, y) self.exit_blocks_list.add(e) if col == "J": j = JumpBlock(x, y) self.jump_blocks_list.add(j) if col == "S": s = Structure(x, y) self.platform_list.add(s) if col == "Q": q = EnemyStructure(x, y) self.platform_list.add(q) self.enemy_platform_list.add(q) if col == "K": k = KillBlock(x, y) self.kill_blocks_list.add(k) #self.enemy_platform_list.add(k) if col == "I": i = InvisibleBlock(x, y) self.enemy_platform_list.add(i) if col == "B": b = Brick(x, y) self.platform_list.add(b) #self.enemy_platform_list.add(b) if col == "U": u = KillBlock2(x, y) self.kill_blocks_list.add(u) self.enemy_platform_list.add(u) if col == "E": e = Enemy(x, y, 'normal') self.enemy_list.add(e) if col == "Z": z = Enemy(x, y, 'invincible') self.invincible_enemy_list.add(z) if col == "C": c = Coin(x, y) self.coin_list.add(c) if col == "F": f = FakePlatform(x, y) self.fake_blocks_list.add(f) x += PLATFORM_WIDTH y += PLATFORM_HEIGHT x = 0 self.total_level_width = len(Level().level[0]) * PLATFORM_WIDTH self.total_level_height = len(Level().level) * PLATFORM_HEIGHT
def main(): """The main game function that contains all the game attributes and the main game loop. """ pygame.init() FPS = 30 fps_clock = pygame.time.Clock() SCREENSIZE = (800, 600) screen = pygame.display.set_mode(SCREENSIZE) pygame.display.set_caption("Journey to the West") pygame.mouse.set_visible(False) background = Background.Background((800, 600)) platform = Platform.platformGroup() player = Player.Player((-100, 0)) moveL = False moveR = False gameIdle = True gameContinue = True gamePause = False gamePrompt = 0 endGameCounter = 100 pygame.mixer.music.load('bg.ogg') pygame.mixer.music.set_endevent(USEREVENT) pygame.mixer.music.play() fullscreen = False fileCount = 1 while True: # fileName = 'screen' + str(fileCount) + '.jpg' # fileCount = fileCount + 1 # if fileCount % 10 == 1: # pygame.image.save(screen, fileName) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == USEREVENT: pygame.mixer.music.play() if (event.type == KEYDOWN and event.key == K_RETURN and (pygame.key.get_mods() & KMOD_ALT)): if fullscreen: fullscreen = False screen = pygame.display.set_mode(SCREENSIZE) else: fullscreen = True screen = pygame.display.set_mode(SCREENSIZE, FULLSCREEN) if gameContinue: gamePrompt = player.prompt if gameIdle: if event.type == KEYDOWN and event.key == K_RETURN: gameIdle = False player.unhideHeart() elif gamePause: if event.type == KEYDOWN: if event.key == K_p: gamePause = False if event.key == K_q: pygame.quit() sys.exit() else: if event.type == KEYDOWN: if event.key == K_EQUALS: player.increaseHealth() if event.key == K_RIGHT: moveR = True if event.key == K_LEFT: moveL = True if event.key == K_SPACE: player.jump() if event.key == K_p: gamePause = True if event.key == K_RETURN: if gamePrompt != 0: gamePrompt = 0 player.prompt = 0 if event.type == KEYUP: if event.key == K_RIGHT: moveR = False if event.key == K_LEFT: moveL = False else: if event.type == KEYDOWN: if event.key == K_r: background = Background.Background((800, 600)) platform = Platform.platformGroup() player = Player.Player((150, 200)) gameContinue = True moveL = False moveR = False if event.key == K_q: pygame.quit() sys.exit() if gameContinue: if gameIdle: player.hideHeart() player.land(platform.platList(), Platform.Platform(1, (13000, 3))) background.update(screen) player.update(screen) demo(screen) platform.update(screen) if not player.moveR(): background.moveR() elif gamePause: #prompt('cigar', screen) pause(screen) elif gamePrompt != 0: if gamePrompt == 1: prompt('fat', screen) elif gamePrompt == 2: prompt('salt', screen) elif gamePrompt == 3: prompt('cigar', screen) elif gamePrompt == 4: prompt('couch', screen) else: if moveL: player.moveL() if moveR: if not player.moveR(): background.moveR() platform.moveR() screen.fill((0, 0, 0)) player.land(platform.platList(), platform.finalPlat()) player.enemyCollision(platform.monList()) player.fruitCollison(platform.fruList()) player.fireballCollison(platform.fireList()) if player.gameOver() or player.win(): gameContinue = False background.update(screen) platform.update(screen) player.update(screen) else: if endGameCounter == 0: gameIdle = True background = Background.Background((800, 600)) platform = Platform.platformGroup() player = Player.Player((150, 200)) gameContinue = True moveL = False moveR = False endGameCounter = 100 else: endGameCounter -= 1 if player.win(): gameWon(screen) else: gameOver(screen) pygame.display.update() fps_clock.tick(FPS)