def redraw_screen(): screen.blit(bg, (0, 0)) collision_projectile_enemy() if (player.x == projectile_motion.x or (projectile_motion.x + 5) == player.x or (projectile_motion.x - 5) == player.x) and not (projectile_motion.shoot): projectile.draw_guide(screen, (0, 0, 0), (player.x, player.y), projectile_motion.angle, projectile_motion.v0) if projectile_motion.shoot: projectile.draw( screen, (projectile_motion.x, projectile_motion.y), projectile_motion.angle, projectile_motion.vx, projectile_motion.vy, ) if enemy.health > 0: collision_enemy_character() player.draw(screen) enemy.draw(screen) pygame.display.update()
def deal(players, dealer, deck): for player in players: player.draw(deck) player.draw(deck) dealer.draw(deck) dealer.draw(deck)
def update(): global player, food, clock, is_running clock.tick(60) # Keys player.press(pygame.key.get_pressed()) # Events for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False elif event.type == player_event: player.move() eating() elif event.type == food_event: food.create() # Draw window.fill(BACKGROUND_COLOR) player.draw(draw_rect) food.draw(draw_rect) pygame.display.update()
def draw(): surface.fill((0, 0, 10))#background stars.draw(surface) em.draw(surface) player.draw(surface) bm.draw(surface) pygame.display.flip()
def drawAndDelay(player): #fill screen with black screen.fill(black) #Draw player player.draw() #Update the screen pygame.display.flip() #Delay to get 30 fps clock.tick(30)
def draw(screen): draw_background(screen) for bullet in bullets: bullet.draw(screen) player.draw(screen) for asteroid in asteroids: asteroid.draw(screen)
def drawAndDelay(player, bullets): #fill screen with black screen.fill(black) #Draw players and bullets player.draw() for b in bullets: b.draw() #Update the screen pygame.display.flip() #Delay to get 30 fps clock.tick(30)
def drawAndDelay(player, race_track): #fill screen with black screen.fill(black) #Draw player player.draw() race_track[0].color = (255,0,0) #TODO TESTING for seg in race_track: seg.draw() #Update the screen pygame.display.flip() #Delay to get 30 fps clock.tick(30)
class Game(): # ustawienia ekranu i gry pygame.display.set_caption('Dedal Maze') screen = pygame.display.set_mode(gm.SIZESCREEN, pygame.FULLSCREEN) screen.blit(gm.BACKGROUND, (0, 0)) clock = pygame.time.Clock() # centrowanie okna os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() # konkretyzacja obiektów player = player.Player(gm.STAND_D) plate = plates.Plates(gm.BLACK, gm.SCALE, gm.ROAD) # głowna pętla gry window_open = True while window_open: # pętla zdarzeń for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: window_open = False elif event.type == pygame.QUIT: window_open = False # rysowanie i aktualizacja obiektów plate.draw(screen) player.draw(screen) # aktualizacja okna pygame pygame.display.flip() clock.tick(30) pygame.quit()
def playGame(players, dealer, deck): for player in players: print(player.name, "has: ") player.showHand() print(dealer.name, "shows: ") dealer.showOneCard() print(player.name, "has a total of: ", player.getValue()) t = True #this is where the user decides if they want to hit(add another card) or stay #with what theyve got. This decision is made while only seeing one dealer card while player.getValue() < int(21) and t == True: hit = str(input("Hit (h) or Stay (s) {}? ".format(player.name))) if hit == str("h"): player.draw(deck) #hit print(player.name, "has: ") player.showHand() #cards in hand print(player.name, "has a total of: ", player.getValue()) #value of hand #if the player goes over 21 they lose immediately if player.getValue() > int(21): print("You went over, Dealer wins!!") d = False break #if the player gets 21 the dealer still has a chance to match(push) if player.getValue() == int(21): print("Blackjack!") t = False d = True return d #return d as true to move in to the determine winner function elif hit == str("s"): t = False d = True print("You have decided to stay. ") print(dealer.name, "has: ") dealer.showHand() print(dealer.name, "has a total of: ", dealer.getValue()) return d
enemy_proj_t.join() enemy_t.join() #begin the final updates and drawing # collision detection & update points points = enemy_hldr.update_coll(player.get_weapon().get_proj_pos(),player.get_weapon().get_proj_art_size()) # print(points) menu.add_points(points) if enemy_hldr.update_proj_coll(player.get_pos()): menu.dec_hp() enemy_hldr.draw_proj() enemy_hldr.draw() player.draw_proj() #call game class and do game things and update game variables and stuff player.draw(screen) # adds hud menu.draw_hud() # Go ahead and update the screen with what we've drawn. if not menu.get_hp(): #if not True: player_alive = False paused = True running = False pygame.display.flip() # --- Limit to 60 frames per second frame_counter = frame_counter+1 if frame_counter >= diff : if running:
def on_draw(): window.clear() laser.draw() player.draw() monsters.draw()
if keys[pygame.K_d]: player.faceDirection = "R" if player.x_pos < current_map.map_bounds_right: current_map.detect_collisions(player) if player.can_move_right: player.walking = True player.move_right() # Graphics (see maps.txt in dev manual) # load things into the game world current_map.load_terrain(world, 32, 32) # load tiles that are below the player # Check if the player is in front of or behind the NPC. if player.T_R[1] > npc1.T_R[1]: npc1.draw(world, player, start_time) player.draw(world, start_time) # draw the player else: player.draw(world, start_time) # draw the player npc1.draw(world, player, start_time) current_map.load_buildings(world, 32, 32) # load tiles that are above the player # blit/scale everything to the game window window_area.blit(world, (-player.x_pos - 16 + (WINDOW_X_area / 2), -player.y_pos - 16 + (WINDOW_Y_area / 2))) pygame.transform.scale(window_area, (WINDOW_X, WINDOW_Y), window) pygame.display.flip()
def gameLoop(): # initialize exit condition game = True # user inputs press_W = False press_S = False press_A = False press_D = False press_left = False press_right = False press_up = False # Variables for display Round = 1 score = 0 # List of bullet instances bullets = [] # game loop while game: # resets movement inputs so player stops when there is no input. x = 0 y = 0 # variables to be drawn on display scoreTxt = myfont.render('Score: ', False, grey) scoreNum = myfont.render((str(score)), False, grey) roundTxt = myfont.render('Round: ', False, grey) roundNum = myfont.render((str(Round)), False, grey) # Collects user inputs and exit condition. for event in pygame.event.get(): if (event.type == pygame.QUIT ): # exit condition / X button in corner game = False # Checks for key presses from 'W' 'A' 'S' 'D' and arrow keys. elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_w)): press_W = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_w)): press_W = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_s)): press_S = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_s)): press_S = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_a)): press_A = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_a)): press_A = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_d)): press_D = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_d)): press_D = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_LEFT)): press_left = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_LEFT)): press_left = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_RIGHT)): press_right = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_RIGHT)): press_right = False elif ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_UP)): press_up = True elif ((event.type == pygame.KEYUP) and (event.key == pygame.K_UP)): press_up = False # These inputs change player location if (press_W): y -= 3 elif (press_S): y += 3 if (press_A): x -= 3 elif (press_D): x += 3 player.move(x, y) # These inputs rotate the player. if (press_left): player.turnLeft() elif (press_right): player.turnRight() # Up arrow fires bullets. (because the spacebar felt to awkward) if (press_up) and player.health != 0: bullets.append( bullet.Bullet(player.oriX, player.oriY, player.locX, player.locY)) # Delete bullets after they have moved 60 times if len(bullets) > 0: for x in range(len(bullets)): bullets[x].move() if (bullets[x].count > 60): remove = bullets[x] del bullets[x] remove.kill() break # Stop inputs if player dies. if player.collision(enemies): player.health = 0 # If bullets hit enemies, enemies die. if (len(enemies) > 0): for x in range(len(enemies)): enemies[x].move(player.locX, player.locY) for x in range(len(enemies)): for b in range(len(bullets)): if (math.sqrt((abs(bullets[b].x - enemies[x].x)**2) + abs(bullets[b].y - enemies[x].y)**2) < 10): score += 1 remove = enemies[x] del enemies[x] remove.kill() break break # If all the enemies are dead increase # round by 1 and add more enemies. elif (len(enemies) < 1): nextRound(Round, enemies) Round += 1 # Draw everything. DISPLAYSURF.fill(black) # Draw new background DISPLAYSURF.blit(scoreTxt, (5, 5)) # Draw score DISPLAYSURF.blit(scoreNum, (100, 5)) DISPLAYSURF.blit(roundTxt, (5, 55)) # Draw round DISPLAYSURF.blit(roundNum, (100, 55)) if len(bullets) > 0: # Draw all the bullets. for x in range(len(bullets)): bullets[x].draw(DISPLAYSURF) if len(enemies) > 0: # Draw all the enemies. for x in range(len(enemies)): enemies[x].draw(DISPLAYSURF) player.draw(DISPLAYSURF) # Draw the player. pygame.display.update() FPS.tick(45) # Refresh rate.
def draw_players(self, surface): for player in self.player_list: player.draw(surface)
def main(): # set up pygame pygame.init() mainClock = pygame.time.Clock() #player power states player1 = pygame.image.load("img/player.png") player2 = pygame.image.load("img/player2.png") player3 = pygame.image.load("img/player3.png") player4 = pygame.image.load("img/player4.png") player_image = player1 player = Player("img/player.png") background = pygame.image.load("img/background.png") ASTEROID_image = pygame.image.load("img/Rock.png") BOSS_image = pygame.image.load("img/Spaceship.png") BULLET_image = pygame.image.load("img/bullet.png") BOSSBULLET_image = pygame.image.load("img/enemy_bullet.png") BOSSBULLET2_image = pygame.image.load("img/enemy_bullet2.png") EXPLOSION_image = pygame.image.load("img/explosion_tiles.bmp") HEALTH_image = pygame.image.load("img/HealthPowerUp.png") POWER_image = pygame.image.load("img/Bolt.png") bulletSound_1 = pygame.mixer.Sound("audio/shoot_1.wav") bulletSound_2 = pygame.mixer.Sound("audio/shoot_2.wav") bulletSound_3 = pygame.mixer.Sound("audio/shoot_3.wav") scollide = pygame.mixer.Sound("audio/scollide.ogg") #set up music pygame.mixer.music.load("audio/backgroundmusic.mp3") #set background rect equal to the size of the background image backgroundRect = background.get_rect() backgroundArea = backgroundRect backgroundY = 0 # set up the window WINDOWWIDTH = 600 WINDOWHEIGHT = 800 screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) pygame.display.set_caption('Roid Rage') font = pygame.font.Font(None, 36) # set up gameplay variables moveLeft = False moveRight = False moveUp = False moveDown = False MOVESPEED = 8 gameOver = False gameRunning = False splashScreen = True # set up the colors BLACK = (0, 0, 0) GREEN = (0, 255, 0) RED = (255, 0, 0) BLUE = (0, 0, 255) RANDOMCOLOUR = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) WHITE = (255, 255, 255) # player bullet variables bulletCounter = 0 NEWBULLET = 5 BULLETSIZE = 8 BULLETSPEEDY = -25 BULLETSPEEDX = 5 bullets = [] # boss bullet variables bossbulletCounter = 0 bossbulletCounterTotal = 0 bossbulletwaveCounter = 0 NEWBOSSBULLET = 4 NEWBOSSBULLETWAVE = 12 NEWBOSSBULLETWAVESTOP = 20 BOSSBULLETSIZE = 16 BOSSBULLETSPEEDY = 12 BOSSBULLETSPEEDX = 8 boss_bullets = [] # boss fighter variables bossfighterCounter = 0 boss_health_init = 800 boss_health = 800 boss_x = 0 boss_y = 0 NEWBOSS = 500 BOSSSIZE = 96 BOSSSPEEDY = 4 BOSSSPEEDX = 4 BOSS_SHOOTING = False bossfighters = [] boss_shoot = False # explosion variables EXPLOSIONFRAMES = 17 EXPLOSIONSIZE = 200 EXPLOSIONSCALE = 5 explosions = [] # health pick up variables HEALTHSIZE = 32 HEALTHSPEED = 6 healthpickups = [] #power pickup variables POWERSIZE = 32 POWERSPEED = 6 powerpickups = [] fontRenderer = FontRenderer() asteroids = AsteroidFactory("img/Rock.png", "img/explosion_tiles_ast.bmp", "audio\explosion_1.wav") fighters = FighterFactory("img/enemy_1.png", "img/explosion_tiles.bmp", "audio\explosion_1.wav") # Splash screen specific variables splashPart1 = True splashPlayerX = 0 splashPlayerY = 600 splashBossX = 300 - 32 splashBossY = -64 playerRotated = pygame.transform.rotate(player_image, -90) bossRotated = pygame.transform.rotate(BOSS_image, 0) # Splash Screen while splashScreen == True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.key == ord(' '): splashScreen = False gameRunning = True # Draw functions here # Draw the scrolling background backgroundY = backgroundY + 1 if backgroundY == 800: backgroundY = 0 screen.blit(background, (0, backgroundY)) screen.blit(background, (0, backgroundY - 800)) if splashPart1: if splashPlayerX < 600: playerRotated = pygame.transform.rotate(player_image, -90) splashPlayerX = splashPlayerX + 2 elif splashBossY < 800: bossRotated = pygame.transform.rotate(BOSS_image, 0) splashBossY = splashBossY + 5 if splashBossY >= 800: # Go to part 2 splashPart1 = False else: if splashPlayerX > -32: playerRotated = pygame.transform.rotate(player_image, 90) splashPlayerX = splashPlayerX - 2 elif splashBossY > -64: bossRotated = pygame.transform.rotate(BOSS_image, 180) splashBossY = splashBossY - 5 if splashBossY <= -64: # Reset placement and go back to part 1 splashPart1 = True splashPlayerX = -32 splashPlayerY = random.randint(0, 800) splashBossY = -64 # Draw player screen.blit(playerRotated, (splashPlayerX, splashPlayerY)) screen.blit(bossRotated, (splashBossX, splashBossY)) # Draw Title fontRenderer.draw_title("Press Space to play!", (50, 300), screen) # draw the window onto the screen pygame.display.update() mainClock.tick(40) while gameRunning == True: # start music loop pygame.mixer.music.play(5) while gameOver == False: # PROCCESS EVENTS for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: # change the keyboard variables if event.key == K_LEFT or event.key == ord('a'): moveLeft = True if event.key == K_RIGHT or event.key == ord('d'): moveRight = True if event.key == K_UP or event.key == ord('w'): moveUp = True if event.key == K_DOWN or event.key == ord('s'): moveDown = True if event.key == K_SPACE: player.shooting = True if event.type == KEYUP: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.key == K_LEFT or event.key == ord('a'): moveLeft = False if event.key == K_RIGHT or event.key == ord('d'): moveRight = False if event.key == K_UP or event.key == ord('w'): moveUp = False if event.key == K_DOWN or event.key == ord('s'): moveDown = False if event.key == K_SPACE: player.shooting = False bulletCounter = NEWBULLET # UPDATE EVERYTHING asteroids.spawn(WINDOWWIDTH) fighters.spawn(WINDOWWIDTH) #add to the boss fighter counter until time for new boss to spawn bossfighterCounter += 1 if bossfighterCounter == NEWBOSS: #spawn the new boss bossfighters.append({ 'rect': pygame.Rect(316, 0 - BOSSSIZE, BOSSSIZE, BOSSSIZE), 'speed': (BOSSSPEEDX, BOSSSPEEDY), 'surface': pygame.transform.scale(BOSS_image, (BOSSSIZE, BOSSSIZE)) }) boss_x = 316 boss_y = (0 - BOSSSIZE) #player shooting mechanic / fires extra bullets with each level of power if player.shooting == True: bulletCounter += 1 if bulletCounter >= NEWBULLET: bulletSound_1.play() bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (0, BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) if player.power >= 2: bulletSound_2.play() bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (BULLETSPEEDX, 0.95 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (-BULLETSPEEDX, 0.95 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) if player.power >= 3: bulletSound_3.play() bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (2 * BULLETSPEEDX, 0.9 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (-2 * BULLETSPEEDX, 0.9 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) if player.power >= 4: bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (3 * BULLETSPEEDX, 0.8 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) bullets.append({ 'rect': pygame.Rect(player.x, player.y, BULLETSIZE, BULLETSIZE), 'speed': (-3 * BULLETSPEEDX, 0.8 * BULLETSPEEDY), 'surface': pygame.transform.scale(BULLET_image, (BULLETSIZE, BULLETSIZE)) }) bulletCounter = 0 # Change player sprite based on power level (currently broken) if player.power >= 1: player.image = player1 if player.power >= 2: player.image = player2 if player.power >= 3: player.image = player3 if player.power >= 4: player.image = player4 # Delete things that are outside the screen player.score += asteroids.remove(WINDOWHEIGHT, explosions, EXPLOSIONSIZE, EXPLOSIONSCALE, EXPLOSIONFRAMES) fighters.remove(WINDOWHEIGHT) for a in boss_bullets: if a['rect'].top > WINDOWHEIGHT: boss_bullets.remove(a) for b in bullets[:]: if b['rect'].bottom < 0: bullets.remove(b) for e in explosions[:]: e['frame'] = e['frame'] + 1 if e['frame'] >= 18: explosions.remove(e) # move the player if moveDown and player.rect.bottom < WINDOWHEIGHT: player.rect.top += MOVESPEED player.y += MOVESPEED if moveUp and player.rect.top > 0: player.rect.top -= MOVESPEED player.y -= MOVESPEED if moveLeft and player.rect.left > 0: player.rect.left -= MOVESPEED player.x -= MOVESPEED if moveRight and player.rect.right < WINDOWWIDTH: player.rect.right += MOVESPEED player.x += MOVESPEED # move things asteroids.move() fighters.move() for b in bossfighters: if boss_y < 150: b['rect'].move_ip(0, BOSSSPEEDY) boss_y += BOSSSPEEDY #print (boss_y) if boss_y >= 150: BOSS_SHOOTING = True if boss_x < player.x - 48: b['rect'].move_ip(BOSSSPEEDX, 0) boss_x += BOSSSPEEDX if boss_x > player.x - 48: b['rect'].move_ip(-BOSSSPEEDX, 0) boss_x -= BOSSSPEEDX if BOSS_SHOOTING == True: bossbulletwaveCounter += 1 if bossbulletwaveCounter >= NEWBOSSBULLETWAVE: bossbulletCounter += 1 bossbulletCounterTotal += 1 if bossbulletCounter >= NEWBOSSBULLET: boss_bullets.append({ 'rect': pygame.Rect(boss_x + 48, boss_y, BULLETSIZE, BULLETSIZE), 'speed': (0, BOSSBULLETSPEEDY), 'surface': pygame.transform.scale( BOSSBULLET_image, (BOSSBULLETSIZE, BOSSBULLETSIZE)) }) boss_bullets.append({ 'rect': pygame.Rect(boss_x + 32, boss_y, BULLETSIZE, BULLETSIZE), 'speed': (-0.15 * BOSSBULLETSPEEDX, 0.5 * 0.95 * BOSSBULLETSPEEDY), 'surface': pygame.transform.scale( BOSSBULLET2_image, (BOSSBULLETSIZE, BOSSBULLETSIZE)) }) boss_bullets.append({ 'rect': pygame.Rect(boss_x + 64, boss_y, BULLETSIZE, BULLETSIZE), 'speed': (0.15 * BOSSBULLETSPEEDX, 0.5 * 0.95 * BOSSBULLETSPEEDY), 'surface': pygame.transform.scale( BOSSBULLET2_image, (BOSSBULLETSIZE, BOSSBULLETSIZE)) }) boss_bullets.append({ 'rect': pygame.Rect(boss_x + 16, boss_y, BULLETSIZE, BULLETSIZE), 'speed': (-0.5 * BOSSBULLETSPEEDX, 0.9 * BOSSBULLETSPEEDY), 'surface': pygame.transform.scale( BOSSBULLET_image, (BOSSBULLETSIZE, BOSSBULLETSIZE)) }) boss_bullets.append({ 'rect': pygame.Rect(boss_x + 80, boss_y, BULLETSIZE, BULLETSIZE), 'speed': (0.5 * BOSSBULLETSPEEDX, 0.9 * BOSSBULLETSPEEDY), 'surface': pygame.transform.scale( BOSSBULLET_image, (BOSSBULLETSIZE, BOSSBULLETSIZE)) }) bossbulletCounter = 0 if bossbulletCounterTotal >= NEWBOSSBULLETWAVESTOP: bossbulletCounterTotal = 0 bossbulletwaveCounter = 0 for b in bullets: b['rect'].move_ip(b['speed']) for b in boss_bullets: b['rect'].move_ip(b['speed']) for b in healthpickups: b['rect'].move_ip(0, b['speed']) for b in powerpickups: b['rect'].move_ip(0, b['speed']) player.score += fighters.collide_bullets( bullets, explosions, EXPLOSIONSIZE, EXPLOSIONSCALE, EXPLOSIONFRAMES, healthpickups, HEALTHSIZE, HEALTHSPEED, HEALTH_image, powerpickups, POWERSIZE, POWERSPEED, POWER_image) # TODO make this the other way round, # bullets should be removed if they are touching asteroids asteroids.collide_bullets(bullets, explosions) player.health = asteroids.collide_player(player.rect, player.health) player.health = fighters.collide_player(player.rect, player.health) for i in bullets: for f in bossfighters: if (i['rect']).colliderect(f['rect']): bullets.remove(i) boss_health -= 5 if boss_health <= 0: for b in bossfighters: bossfighters.remove(b) bossfighterCounter = 0 boss_health = boss_health_init + 200 boss_health_init = boss_health BOSSSIZE += 8 BOSSBULLETSIZE += 4 BOSSBULLETSPEEDY += 2 # increase the players max health player.maxHealth += 10 BOSSBULLETSPEEDX += 1 for b in boss_bullets: if player.rect.colliderect(b['rect']): boss_bullets.remove(b) player.health -= 5 for b in bossfighters: if player.rect.colliderect(b['rect']): player.health = 0 player.collide_health(healthpickups, 20) for b in powerpickups: if player.rect.colliderect(b['rect']): powerpickups.remove(b) if player.power < 4: player.power += 1 #check player health if player.health <= 0: gameOver = True # DRAW PHASE # draw the scrolling backgound backgroundY = backgroundY + 1 if backgroundY == 800: backgroundY = 0 screen.blit(background, (0, backgroundY)) screen.blit(background, (0, backgroundY - 800)) player.draw(screen) asteroids.draw(screen) fighters.draw(screen) #draw things on screen for b in bullets: screen.blit(b['surface'], b['rect']) for b in boss_bullets: screen.blit(b['surface'], b['rect']) for b in bossfighters: screen.blit(b['surface'], b['rect']) for b in healthpickups: screen.blit(b['surface'], b['rect']) for b in powerpickups: screen.blit(b['surface'], b['rect']) for e in explosions: screen.blit( e['surface'], e['rect'], pygame.Rect((e['frame'] * EXPLOSIONSIZE) / 5, 0, EXPLOSIONSIZE / 5, EXPLOSIONSIZE / 5)) # draw the stats fontRenderer.draw_stat("Score: ", player.score, (10, 10), screen) fontRenderer.draw_stat("Health: ", player.health, (10, 40), screen) if bossfighters: fontRenderer.draw_stat("Boss Health: ", boss_health, (10, 70), screen) # draw the window onto the screen pygame.display.update() mainClock.tick(100) while gameOver == True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.key == ord('r'): # reset everything asteroids.remove_all() fighters.remove_all() for b in bullets: bullets.remove(b) bullets = [] for b in boss_bullets: boss_bullets.remove(b) boss_bullets = [] for b in bossfighters: bossfighters.remove(b) bossfighters = [] for b in healthpickups: healthpickups.remove(b) healthpickups = [] for b in powerpickups: powerpickups.remove(b) powerpickups = [] player.reset(300, 700) bossfighterCounter = 0 player.power = 1 boss_health = 800 boss_health_init = 800 BOSSBULLETSIZE = 16 BOSSBULLETSPEEDY = 12 BOSSSIZE = 96 gameOver = False moveLeft = False moveRight = False moveDown = False moveUp = False fontRenderer.draw_title("Press R to retry", (100, 300), screen) if player.health > 0: gameOver = False # draw the window onto the screen pygame.display.update() mainClock.tick(40)
def do_action(self, board, player): """ this does what it is told, it plays the card on the board played by player """ if self.name == CARD_NAMES[0]: #CELLAR """ +1 action discard any number of cards from your hand (not this card) and draw that number of discarded cards """ player.actions += 1 print("Please type in which cards you would like to discard.") print( "Input: comma seperated numbers starting at 0 from your hand \n" ) card_choices = raw_input("Please enter something: ") if " " in card_choices: print( "remember, no spaces and numbers seperated by commas, try again" ) self.do_action(board, player) #self is me! else: try: list_choices = card_choices.split(",") player.hand_to_discard(list_choices) player.draw( len(list_choices) ) #if it gets here, will already have discarded correctly and draw should never error except Exception as e: print(e) print("Please try again, that was an invalid command \n") self.do_action(board, player) elif self.name == CARD_NAMES[1]: #CHAPEL """ Trash up to four cards """ print("Please type in which cards you would like to trash.") print( "Your current cards are" + player.cards ) # I think we should print cards by 1) NAME and they select the numbers print( "Please type in the card numbers and comma seperate them with no space \n" ) card_choices = raw_input("Please enter something: ") if " " in card_choices: print( "remember, no spaces and numbers seperated by commas, try again" ) self.do_action(board, player) else: list_choices = card_choices.split(",") try: player.trash(list_choices) except Exception as e: print(e) self.do_action(board, player) elif self.name == CARD_NAMES[2]: #MOAT """ Draw two cards and protects you from action cards if it is in your hand """ player.draw(2) elif self.name == CARD_NAMES[3]: #HARBINGER """ +1 card +1 action Look into discard pile, you can put something from there onto your deck """ player.draw(1) player.action += 1 print( "Your discard pile: type in the number to place that card on the top of your current deck" ) for i in range(len(player.discard)): print(str(i) + ") " + player.discard[i].name) card_choice = raw_input("Please enter the card number: ") try: card = player.discard[str(card_choice)] player.discard.remove(card) player.deck = [card] + player.deck except Exception as e: print("Incorrect card input, try again") self.do_action(board, player) elif self.name == CARD_NAMES[4]: #MERCHANT """ +1 card +1 action first time play a silver this turn, +1 money """ player.draw(1) player.actions += 1 #TODO why would you play a silver then get gold, I don't get it played_names = [ player.played[i].name for i in range(len(player.played)) ] if "SILVER" in played_names: player.money += 1 elif self.name == CARD_NAMES[5]: #VASSAL """ +2 gold discard top card of deck, if action card, play it """ player.money += 2 top_card = player.take() #TODO might have to reshuffle! if top_card.name in CARD_NAMES: top_card.do_action(board, player) player.played.append(top_card) else: player.discard_func(top_card) elif self.name == CARD_NAMES[6]: #VILLAGE """ +1 card +2 actions """ player.draw(1) player.actions += 2 elif self.name == CARD_NAMES[7]: #WORKSHOP """ gain any card costing up to 4 """ print( "Please select one of the cards to add to your hand costing up to 4" ) print("Select the card you want by typing the name:") card_choice = raw_input("Please enter the card name: ") try: selected = self.game_board.stock_piles[ card_choice.upper()].pop() #will player.add(selected) except Exception as e: print(e) #maybe that card is out print("Incorrect card input, try again") self.do_action(board, player) elif self.name == CARD_NAMES[8]: #BUREAUCRAT """ gain a silver onto your deck each other player reveals a victory card from their hand and puts it onto their deck (or revals a hand with no Victory cards!) """ #TODO - how can a ML program or a strategy use this?? silver_card = self.game_board.silvers.pop() player.add(silver_card) for other_players in self.game_board.players( player): #don't want to return myself??? other_hand = other_players.hand( ) #IMPORTANT this is why you always make their hand full after they end the turn and they don't play it until it is their turn victory_list = [] for card in other_hand: if card.type == "vicotry": #TODO how can I do this in gameplay? Let them choose? victory_list.append(card) if victory_list.empty(): print("Player " + player.name + "'s hand is:") print other_hand else: print( "Player" + player.name + "choose a victory card to get rid of from your hand") #TODO can I hide this from other people?? for i in range(len(victory_list)): print(str(i) + ") " + victory_list[i].name) card_choice = raw_input("Please enter the card number: ") other_players.deck = [ victory_list[int(card_choice)] ] + other_players.deck #Putting it on deck, #TODO make a method for this, kinda common action elif self.name == CARD_NAMES[9]: #GARDENS """ this is a victory card, only counts at game end """ print("Nothing to do here") elif self.name == CARD_NAMES[10]: #MILITIA """ +2 gold attack each other player discards down to 3 cards in their hand """ #TODO for attach, each bot needs a strategy to handle this player.money += 2 for other_player in board.players( player): #don't want to return myself??? other_player.discard_to(3) elif self.name == CARD_NAMES[11]: #MONEYLENDER """ You can trash a copper for +3 gold """ contains_copper = False index = 0 card_names = [card.name for card in player.hand] for curr_name in card_names: if curr_name == "copper": contains_copper = True break index += 1 if contains_copper: #assume if they are playing it they want to player.trash(index) player.money += 3 elif self.name == CARD_NAMES[12]: #POACHER """ +1 card +1 action +1 money discard a card per empty stock pile """ player.draw(1) player.actions += 1 player.money += 1 empty_piles = 0 for stock in self.game_board.stock_piles.values(): if len(stock) == 0: empty_piles += 1 player.discard_to(len(player.hand) - empty_piles) elif self.name == CARD_NAMES[13]: #REMODEL """ trash a card from your hand and gain a card costing up to 2 more than it """ #two approaches here, let the player do the choosing, or ask them out in the open print( "Please select a card from your hand to trash" ) #can keep anonymous by not printing everything #Abstract the seleting thing, can generalize player_hand = player.hand() selected_card = player.select_from( player_hand ) #TODO I am trying this instead of iterating and asking for a number, let the player handle it! purchasing_power = selected_card.cost + 2 player.buy( purchasing_power, oneTime=True ) #TODO this is a method we use in play time, after actions run out, they would buy, but this is a one time buy #could get confusing because what if they try to use multiple buys and shit, player.trash(selected_card) #End elif self.name == CARD_NAMES[14]: #SMITHY """ +3 cards """ player.draw(3) elif self.name == CARD_NAMES[15]: #THRONE ROOM """ play an action card from your hand twice """ throne = player.select_from(player.hand()) #pick an action card! throne.do_action(board, player) throne.do_action(board, player) elif self.name == CARD_NAMES[16]: #BANDIT """ gain a gold each player reveals top 2 cards of deck, trash a revealed treasure card other than copper, discard the rest """ gold = board.get("gold") player.add( gold ) #TODO add it in my current hand, so not discard or deck yet for other_players in board.players(player): rest = other_players.deck[ 2:] #TODO what if they have less than two, need to shuffle!!! top_two = other_players.deck[ 0: 2] #but this adds two to their hand, it doesn't return them! players.deck = rest trashed = False for top in top_two: #at this point, it is like the player doesn't own the card, we need to either discard or put in hand or put in deck. if top.type in ["gold", "silver"] and not trashed: print(other_players.name + "lost a " + top.type) player.trash( top ) #TODO need to give them a choice if they happen to have two trashed = True else: player.discard_func(top) elif self.name == CARD_NAMES[17]: #COUNCIL ROOM """ +4 cards +1 buy each other player draws a card """ player.draw(4) player.buys += 1 for other_player in board.players_list(player): other_player.draw(1) elif self.name == CARD_NAMES[18]: #FESTIVAL """ +2 actions +1 buy +2 money """ player.actions += 2 player.buys += 1 player.money += 2 elif self.name == CARD_NAMES[19]: #LABORATORY """ +2 cards +1 action """ player.draw(2) player.actions += 1 elif self.name == CARD_NAMES[20]: #LIBRARY """ """ discarded_pile = [] while len(player.hand()) < 7: curr_card = player.take(1) print("card is " + curr_card.name) if curr_card.type is "action": print("1) keep") print("2) discard") card_decision = raw_input("select move for action card:") if card_decision == "1": player.add(curr_card) else: discarded_pile.append(curr_card) else: player.add(curr_card) for card in discarded_pile: player.discard(card) elif self.name == CARD_NAMES[21]: #MARKET """ +1 card +1 action +1 buy +1 money """ player.draw(1) player.actions += 1 player.buys += 1 player.money += 1 elif self.name == CARD_NAMES[22]: #MINE """ can trash a treasure from your hand and gain a treasure costing up to 3 more than it -> trash and upgrade """ player_hand = player.hand() money_cards = [] for card in player_hand: if card.name in MONEY_CARDS: money_cards.append(card) print("choose a card to upgrade by selecting the number" ) #privacy isn't important here, it is your turn for i in range(len(money_cards)): print(str(i) + ") " + money_cards[i].name) card_choice = raw_input("Please enter the card number: ") seleted_money = money_cards[int( card_choice)] #TODO what if they don't have money!! upgrade = "" #don't let gold upgrades, just stupid if seleted_money.type == "silver": upgrade = "gold" else: upgrade = "silver" #TODO might need more cases here just in case users are stupid new_gold = board.get(update) player.add(new_gold) player.trash(seleted_money) elif self.name == CARD_NAMES[23]: #SENTRY """ +1 card +1 action look at top 2 cards trash/discard any number of them, put the rest back on top in any order """ player.draw(1) player.actions += 1 top_two = player.take( 2 ) #TODO I like this for taking from the top, can also use this abstraction to implement .draw() #can also take care of shuffling here if needed! It should always work, if not it will say, no more cards to draw, use a try and catch to cath this error print("here is the first card:") print(top_two[0].name) print("type in 1) trash 2) discard 4) put back on top" ) #TODO they should be able to put on top in any order choice_1 = raw_input("Please enter the numer: ") if choice_1 == "1": print("Card is out of the game") if choice_1 == "2": player.discard(top_two[0]) else: player.deck = [ top_two[0] ] + player.deck #use add? or a different method #TODO print("type in 1) trash 2) discard 4) put back on top" ) #TODO they should be able to put on top in any order print(top_two[1].name) choice_2 = raw_input("Please enter the numer: ") if choice_2 == "1": print("card is out of the game") #do nothing, the card is out of the game now if choice_2 == "2": player.discard_func(top_two[0]) else: player.deck = [top_two[0]] + player.deck elif self.name == CARD_NAMES[24]: #WITCH """ +2 cards each other player gets a curse (unless moat!) """ player.draw(2) for other_players in board.players( player): #don't want to return myself??? if not other_players.contain( "MOAT"): #contains is an abstracted method! player.add(board.get("curse")) elif self.name == CARD_NAMES[25]: #ARTISAN """ gain a card costing up to 5 put a card from your hand onto your deck -- similar to REMODEL """ purchasing_power = 5 player.buy( purchasing_power, oneTime=True ) #TODO this is a method we use in play time, after actions run out, they would buy, but this is a one time buy #could get confusing because what if they try to use multiple buys and shit, print("select a card from your hand to put on top of your deck") for i in range(len(player.hand())): print(str(i) + ") " + player.hand()[i].name) selected_num = raw_input("Please enter the numer: ") selected_card = player.hand[int(selected_num)] player.hand.remove( selected_card ) #TODO, do I need another custom method here? it would be an @override right?, I need something to just take cards from my deck #the abstracted method would help move cards from hand to discard anyway when a turn ends player.deck = [selected_card] + player.deck
for ghost in ghosts: ghost.move(map) screen.fill((0, 0, 0)) map_y = len(map[0]) map_x = len(map) for a in xrange(map_y): for b in xrange(map_x): if map[b][a] == 0: pygame.draw.rect(screen, (0, 0, 255), pygame.Rect(a * 30, b * 30, 30, 30)) if map[b][a] == 1: pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(a * 30, b * 30, 30, 30)) if map[b][a] == 2: pygame.draw.circle(screen, (255, 255, 255), (a * 30 + 15, b * 30 + 15), 5, 0) player.draw(screen) if level.ispoints(): print "win" label = myfont.render("YOU WON! Your score: " + str(score), 1, (255, 255, 0)) screen.blit(label, (225, 335)) pygame.display.flip() clock.tick(0.5) done = True for ghost in ghosts: ghost.draw(screen) if ghost.overlap(player.y, player.x): print "dead" label = myfont.render("YOU'RE DEAD", 1, (255, 255, 0)) screen.blit(label, (225, 335)) pygame.display.flip() clock.tick(0.5)
#exit manager running = True clock = pygame.time.Clock() while running: # for loop through the event queue for event in pygame.event.get(): # Check for KEYDOWN event; KEYDOWN is a constant defined in pygame.locals, which we imported earlier if event.type == KEYDOWN: # If the Esc key has been pressed set running to false to exit the main loop if event.key == K_ESCAPE: running = False # Check for QUIT event; if QUIT, set running to false elif event.type == QUIT: running = False board.blitBoard(window) board.blitBreakableWalls(window) pressed_keys = pygame.key.get_pressed() if pressed_keys[pygame.K_SPACE] and bomb is None: x = player.x() y = player.y() bomb = bombe.Bomb(x, y, window) elif bomb is not None: bomb.draw(window) player.update(pressed_keys) player.draw(window) pygame.display.update() clock.tick(40)
def render_all(): """Goes through object list and renders everything""" global fov_recompute global visible_tiles if fov_recompute: fov_recompute = False visible_tiles = quickFOV(player.x, player.y, gmap.is_visible_tile, fov=FOV_ALGO, radius=TORCH_RADIUS, lightWalls=FOV_LIGHT_WALLS, sphere=False) #Set to the background layer before drawing the area t.layer(BASE_LAYER) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): set_colour(colours.black, 255) visible = (x, y) in visible_tiles wall = gmap.Map[x][y].block_sight if not visible: if gmap.Map[x][y].explored: if wall: set_colour(colours.darkest_gray, 255) else: set_colour(colours.darker_gray, 255) else: if wall: set_colour(colours.gray, 255) else: set_colour(colours.light_gray, 255) #add visible tile as explored gmap.Map[x][y].explored = True #Draw the character on the map t.put(x, y, BLOCK_CHAR) t.layer(OBJECT_LAYER) for obj in objects: if obj != player: obj.draw() for stair in stairs: stair.draw() player.draw() #GUI Panel cleared for redraw #panel.clear(fg=colours.white, bg=colours.black) #Print out all game messages t.layer(UI_TEXT_LAYER) t.clear_area(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) y = PANEL_Y for (line, colour) in game_msgs: set_colour(colour) t.puts(MSG_X, y, line) #panel.draw_str(MSG_X, y, line, bg=None, fg=colour) y += 1 #Contents under mouse set_colour(colours.light_gray) t.puts(1, PANEL_Y - 1, get_names_under_mouse()) #Statbar render_bar(1, PANEL_Y, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, colours.dark_red, colours.darker_red) t.refresh()
def draw(): ball.draw(surface) player.draw(surface) cpu.draw(surface) draw_scores() draw_court()
for event in pygame.event.get(): player_controls(event) if event.type == pygame.QUIT: gameRunning = False if event.type == pygame.USEREVENT: walker_npc.walkabout() if event.type == pygame.KEYDOWN: print "%d, %d, %d, %d, %s" % (player.x, player.y, world.tiles_grid[player.x][player.y].posX, world.tiles_grid[player.x][player.y].posY, "@") #interacction if event.key == pygame.K_e: talker_npc.talkabout(gameDisplay) print "Test print interaction event" # test print clock.tick(60) gameDisplay.fill(col.grey) #world.draw(gameDisplay,col,"monospace", 20, 3) world.draw_world() #Draw entities walker_npc.draw(gameDisplay) talker_npc.draw(gameDisplay) player.draw(gameDisplay) pygame.display.update() pygame.quit() quit()
def main(): pygame.init() size= [constants.SCREEN_WIDTH,constants.SCREEN_HEIGHT] screen = pygame.display.set_mode(size) pygame.display.set_caption("Punks R Us") # Different pieces! map = Map() scene = Scene() npc_list = pygame.sprite.Group() item_list = pygame.sprite.Group() text_box = TextBox(self) character = charselect.CharSelect() # Getting the player character if character == "Quit": done = True else: # Create the player player = Player(character) player.rect.x = constants.SCREEN_WIDTH/2 - player.rect.width/2 player.rect.y = constants.SCREEN_HEIGHT-45 - player.rect.height # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() # -------- Main Program Loop ----------- while not done: # --- Main event loop for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop # Call event check function check_event(event,map,scene,player,npc_list,item_list) # --- Game logic should go here map.update() npc_list.update() item_list.update() player.update() scene.update() # --- Drawing code should go here # First, clear the screen to white. Don't put other drawing commands # above this, or they will be erased with this command. screen.fill(constants.BLACK) map.draw(screen) npc_list.draw(screen) player.draw(screen) item_list.draw(screen) if dialogue == True: for npc in npc_list: if npc.is_talk() == True: text = font.render(npc.current_text(player.who()),True,constants.WHITE) textsize = font.size(npc.current_text(player.who())) text_box.draw(screen,npc.what_box()) textheight = text_box.rect.y + text_box.rect.height/2 - textsize[1]/2 screen.blit(text, [constants.SCREEN_WIDTH/2-textsize[0]/2, textheight]) # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second clock.tick(60) pygame.quit()
def draw(): current_screen.draw() player.draw()