def test_if_mario_eat_mushroom_while_tall_nothing_happens(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 6) level.set_items(8, 2, model.MUSHROOM) level.move_mario(2) level.set_items(8, 3, model.MUSHROOM) level.move_mario(1) self.assertEqual(level.mario.size, 2)
def test_if_mario_is_on_a_spike_mario_dies(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.set_spikes(9, 3, 2) level.move_mario(4) self.assertEqual(level.mario.c, 0) self.assertEqual(level.mario.l, 8)
def test_if_mario_jump_while_jumpin_nothing_happens(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.jump_mario() level.update() level.jump_mario() self.assertEqual(level.mario.vl, 1) level.update() level.jump_mario() self.assertEqual(level.mario.vl, 0)
def test_if_mario_jump_below_a_spike_mario_dies(self): level = model.Level(None, 10, 10, 8, 0) level.set_spikes(7, 0, 2) level.set_platform(9, 0, 3) level.move_mario(1) level.jump_mario() level.update() self.assertEqual(level.mario.c, 0) self.assertEqual(level.mario.l, 8)
def test_if_mario_jump_below_a_platform_mario_doesnot_move_above_the_platform( self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(7, 0, 2) level.set_platform(9, 0, 3) level.jump_mario() level.update() self.assertEqual(level.mario.l, 8)
def test_if_big_mario_falls_he_become_little(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.set_spikes(9, 3, 2) level.set_items(8, 2, model.MUSHROOM) level.move_mario(2) level.move_mario(2) self.assertEqual(level.mario.c, 4) self.assertEqual(level.mario.l, 8) self.assertEqual(level.mario.size, 1) self.assertTrue(level.mario.cpt > 0)
def load_levels(): l1 = model.Level(map="GGG ppp GGG", petStart="0 1", treatPos="2 1") model.session.add(l1) l2 = model.Level(map="GGGG pppG GGpp GGGG", petStart="0 1", treatPos="3 2") model.session.add(l2) l3 = model.Level(map="ppGG GppG GGpp GGGp", petStart="3 3", treatPos="0 0") model.session.add(l3) l4 = model.Level(map="pGGGG pppGG GGppp GGGGp", petStart="0 0", treatPos="4 3") model.session.add(l4) l5 = model.Level(map="GpGG GgpG GGpG GGpG GGpG", petStart="1 0", treatPos="2 4") model.session.add(l5) l6 = model.Level(map="GbpG GpGG GpgG GGpG GbpG", petStart="1 4", treatPos="2 0") model.session.add(l6)
def test_if_mario_eat_mushroom_he_grows(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.set_items(8, 2, model.MUSHROOM) level.move_mario(2) self.assertEqual(level.mario.size, 2)
def test_mario_initial_position(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) self.assertEqual(level.mario.l, 8) self.assertEqual(level.mario.c, 0)
def test_if_mario_jump_mario_move_up(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.jump_mario() level.update() self.assertEqual(level.mario.l, 6)
def test_mario_can_jump(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.jump_mario() self.assertTrue(level.mario.vl > 0)
def test_mario_cannot_move_right_at_rightmost_point(self): level = model.Level(None, 10, 10, 8, 9) level.set_platform(9, 0, 10) level.move_mario(1) self.assertEqual(level.mario.c, 9)
def test_mario_cannot_move_left_at_leftmost_point(self): level = model.Level(None, 10, 10, 8, 0) level.set_platform(9, 0, 3) level.move_mario(-1) self.assertEqual(level.mario.c, 0)
def test_mario_move_left(self): level = model.Level(None, 10, 10, 8, 2) level.set_platform(9, 0, 3) level.move_mario(-1) self.assertEqual(level.mario.c, 1)
import curses stdscr = curses.initscr() import model curses.noecho() curses.cbreak() curses.curs_set(0) stdscr.keypad(True) stdscr.clear() stdscr.timeout(100) width = curses.COLS - 1 height = 23 level = model.Level(stdscr, width, height, height - 2, 0) level.set_platform(height - 1, 0, width) level.set_platform(19, 10, 5) level.set_spikes(19, 15, 5) level.set_platform(19, 20, 5) level.set_items(21, 10, model.MUSHROOM) level.display() i = 0 while True: i += 1 c = stdscr.getch() if c == ord('a'): break elif c == curses.KEY_LEFT: level.move_mario(-1, True) elif c == curses.KEY_RIGHT:
def main(): pygame.init() screen = pygame.display.set_mode((640, 480)) dirt = pygame.transform.scale2x(utils.load_png("dirt.png")) background = pygame.Surface(screen.get_size()) background = background.convert() for x in range(32,640,32): for y in range(0,480,32): background.blit(dirt, (x,y)) levelNumber=1 inventory = pygame.Surface((528,368)) song = model.Music() panel = pygame.surface.Surface((242, 32)) panel.fill((192,192,192)) selector = pygame.surface.Surface((246,36)) selector.fill((255,0,255)) l=model.Level(levelNumber) character = model.Character() has_runes = [True, True, True, True, False, False, False, False] has_buffs = [False, False, False, False, False, False, False, False] runes_pictures = [pygame.transform.scale2x(utils.load_png('rune1.png')), pygame.transform.scale2x(utils.load_png('rune2.png')), pygame.transform.scale2x(utils.load_png('rune3.png')), pygame.transform.scale2x(utils.load_png('rune4.png'))] runes_text = ["REFRESH - Fully restore character health", "ENDURE - Reduce damage taken by 80% in this room", "EMPOWER - Quadruple attack damage in this room", "DESOLATE - Monsters within 200 pixels take 60 damage"] add_buffs_text = ["REFRESH - ???", "ENDURE - ???", "EMPOWER - ???", "DESOLATE - ???"] buffs_text = ["REFRESH - Restores 5 health on each kill", "ENDURE - Wow. Such Buff. Much effects.", "EMPOWER - This is a really good buff", "Alright then, Listen here you little shit"] healthbar = gui.HealthBar() clock = pygame.time.Clock() charactersprites = pygame.sprite.RenderUpdates(character) obstacles = pygame.sprite.RenderPlain() obstacles.add(model.Obstacle((128,128), "rock.png"), model.Obstacle((128, 192), "rock.png"), model.Obstacle((192,192), "rock.png")) sword = pygame.sprite.RenderUpdates() moveables = pygame.sprite.RenderUpdates() moveables.add(character) character.currentroom = l.getLocation(l.rootRoom) character.currentroom.moveables.add(character) for room in l.getAllRooms(): room.add_monsters(charactersprites, l) obstacles.add(character.currentroom.walls) while True: clock.tick(40) event_list = [event for event in pygame.event.get()] for event in event_list: if event.type == QUIT: return elif event.type == USEREVENT: if event.subtype == "MonsterDeath": l.num_monsters -= 1 print "Monsters Left", l.num_monsters if l.num_monsters == 0: print("Level Clear!") for room in l.getAllRooms(): if room.bossdoors.sprites() != []: room.door_sprites.add(model.Door(room.bossdoors.sprites()[0].rect.topleft)) room.bossdoors.empty() if event.subtype=='BossDeath': print 'boss death' l.getLocation(l.bossRoom).bossdoors.empty() el=model.Elevator() l.getLocation(l.bossRoom).levelExit.add(el) if event.subtype=='ChangeLevel': #show the player the buff screen and then start a new level! alpha = pygame.Surface(screen.get_size()) alpha.fill((0,0,0)) alpha.set_alpha(128) screen.blit(alpha, (0,0)) exit_inventory = False item_selected = 0 utils.text_format(screen, "Convert a rune into a permanent buff", 20, (20,0),(212,212,212), 40) utils.text_format(screen, "Or press ESC to exit", 20, (150, 435), (212,212,212), 40) pygame.display.flip() while(1): clock.tick(40) inventory.fill((224,224,224)) inventory = inventory.convert() utils.text_format(inventory, "INVENTORY", 24, (170,0), (0, 0, 255), 28) utils.text_format(inventory, "Runes:", 16, (360, 34), (255,0,0),20) utils.text_format(inventory, "Buffs:", 16, (100, 34), (255,0,255),20) i = 0 runes = [] for rune in has_runes: if rune == True: runes.append(i) i += 1 buffs = [] for buff in has_buffs: if buff is not False: buffs.append(buff) event_list = [event for event in pygame.event.get()] for event in event_list: if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: exit_inventory = True elif event.key == K_DOWN: if (item_selected <(len(runes)-1)): item_selected += 1 elif event.key == K_UP: if (item_selected>0): item_selected -= 1 elif event.key == K_RETURN: buff_num = runes[item_selected] has_buffs[len(buffs)] = buff_num has_runes[buff_num] = False character.buff_effects[buff_num] = True exit_inventory = True break if exit_inventory: break if(len(runes) != 0): inventory.blit(selector, (14,62+36*(item_selected+len(buffs)))) for y in range(62,350,36): inventory.blit(panel, (272, y+2)) for y in range(62,350,36): inventory.blit(panel, (16, y+2)) i = 0 for buff in buffs: inventory.blit(runes_pictures[buff], (16, 64+36*i)) utils.text_format(inventory, buffs_text[buff], 8, (54, 66+36*i), (255,255,255), 22) i += 1 i = 0 for rune in runes: inventory.blit(runes_pictures[rune], (274,64+36*i)) utils.text_format(inventory, runes_text[rune], 8, (312,66+36*i), (255, 255, 255), 22) inventory.blit(runes_pictures[rune], (16, 64+36*(i+len(buffs)))) utils.text_format(inventory, add_buffs_text[rune], 8, (54, 72+36*(i+len(buffs))), (255,255,255), 22) i += 1 screen.blit(inventory, (56,56)) pygame.display.flip() #show the player the buff screen and then start a new level! alpha = pygame.Surface(screen.get_size()) alpha.fill((0,0,0)) alpha.set_alpha(128) screen.blit(alpha, (0,0)) exit_inventory = False item_selected = 0 utils.text_format(screen, "Convert a rune into a permanent buff", 20, (20,0),(212,212,212), 40) utils.text_format(screen, "Or press ESC to exit", 20, (150, 435), (212,212,212), 40) pygame.display.flip() while(1): clock.tick(40) inventory.fill((224,224,224)) inventory = inventory.convert() utils.text_format(inventory, "INVENTORY", 24, (170,0), (0, 0, 255), 28) utils.text_format(inventory, "Runes:", 16, (360, 34), (255,0,0),20) utils.text_format(inventory, "Buffs:", 16, (100, 34), (255,0,255),20) i = 0 runes = [] for rune in has_runes: if rune == True: runes.append(i) i += 1 buffs = [] for buff in has_buffs: if buff is not False: buffs.append(buff) event_list = [event for event in pygame.event.get()] for event in event_list: if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: exit_inventory = True elif event.key == K_DOWN: if (item_selected <(len(runes)-1)): item_selected += 1 elif event.key == K_UP: if (item_selected>0): item_selected -= 1 elif event.key == K_RETURN: buff_num = runes[item_selected] has_buffs[len(buffs)] = buff_num has_runes[buff_num] = False character.buff_effects[buff_num] = True exit_inventory = True break if exit_inventory: break if(len(runes) != 0): inventory.blit(selector, (14,62+36*(item_selected+len(buffs)))) for y in range(62,350,36): inventory.blit(panel, (272, y+2)) for y in range(62,350,36): inventory.blit(panel, (16, y+2)) i = 0 for buff in buffs: inventory.blit(runes_pictures[buff], (16, 64+36*i)) utils.text_format(inventory, buffs_text[buff], 8, (54, 66+36*i), (255,255,255), 22) i += 1 i = 0 for rune in runes: inventory.blit(runes_pictures[rune], (274,64+36*i)) utils.text_format(inventory, runes_text[rune], 8, (312,66+36*i), (255, 255, 255), 22) inventory.blit(runes_pictures[rune], (16, 64+36*(i+len(buffs)))) utils.text_format(inventory, add_buffs_text[rune], 8, (54, 72+36*(i+len(buffs))), (255,255,255), 22) i += 1 screen.blit(inventory, (56,56)) pygame.display.flip() #now we have to start a new level! levelNumber+=1 l=model.Level(levelNumber) character.currentroom = l.getLocation(l.rootRoom) for room in l.getAllRooms(): room.add_monsters(charactersprites, l) obstacles.add(character.currentroom.walls) continue elif event.type == KEYDOWN: if event.key == K_i: alpha = pygame.Surface(screen.get_size()) alpha.fill((0,0,0)) alpha.set_alpha(128) screen.blit(alpha, (0,0)) pygame.display.flip() exit_inventory = False item_selected = 0 while(1): inventory.fill((224,224,224)) inventory = inventory.convert() utils.text_format(inventory, "INVENTORY", 24, (170,0), (0, 0, 255), 28) utils.text_format(inventory, "Runes:", 16, (360, 34), (255,0,0),20) utils.text_format(inventory, "Buffs:", 16, (100, 34), (255,0,255),20) i = 0 buffs = [] for buff in has_buffs: if buff is not False: buffs.append(buff) runes = [] for rune in has_runes: if rune == True: runes.append(i) i += 1 event_list = [event for event in pygame.event.get()] for event in event_list: if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_i: exit_inventory = True elif event.key == K_DOWN: if (item_selected <(len(runes)-1)): item_selected += 1 elif event.key == K_UP: if (item_selected>0): item_selected -= 1 elif event.key == K_RETURN: rune_num = runes[item_selected] has_runes[rune_num] = False character.rune_effects[rune_num] = True if exit_inventory: break inventory.blit(selector, (270,62+36*item_selected)) for y in range(62,350,36): inventory.blit(panel, (272, y+2)) for y in range(62,350,36): inventory.blit(panel, (16, y+2)) i = 0 for buff in buffs: inventory.blit(runes_pictures[buff], (16, 64+36*i)) utils.text_format(inventory, buffs_text[buff], 8, (54, 66+36*i), (255,255,255), 22) i += 1 i = 0 for rune in runes: inventory.blit(runes_pictures[rune], (274,64+36*i)) utils.text_format(inventory, runes_text[rune], 8, (312,66+36*i), (255, 255, 255), 22) i += 1 screen.blit(inventory, (56,56)) pygame.display.flip() elif event.key == K_e: for room in l.getAllRooms(): if room.medbay.sprites() != [] and room.medbay.sprites()[0].can_heal == True: room.medbay.sprites()[0].is_healing = True elif event.key == K_SPACE or event.key == K_RETURN: if sword.sprites() == [] and character.sword_cooldown > 10: sword.add(model.Sword(character)) elif event.key == K_a: cont = False for event2 in event_list: if event2.type == KEYDOWN and event2.key == K_d: cont = True if cont: continue character.movepos[0] = -6 character.tryingmoveleft = True character.last_direction_moved = "left" elif event.key == K_w: cont = False for event2 in event_list: if event2.type == KEYDOWN and event2.key == K_s: cont = True if cont: continue character.movepos[1] = -6 character.tryingmoveup = True character.last_direction_moved = "up" elif event.key == K_s: cont = False for event2 in event_list: if event2.type == KEYDOWN and event2.key == K_w: cont = True if cont: continue character.movepos[1] = 6 character.tryingmovedown = True character.last_direction_moved = "down" elif event.key == K_d: cont = False for event2 in event_list: if event2.type == KEYDOWN and event2.key == K_a: cont = True if cont: continue character.movepos[0] = 6 character.tryingmoveright = True character.last_direction_moved = "right" elif event.type == KEYUP: if event.key == K_e: for room in l.getAllRooms(): if room.medbay.sprites() != []: room.medbay.sprites()[0].is_healing = False elif event.key == K_a: #if character.movepos[0] < 0: if character.tryingmoveright == False: character.movepos[0] = 0 else: character.movepos[0] = 6 character.tryingmoveleft = False elif event.key == K_w: #if character.movepos[1] < 0: if character.tryingmovedown == False: character.movepos[1] = 0 else: character.movepos[1] = 6 character.tryingmoveup = False elif event.key == K_s: #if character.movepos[1] > 0: if character.tryingmoveup == False: character.movepos[1] = 0 else: character.movepos[1] = -6 character.tryingmovedown = False elif event.key == K_d: #if character.movepos[0] > 0: if character.tryingmoveleft == False: character.movepos[0] = 0 else: character.movepos[0] = -6 character.tryingmoveright = False if character.health <= 0: break screen.blit(background, (0,0)) healthbar.health = character.health healthbar.draw(screen, l) character.currentroom.walls.draw(screen) character.currentroom.monsters.draw(screen) character.currentroom.projectiles.draw(screen) character.currentroom.bossdoors.draw(screen) character.currentroom.medbay.draw(screen) #for monster in currentroom.monsters.sprites(): # screen.blit(monster.image, monster.rect) charactersprites.update(character.currentroom.walls, character.currentroom.moveables, sword) sword.update(character, character.currentroom.monsters) charactersprites.draw(screen) character.currentroom.projectiles.update(charactersprites) character.currentroom.bossdoors.update(character.currentroom.moveables) character.currentroom.monsters.update(character.currentroom.walls, character.currentroom.moveables, character) #obstacles.draw(screen) if character.currentroom.cord==l.bossRoom: character.currentroom.levelExit.draw(screen) character.currentroom.levelExit.update(character) character.currentroom.door_sprites.update(character, l) character.currentroom.medbay.update(character, l) sword.draw(screen) pygame.display.flip() alpha = pygame.Surface(screen.get_size()) for x in range(64): clock.tick(32) alpha.fill((0,0,0)) alpha.set_alpha(2) screen.blit(alpha, (0,0)) pygame.display.flip() utils.text_format(screen, "Game Over.", 24, (320, 240), (255, 0, 0), 15) pygame.display.flip() while(1): event_list = [event for event in pygame.event.get()] for event in event_list: if event.type == QUIT: return