def main(): # Initialize pygame pygame.init() ###################################################################### #SETTINGS screenWidth = 800 screenHeight = 600 FPS = 30 # timeDelay = 50 DEPRECATED #Creates window, and clock, sets Icon screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("Dungeon Taker: OTA") icon = pygame.image.load('images/oubliette.png') pygame.display.set_icon(icon) clock = pygame.time.Clock() ###################################################################### player = character.Character() running = True def drawHandling(): #this function handles the drawing in layers #RGB VALUES screen.fill((0, 0, 0)) # pDraw() floor_sprites.draw(screen) all_sprites.draw(screen) wall_sprites.draw(screen) collision_sprites.draw(screen) attack_sprites.draw(screen) # def spawn_handling(): # if player.attack == True: # print("spawn thing now") # attack = character.Player_Attack(player.direction, player, 10) # all_sprites.add(attack) # player.attack = False # return(attack) # sprite groups! <3 floor_sprites = pygame.sprite.Group() wall_sprites = pygame.sprite.Group() attack_sprites = pygame.sprite.Group() all_sprites = pygame.sprite.Group() collision_sprites = pygame.sprite.Group() enemy_sprites = pygame.sprite.Group() all_sprites.add(player) #get a list of sprites with built in location information dungeonTiles = roomLib.drawTestRoom() for tile in dungeonTiles: if tile.tile_type == 1: floor_sprites.add(tile) if tile.tile_type == 0: wall_sprites.add(tile) # Sad cyril attempt at populating world with enemies. # I guess I wasn't cut out for populating the world. OUCH! # def populate_with_enemies(): # testRoom = roomLib.testRoom # for y in range(1, (len(testRoom)) - 1, 1): # for x in range(1, (len(testRoom[y])) - 1, 1): # print("this is x", x) # print("this is y", y) # if testRoom[y][x] == 1: # print("y,x = 1") # # if roomLib.searchTest(testRoom, x, y, 5, 5) == True: # # print("search returned true") # fly_y = (y*40) + 20 # fly_x = (x*40) + 20 # fly_holder = enemy.Fly(fly_y,fly_x) # print("fly created at,", x, ",", y) # return fly_holder # flyTest = populate_with_enemies() fly_list = [] for i in range(0, 600, 1): y = ((random.randint(1, 13)) * 40) + 20 x = ((random.randint(1, 18)) * 40) + 20 fly_list.append(enemy.Fly(x, y)) print("Made a new fly!") for fly in fly_list: enemy_sprites.add(fly) all_sprites.add(fly) colls = fly.coll_boxes for box in colls: collision_sprites.add(box) # roomLib.procRoomX() coll_boxes = player.coll_list for box in coll_boxes: collision_sprites.add(box) # testing fly collision # Loading area for rooms # A state machine for managing the main game loop while running: clock.tick(FPS) # pygame.time.delay(timeDelay) DEPRECATED #Update all_sprites.update() # attack = spawn_handling() if player.attack == True: # print("spawn thing now") attack = character.Player_Attack(player.direction, player, 10) attack_sprites.add(attack) # all_sprites.add(attack) player.attack = False attack_sprites.update() collision_sprites.update() wall_sprites.update() running = player.game_running hits = pygame.sprite.groupcollide(collision_sprites, wall_sprites, False, False) if player.top_box in hits: player.collide_up = True else: player.collide_up = False if player.bottom_box in hits: player.collide_down = True else: player.collide_down = False if player.left_box in hits: player.collide_left = True else: player.collide_left = False if player.right_box in hits: player.collide_right = True else: player.collide_right = False # and now, for the fly object for fly in fly_list: if fly.top_box in hits: fly.go_up = False if fly.bottom_box in hits: fly.go_up = True if fly.left_box in hits: fly.go_left = False if fly.right_box in hits: fly.go_left = True ticks = pygame.sprite.groupcollide(enemy_sprites, attack_sprites, True, False) for fly in fly_list: if fly in ticks: print("YEEEEETT") if player in ticks: print("scored a hit") if ticks: print("the fly is hit!") # Draw / render drawHandling() pygame.display.flip() return ("END")
# sprite groups! <3 floor_sprites = pygame.sprite.Group() wall_sprites = pygame.sprite.Group() attack_sprites = pygame.sprite.Group() all_sprites = pygame.sprite.Group() collision_sprites = pygame.sprite.Group() enemy_sprites = pygame.sprite.Group() all_sprites.add(player) # get a list of sprites with built in location information flyTest = enemy.Fly() enemy_sprites.add(flyTest) flyList = [flyTest] all_sprites.add(flyTest) roomLib.procRoomX() dungeonTiles = roomLib.drawTestRoom() for tile in dungeonTiles: if tile.tile_type == 1: floor_sprites.add(tile) if tile.tile_type == 0: wall_sprites.add(tile) coll_boxes = player.coll_list for box in coll_boxes: collision_sprites.add(box) colls = flyTest.coll_boxes for box in colls: collision_sprites.add(box) # testing fly collision
def main(): # Image and Sound directories img_dir = path.join(path.dirname(__file__), "images") snd_dir = path.join(path.dirname(__file__), "sounds") # Initialize pygame pygame.init() pygame.mixer.init() ###################################################################### #SETTINGS screenWidth = 800 screenHeight = 600 FPS = 30 # timeDelay = 50 DEPRECATED #Creates window, and clock, sets Icon screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("Dungeon Taker: OTA") icon = pygame.image.load('images/oubliette.png') pygame.display.set_icon(icon) clock = pygame.time.Clock() ###################################################################### # Loading game sounds bug_splat_sound = pygame.mixer.Sound(path.join(snd_dir, "bug_splat.wav")) swoosh_sounds = [] for snd in ["swoosh_one.wav", "swoosh_two.wav"]: swoosh_sounds.append(pygame.mixer.Sound(path.join(snd_dir, snd))) pygame.mixer.music.load(path.join(snd_dir, "python_project_level.wav")) pygame.mixer.music.set_volume(0.8) player = character.Character() running = True def drawHandling(): #this function handles the drawing in layers #RGB VALUES screen.fill((0, 0, 0)) # pDraw() floor_sprites.draw(screen) all_sprites.draw(screen) wall_sprites.draw(screen) collision_sprites.draw(screen) attack_sprites.draw(screen) # def spawn_handling(): # if player.attack == True: # print("spawn thing now") # attack = character.Player_Attack(player.direction, player, 10) # all_sprites.add(attack) # player.attack = False # return(attack) # sprite groups! <3 floor_sprites = pygame.sprite.Group() wall_sprites = pygame.sprite.Group() attack_sprites = pygame.sprite.Group() all_sprites = pygame.sprite.Group() collision_sprites = pygame.sprite.Group() enemy_sprites = pygame.sprite.Group() all_sprites.add(player) #get a list of sprites with built in location information basic_chaserTest = enemy.Basic_Chaser() flyTest = enemy.Fly() enemy_sprites.add(basic_chaserTest) enemy_sprites.add(flyTest) flyList = [flyTest] all_sprites.add(basic_chaserTest) all_sprites.add(flyTest) # roomLib.procRoomX() dungeonTiles = roomLib.drawTestRoom() for tile in dungeonTiles: if tile.tile_type == 1: floor_sprites.add(tile) if tile.tile_type == 0: wall_sprites.add(tile) coll_boxes = player.coll_list for box in coll_boxes: collision_sprites.add(box) colls = flyTest.coll_boxes for box in colls: collision_sprites.add(box) colls = basic_chaserTest.coll_boxes for box in colls: collision_sprites.add(box) # testing fly collision # Loading area for rooms # A state machine for managing the main game loop while running: clock.tick(FPS) # pygame.time.delay(timeDelay) DEPRECATED #Update all_sprites.update() # attack = spawn_handling() if player.attack == True: # print("spawn thing now") attack = character.Player_Attack(player.direction, player, 10) attack_sprites.add(attack) # all_sprites.add(attack) player.attack = False attack_sprites.update() collision_sprites.update() wall_sprites.update() running = player.game_running hits = pygame.sprite.groupcollide(collision_sprites, wall_sprites, False, False) # and now for the chaser object if basic_chaserTest.top_box in hits: basic_chaserTest.go_up = False else: basic_chaserTest.go_up = True if basic_chaserTest.bottom_box in hits: basic_chaserTest.go_down = False else: basic_chaserTest.go_down = True if basic_chaserTest.left_box in hits: basic_chaserTest.go_left = False else: basic_chaserTest.go_left = True if basic_chaserTest.right_box in hits: basic_chaserTest.go_right = False else: basic_chaserTest.go_right = True if player.top_box in hits: player.collide_up = True else: player.collide_up = False if player.bottom_box in hits: player.collide_down = True else: player.collide_down = False if player.left_box in hits: player.collide_left = True else: player.collide_left = False if player.right_box in hits: player.collide_right = True else: player.collide_right = False # and now, for the fly object if flyTest.top_box in hits: flyTest.go_up = False # Cyril added random direction and angle x = random.randint(1, 2) if x == 1: flyTest.go_left = True else: flyTest.go_left = False k = random.randint(1, 4) if k == 1: flyTest.vert_angle = True flyTest.lat_angle = False elif k == 2: flyTest.vert_angle = False flyTest.lat_angle = True else: flyTest.vert_angle = True flyTest.lat_angle = True if flyTest.bottom_box in hits: flyTest.go_up = True # Cyril added random direction and angle x = random.randint(1, 2) if x == 1: flyTest.go_left = True else: flyTest.go_left = False k = random.randint(1, 4) if k == 1: flyTest.vert_angle = True flyTest.lat_angle = False elif k == 2: flyTest.vert_angle = False flyTest.lat_angle = True else: flyTest.vert_angle = True flyTest.lat_angle = True if flyTest.left_box in hits: flyTest.go_left = False # Cyril added random direction and angle x = random.randint(1, 2) if x == 1: flyTest.go_up = True else: flyTest.go_up = False k = random.randint(1, 4) if k == 1: flyTest.vert_angle = True flyTest.lat_angle = False elif k == 2: flyTest.vert_angle = False flyTest.lat_angle = True else: flyTest.vert_angle = True flyTest.lat_angle = True if flyTest.right_box in hits: flyTest.go_left = True # Cyril added random direction and angle x = random.randint(1, 2) if x == 1: flyTest.go_up = True else: flyTest.go_up = False k = random.randint(1, 4) if k == 1: flyTest.vert_angle = True flyTest.lat_angle = False elif k == 2: flyTest.vert_angle = False flyTest.lat_angle = True else: flyTest.vert_angle = True flyTest.lat_angle = True basic_chaserTest.update_basic_chaser(player) ticks = pygame.sprite.groupcollide(enemy_sprites, attack_sprites, True, False) if flyTest in ticks: bug_splat_sound.play() print("YEEEEETT") if player in ticks: print("scored a hit") if ticks: print("the fly is hit!") # Draw / render drawHandling() pygame.display.flip() return ("END")
def main(): # Initialize pygame pygame.init() ###################################################################### #SETTINGS screenWidth = 800 screenHeight = 600 FPS = 30 # timeDelay = 50 DEPRECATED #Creates window, and clock, sets Icon screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("Dungeon Taker: OTA") icon = pygame.image.load('images/oubliette.png') pygame.display.set_icon(icon) clock = pygame.time.Clock() ###################################################################### player = character.Character() running = True def drawHandling(): #this function handles the drawing in layers #RGB VALUES screen.fill((0, 0, 0)) # pDraw() floor_sprites.draw(screen) all_sprites.draw(screen) wall_sprites.draw(screen) collision_sprites.draw(screen) attack_sprites.draw(screen) # def spawn_handling(): # if player.attack == True: # print("spawn thing now") # attack = character.Player_Attack(player.direction, player, 10) # all_sprites.add(attack) # player.attack = False # return(attack) # sprite groups! <3 floor_sprites = pygame.sprite.Group() wall_sprites = pygame.sprite.Group() attack_sprites = pygame.sprite.Group() all_sprites = pygame.sprite.Group() collision_sprites = pygame.sprite.Group() enemy_sprites = pygame.sprite.Group() all_sprites.add(player) #get a list of sprites with built in location information flyTest = enemy.Fly() enemy_sprites.add(flyTest) flyList = [flyTest] all_sprites.add(flyTest) roomLib.procRoomX() dungeonTiles = roomLib.drawTestRoom() for tile in dungeonTiles: if tile.tile_type == 1: floor_sprites.add(tile) if tile.tile_type == 0: wall_sprites.add(tile) coll_boxes = player.coll_list for box in coll_boxes: collision_sprites.add(box) colls = flyTest.coll_boxes for box in colls: collision_sprites.add(box) # testing fly collision # Loading area for rooms # A state machine for managing the main game loop while running: clock.tick(FPS) # pygame.time.delay(timeDelay) DEPRECATED #Update all_sprites.update() # attack = spawn_handling() if player.attack == True: # print("spawn thing now") attack = character.Player_Attack(player.direction, player, 10) attack_sprites.add(attack) # all_sprites.add(attack) player.attack = False attack_sprites.update() collision_sprites.update() wall_sprites.update() running = player.game_running hits = pygame.sprite.groupcollide(collision_sprites, wall_sprites, False, False) if player.top_box in hits: player.collide_up = True else: player.collide_up = False if player.bottom_box in hits: player.collide_down = True else: player.collide_down = False if player.left_box in hits: player.collide_left = True else: player.collide_left = False if player.right_box in hits: player.collide_right = True else: player.collide_right = False # and now, for the fly object if flyTest.top_box in hits: flyTest.go_up = False if flyTest.bottom_box in hits: flyTest.go_up = True if flyTest.left_box in hits: flyTest.go_left = False if flyTest.right_box in hits: flyTest.go_left = True ticks = pygame.sprite.groupcollide(enemy_sprites, attack_sprites, True, False) if flyTest in ticks: print("YEEEEETT") if player in ticks: print("scored a hit") if ticks: print("the fly is hit!") # Draw / render drawHandling() pygame.display.flip() return ("INTRO")