def process(mario, FPS, total_frames): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: classes.BugProjectile.fire = not classes.BugProjectile.fire keys = pygame.key.get_pressed() if keys[pygame.K_d]: classes.Mario.going_right = True mario.image = pygame.image.load("images/mario.png") mario.velx = 10 elif keys[pygame.K_a]: classes.Mario.going_right = False mario.image = pygame.image.load("images/marioflipped.png") mario.velx = -10 else: mario.velx = 0 if keys[pygame.K_w]: mario.jumping = True if keys[pygame.K_SPACE]: # p=classes.BugProjectile(mario.rect.x,mario.rect.y,21,25,"projectiles/fire.png") if classes.Mario.going_right: if classes.BugProjectile.fire: p = classes.BugProjectile(mario.rect.x + mario.rect.width, mario.rect.y, True, "projectiles/fire.png") p.velx = 12 else: p = classes.BugProjectile(mario.rect.x + mario.rect.width, mario.rect.y, False, "projectiles/ice.png") p.velx = 12 else: if classes.BugProjectile.fire: p = classes.BugProjectile(mario.rect.x, mario.rect.y, True, "projectiles/fire.png") p.image = pygame.transform.flip(p.image, True, False) p.velx = -12 else: p = classes.BugProjectile(mario.rect.x, mario.rect.y, False, "projectiles/ice.png") p.image = pygame.transform.flip(p.image, True, False) p.velx = -12 spawn(FPS, total_frames) collisions()
def process(bug, FPS, total_frames): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: classes.BugProjectile.fire = not classes.BugProjectile.fire #Keys detection are bellow! keys = pygame.key.get_pressed() if keys[pygame.K_d]: classes.Bug.going_right = True bug.image = pygame.image.load("images/bug.png") bug.velx = 5 elif keys[pygame.K_a]: classes.Bug.going_right = False bug.image = pygame.image.load("images/bugflipped.png") bug.velx = -5 else: bug.velx = 0 if keys[pygame.K_w]: bug.jumping = True if keys[pygame.K_SPACE]: def direction(): if classes.Bug.going_right: p.velx = 8 else: p.image = pygame.transform.flip(p.image, True, False) p.velx = -8 if (classes.BugProjectile.fire): p = classes.BugProjectile(bug.rect.x, bug.rect.y, True, "images/fire.png") direction() else: p = classes.BugProjectile(bug.rect.x, bug.rect.y, False, "images/frost.png") direction() spawn(FPS, total_frames) collisions()
def process(bug, FPS, total_frames): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() keys = pygame.key.get_pressed() if keys[pygame.K_d]: classes.Bug.going_right = True bug.image = pygame.image.load("images/bug.png") bug.velx = 5 elif keys[pygame.K_a]: bug.going_right = False bug.image = pygame.image.load("images/bugflipped.png") bug.velx = -5 else: bug.velx = 0 if keys[pygame.K_w]: bug.jumping = True if keys[pygame.K_SPACE]: p = classes.BugProjectile(bug.rect.x, bug.rect.y, 43, 25, "images/projectiles/fire.png") if bug.going_right: p.velx = 8 else: p.image = pygame.transform.flip(p.image, True, False) p.velx = -8 spawn(FPS, total_frames)
def processes(bug, fps, totoalframes): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: classes.BugProjectile.Fire = not classes.BugProjectile.Fire #key testing keys = pygame.key.get_pressed() if keys[pygame.K_a]: bug.velx = -5 bug.image = pygame.image.load('images\\Bugflipped.png') bug.going_right = False elif keys[pygame.K_d]: bug.velx = 5 bug.image = pygame.image.load('images\\bug.png') bug.going_right = True elif keys[pygame.K_w]: bug.jumping = True elif keys[pygame.K_SPACE]: def direction(): if bug.going_right: p.velx = 8 else: p.image = pygame.transform.flip(p.image, True, False) p.velx = -8 if (classes.BugProjectile.Fire): sound = pygame.mixer.Sound('music\\f2.ogg') sound.play() p = classes.BugProjectile(bug.rect.x, bug.rect.y, "images\\projectiles\\fire.png") else: sound = pygame.mixer.Sound('music\\f1.ogg') sound.play() p = classes.BugProjectile(bug.rect.x, bug.rect.y, "images\\projectiles\\frost.png") direction() spawn(fps, totoalframes) score_plus = collisions() return score_plus
def process(bug, FPS, total_frames, SCREENHEIGHT, score): #Processing for event in pygame.event.get(): #If the type of event is that the program wants to quit then we close pygame and make sure our program closes accordingly if event.type == pygame.QUIT: pygame.quit() #Terminates our program sys.exit() #Declaring a variable that will be used to determine what key was pressed keys = pygame.key.get_pressed() #if statements with statements to excute when the right key is pressed. if keys[pygame.K_RIGHT]: #once the right key is pressed the main character will move to the right. classes.Bug.going_right = True #The image of the main character facing in the right direction will loaded. bug.image = pygame.image.load("C:\\Users\\Joseph Molina\\Desktop\\CST\\flippedEnemy1.png") #The position of the main character will change. bug.velx = 5 #If statements with lines of code to be excuted once the left key is pressed elif keys[pygame.K_LEFT]: #The character will now be facing in the left direction. classes.Bug.going_right = False #The image of the character moving in the left direction will be loaded. bug.image = pygame.image.load("C:\\Users\\Joseph Molina\\Desktop\\CST\\enemy1.png") #The position of the character will be moved. bug.velx = -5 else: #if none of the keys above are pressed nothing will occur to the main character bug.velx = 0 #If statement with lines of code to be executed once it is pressed if keys[pygame.K_UP]: #once the up key is pressed the sound effect will be loaded then played once. pygame.mixer.music.load('C:\\Users\\Joseph Molina\\Desktop\\CST\\jump.ogg') pygame.mixer.music.play(1) #Boolean value of the character jumping will be set to True. bug.jumping = True #IF statements with lines of code to be executed once the space key is pressed. if keys[pygame.K_SPACE]: pygame.mixer.music.load('C:\\Users\\Joseph Molina\\Desktop\\CST\\lasersound.ogg') pygame.mixer.music.play(1) p = classes.BugProjectile(bug.rect.x, bug.rect.y, 34, 34, "projectile.gif") if classes.Bug.going_right: p.velx = 8 else: p.image = pygame.transform.flip(p.image, True, False) p.velx = -8 #Calling out the spawn and collision functions with the given parameters spawn(FPS, total_frames, SCREENHEIGHT,score) collisions()
def process(bug, FPS, total_frames, screen): for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: classes.BugProjectile.fire = not classes.BugProjectile.fire if event.key == pygame.K_ESCAPE: b = metrow(screen) if b == 2: classes.period.sp = 1 classes.period.kl = 0 for proj in classes.BugProjectile.List: proj.destroy() for bug in classes.Bug.List: bug.destroy(classes.Bug) for proj in classes.FlyProjectile.List: proj.destroy() for fly in classes.Fly.List: fly.destroy(classes.Fly) return 1 elif b == 1: pass if event.key == pygame.K_d: classes.Bug.going_right = True #bug.image=pygame.image.load('ship/f1.png') bug.velx = 5 elif event.key == pygame.K_a: classes.Bug.going_right = False #bug.image=pygame.image.load('ship/f1.png') bug.velx = -5 elif event.key == pygame.K_w: bug.vely = -5 elif event.key == pygame.K_s: bug.vely = +5 if event.type == pygame.KEYUP: if event.key == pygame.K_d: bug.velx = 0 elif event.key == pygame.K_a: bug.velx = 0 elif event.key == pygame.K_s: bug.vely = 0 elif event.key == pygame.K_w: bug.vely = 0 keys = pygame.key.get_pressed() if keys[pygame.K_SPACE]: def direction(): p.velx = 8 if (classes.BugProjectile.fire): p = classes.BugProjectile(bug.rect.x + bug.rect.width - 10, bug.rect.y + (bug.rect.height / 2) - 2, 'extras/shell.gif') direction() else: p = classes.BugProjectile(bug.rect.x + bug.rect.width, bug.rect.y, 'extras/gun.gif') direction() if classes.period.sp in (1, 2, 3): spawn(FPS, total_frames, bug) spawn1(FPS, total_frames) else: spawn1(FPS, total_frames) spawn2(FPS, total_frames, bug) spawn3(FPS, total_frames, bug) collisions(bug) return 0