Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, time, random, math
- print("Z and C control enemy firerate. A and S control enemy horizontal speed. \n"
- "WARNING:THESE FEATURES ARE EXPERIMENTAL!")
- pygame.mixer.pre_init()
- pygame.init()
- # -------------------------------------------------------------------------------
- w_width = 800
- w_height = 600
- surface = pygame.display.set_mode((w_width, w_height))
- bullet_num = -1
- left = False
- right = False
- spaceship_size = 50
- spaceship = pygame.image.load("spaceship.png").convert_alpha()
- spaceship_left = pygame.image.load("spaceship_left.png").convert_alpha()
- spaceship_right = pygame.image.load("spaceship_right.png").convert_alpha()
- bg = pygame.image.load("spaceLOL.jpg").convert_alpha()
- icon = pygame.image.load("enemy_sprite.png")
- nemy = pygame.image.load("enemy_sprite.png").convert_alpha()# jake
- pygame.display.set_icon(icon)
- # -------------------------------------------------------------------------------
- fps = 30
- game_Start = False
- font = pygame.font.SysFont(None, 70)
- # -------------------------------------------------------------------------------
- e_x = 100
- e_y = 100
- e_mspd = 10
- e_right = True
- e_left = False
- e_range = 10
- e_y_area = e_y + nemy.get_rect().height
- e_x_area = e_x + nemy.get_rect().width
- e_bullet_num = -1
- e_bullet = {}
- e_lowest_bull = 0
- e_sin = 0
- bossman_health = 5
- boss_interval = 0
- difficulty = 0
- # -------------------------------------------------------------------------------
- bullet = {}
- lowest_bull = 0
- playerlife = 5
- # -------------------------------------------------------------------------------
- def gamemusic():
- music = pygame.mixer.Sound("spoopy_scary_skeletor.wav")
- music.play()
- def message(msg, color):
- screen_text = font.render(msg, True, color)
- surface.blit(screen_text,
- [(w_width / 2) - (screen_text.get_rect().width / 2),
- (w_height / 2) - (screen_text.get_rect().height / 2)])
- def gamerestart():
- global bossman_health, e_x, e_y, bullet, bullet_num, e_bullet_num, \
- boss_interval, lowest_bull, e_lowest_bull, playerlife
- playerlife = 5
- e_x = 100
- e_y = 100
- e_bullet_num = -1
- boss_interval = 0
- bossman_health = 5
- bullet = {}
- bullet_num = -1
- lowest_bull = 0
- e_lowest_bull = 0
- # -------------------------------------------------------------------------------
- def ai():
- global e_x, e_y, bossman_health, e_right, e_left, \
- boss_interval, e_bullet, e_bullet_num, bullet, jump_interval, e_sin
- boss_interval += 1
- e_sin += 0.1
- if e_x <= 0:
- e_right = True
- e_left = False
- elif e_x >= (w_width - nemy.get_rect().width):
- e_left = True
- e_right = False
- if e_right == True:
- e_x += e_mspd
- if e_left == True:
- e_x -= e_mspd
- if e_sin >= (math.pi * 2):
- e_sin = 0
- e_y = 100 + (math.sin(e_sin)*50)
- e_y_area = e_y + nemy.get_rect().height
- e_x_area = e_x + nemy.get_rect().width
- for bull_num in range(lowest_bull, bullet_num + 1):
- if bullet[bull_num][0] >= e_x and bullet[bull_num][0] <= e_x_area \
- and bullet[bull_num][1] >= e_y and bullet[bull_num][1] <= e_y_area:
- bullet[bull_num][0] = w_width + 1
- bossman_health -= 1
- surface.blit(nemy, (e_x, e_y))
- if boss_interval >= fire_rate:
- boss_interval = 0
- e_bullet_num += 1
- e_bullet[e_bullet_num] = [e_x + (nemy.get_rect().width / 2),
- e_y + nemy.get_rect().height]
- def player_move(x, y):
- global playerlife, e_bullet
- p_x_area = x + spaceship.get_rect().width
- p_y_area = y + spaceship.get_rect().height
- if left == True:
- surface.blit(spaceship_left, (x, y))
- elif right == True:
- surface.blit(spaceship_right, (x, y))
- else:
- surface.blit(spaceship, (x, y))
- for bull_num in range(e_lowest_bull, e_bullet_num + 1):
- if e_bullet[bull_num][0] >= x and e_bullet[bull_num][0] <= p_x_area \
- and e_bullet[bull_num][1] >= y and e_bullet[bull_num][1] <= p_y_area:
- e_bullet[bull_num][0] = w_width + 1
- playerlife -= 1
- # -------------------------------------------------------------------------------
- def bullet_make(x, y):
- global bullet_num, bullet, surface
- bullet_num += 1
- bullet[bullet_num] = [x + (spaceship.get_rect().width / 2) - 5, y]
- def bullet_move():
- global bullet, bullet_num, surface, lowest_bull
- for bull_num in range(lowest_bull, bullet_num + 1):
- try:
- bullet[bull_num][1] -= 20
- except KeyError:
- print("Neverlucky")
- if bullet[bull_num][1] <= 0:
- bullet.pop(bull_num)
- lowest_bull += 1
- else:
- pygame.draw.rect(surface, (0, 255, 0),
- (bullet[bull_num][0], bullet[bull_num][1], 10, 10))
- def ai_bullet_update():
- global e_x, e_y, bossman_health, e_bullet, e_lowest_bull
- for bull_num in range(e_lowest_bull, e_bullet_num + 1):
- e_bullet[bull_num][1] += 10
- if e_bullet[bull_num][1] >= w_height:
- e_lowest_bull += 1
- e_bullet.pop(bull_num)
- else:
- pygame.draw.rect(surface, (255, 255, 0),
- (e_bullet[bull_num][0], e_bullet[bull_num][1], 10, 10))
- # -------------------------------------------------------------------------------
- def gamestart():
- global game_Start
- pygame.display.set_caption("hello there!")
- while not game_Start:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_x:
- game_Start = True
- gamerestart()
- gameloop()
- surface.blit(bg, (0, 0))
- message("Press the x button to start!", (0, 255, 0))
- pygame.display.update()
- def gameloop():
- global left, right, bg, game_Start, fire_rate, difficulty, e_mspd, game_Start, bossman_health, e_x, e_y
- mspd = 15
- p_x_change = 0
- p_y_change = 0
- p_x = 400
- p_y = 300
- pygame.display.set_caption("TOUHOU GAME")
- game_Exit = False
- while not game_Exit:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- game_Exit = True
- game_Start = False
- gamestart()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_UP:
- p_x_change = 0
- p_y_change = -mspd
- if event.key == pygame.K_DOWN:
- p_x_change = 0
- p_y_change = mspd
- if event.key == pygame.K_LEFT:
- left = True
- p_y_change = 0
- p_x_change = -mspd
- if event.key == pygame.K_RIGHT:
- right = True
- p_y_change = 0
- p_x_change = mspd
- if event.type == pygame.KEYUP:
- if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
- p_y_change = 0
- if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
- left = False
- right = False
- p_x_change = 0
- if event.key == pygame.K_x:
- bullet_make(p_x, p_y)
- if event.key == pygame.K_z:
- difficulty += 1
- if event.key == pygame.K_c:
- difficulty -= 1
- if event.key == pygame.K_a:
- e_mspd += 1
- if event.key == pygame.K_s:
- e_mspd -= 1
- p_x += p_x_change
- p_y += p_y_change
- if p_x <= 0:
- p_x = 5
- if p_x >= w_width - spaceship_size:
- p_x = w_width - spaceship_size
- if p_y <= 0:
- p_y = 5
- if p_y >= w_height - spaceship_size:
- p_y = w_height - spaceship_size
- fire_rate = 60 - difficulty
- surface.blit(bg, (0, 0))
- if bossman_health >= 1:
- ai()
- ai_bullet_update()
- if bossman_health <= 0:
- difficulty += 5
- bossman_health = difficulty * 2
- surface.blit(bg, (0, 0))
- message("Boss " + str(difficulty/5) + " defeated!", (0,255,0))
- pygame.display.update()
- time.sleep(2)
- e_x = random.randint(0,w_width)
- e_y = random.randint(0,200)
- if playerlife > 0:
- player_move(p_x, p_y)
- bullet_move()
- elif playerlife <= 0:
- message("your died lol", (255, 0, 0))
- pygame.display.update()
- time.sleep(3)
- game_Exit = True
- game_Start = False
- gamestart()
- player_move(p_x, p_y)
- pygame.time.Clock().tick(fps)
- pygame.display.update()
- gamestart()
- gamemusic()
- pygame.quit()
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement