Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- import random
- import time
- import os
- import pygame
- def draw_plane(w, plane_x, plane_y, sh, sw):
- plane = [
- " /\\ ",
- " =====|==|===== ",
- " / \\ "
- ]
- # Adjust plane_x and plane_y to wrap around the screen
- plane_x = plane_x % sw
- plane_y = plane_y % sh
- for i, line in enumerate(plane):
- # Ensure plane wraps around vertically if it goes off screen
- if plane_y + i < sh:
- w.addstr(plane_y + i, plane_x, line)
- def draw_start_screen(w, sh, sw, is_dev):
- title = [
- " _____ _ _____ __ _ ",
- " / ____| | | __ \ / _| | | ",
- " | (___ | | ___ _| | | | ___| |_ ___ _ __ __| | ___ _ __ ___ ",
- " \___ \| |/ / | | | | | |/ _ \ _/ _ \ '_ \ / _` |/ _ \ '__/ __|",
- " ____) | <| |_| | |__| | __/ || __/ | | | (_| | __/ | \__ \\",
- " |_____/|_|\_\\__, |_____/ \___|_| \___|_| |_|\__,_|\___|_| |___/",
- " __/ | ",
- " |___/ "
- ]
- # Calculate the starting position of the title
- title_x = sw // 2 - len(title[0]) // 2
- title_y = sh // 2 - len(title) // 2
- # Draw the title on the screen
- for i, line in enumerate(title):
- w.addstr(title_y + i, title_x, line)
- # Add instructions below the title
- instructions = "Press any key to start"
- instr_x = sw // 2 - len(instructions) // 2
- instr_y = title_y + len(title) + 2
- w.addstr(instr_y, instr_x, instructions)
- if is_dev:
- w.addstr(instr_y + 1, instr_x, "Dev")
- # Add hotkeys info
- hotkeys_info = "HotKeys: \"e\" - Automatic Firing."
- w.addstr(sh - 3, 0, hotkeys_info)
- w.addstr(sh - 2, 0, "Edmund C. 2024")
- def draw_health_bar(w, health, max_health):
- health_bar = "[" + "█" * health + " " * (max_health - health) + "]"
- w.addstr(1, 0, f"Health: {health_bar}")
- def main(stdscr):
- # Initialize the screen
- curses.curs_set(0)
- stdscr.nodelay(1)
- stdscr.timeout(0)
- stdscr.keypad(True)
- # Define game dimensions
- sh, sw = stdscr.getmaxyx()
- w = curses.newwin(sh, sw, 0, 0)
- # Check for developer mode
- is_dev = os.path.exists("i.am.dev.txt")
- # Start screen loop
- while True:
- # Clear the screen
- w.clear()
- # Draw start screen
- draw_start_screen(w, sh, sw, is_dev)
- # Refresh the screen
- w.refresh()
- # Wait for user input to start the game
- key = stdscr.getch()
- if key != -1:
- break
- # Initialize pygame for sound
- pygame.mixer.init()
- pygame.mixer.music.load('your_audio_file.mp3')
- pygame.mixer.music.play(-1)
- # Plane dimensions
- plane_width = 14
- plane_height = 3
- # Enemy dimensions
- enemy_width = 4
- enemy_height = 3
- # Initial position of the plane (bottom center)
- plane_x = sw // 2 - plane_width // 2
- plane_y = sh - plane_height - 1
- # List to keep track of bullets and enemies
- bullets = []
- enemies = []
- # Initial score and level
- score = 0
- level = 1
- # Health variables
- max_health = 7
- health = max_health
- # Timers for enemy and bullet movement
- bullet_move_timer = 0
- enemy_move_timer = 0
- # Movement delays
- bullet_delay = 0.1 # Bullet movement interval
- enemy_delay = 0.98 # Enemy movement interval
- plane_move_delay = 0.1 # Plane movement interval
- # Flags
- paused = False
- auto_firing = False
- nuked = False
- # Game loop variables
- frame_delay = 1 / 30 # Targeting 30 FPS
- last_frame_time = time.time()
- last_bullet_time = time.time()
- last_enemy_time = time.time()
- last_plane_move_time = time.time()
- # Main game loop
- while True:
- # Calculate elapsed time since last frame
- current_time = time.time()
- elapsed_time = current_time - last_frame_time
- bullet_elapsed_time = current_time - last_bullet_time
- enemy_elapsed_time = current_time - last_enemy_time
- plane_elapsed_time = current_time - last_plane_move_time
- last_frame_time = current_time
- # Clear the screen
- w.clear()
- # Draw the plane
- draw_plane(w, plane_x, plane_y, sh, sw)
- # Draw bullets
- for bx, by in bullets:
- w.addch(by, bx, '|')
- # Draw enemies
- for ex, ey in enemies:
- w.addstr(ey, ex, "####")
- w.addstr(ey + 1, ex, "# #")
- w.addstr(ey + 2, ex, "####")
- # Generate enemies
- if random.randint(0, 20) == 0:
- if len(enemies) < 5: # Limit enemies on screen to 5
- enemies.append((random.randint(0, sw - enemy_width), 0))
- # Increase level every 20 enemies killed
- if score > 0 and score % 20 == 0:
- level += 1
- if level > 255:
- level = 255
- # Print nuke info
- w.addstr(3, sw - 40, "Press 'B' to nuke the screen once!")
- # Move bullets every 0.1 seconds
- if bullet_elapsed_time >= bullet_delay:
- bullets = [(bx, by - 1) for bx, by in bullets if by > 0]
- last_bullet_time = current_time
- # Move enemies every 0.98 seconds
- if enemy_elapsed_time >= enemy_delay:
- enemies = [(ex, ey + 1) for ex, ey in enemies if ey + enemy_height < sh - 1]
- last_enemy_time = current_time
- # Remove the oldest enemy if more than 5 enemies are on screen
- while len(enemies) > 5:
- enemies.pop(0)
- # Detect collisions
- for bx, by in bullets:
- for ex, ey in enemies:
- if ex <= bx < ex + enemy_width and ey <= by < ey + enemy_height:
- score += 1
- bullets.remove((bx, by))
- enemies.remove((ex, ey))
- break
- # Update health if enemies reach the bottom of the screen
- for ex, ey in enemies:
- if ey + enemy_height >= sh - 1:
- health -= 1
- enemies.remove((ex, ey))
- if health <= 0:
- # Game over
- w.addstr(sh // 2, sw // 2 - 5, "GAME OVER")
- w.refresh()
- time.sleep(3)
- return
- # Display the score, level, and health
- w.addstr(0, 0, f'Score: {score}')
- w.addstr(0, sw - 15, f'Level: {level}')
- draw_health_bar(w, health, max_health)
- # Refresh the screen
- w.refresh()
- # Get user input
- key = stdscr.getch()
- # Check for user input to pause or quit the game
- if key == ord('p'):
- paused = not paused
- elif key == ord('q'):
- break
- # Check for auto firing toggle
- if key == ord('e'):
- auto_firing = not auto_firing
- # Fire bullets
- if (key == ord(' ') or auto_firing) and not paused:
- # Calculate bullet position from top center of plane
- bullet_x = plane_x + plane_width // 2
- bullet_y = plane_y - 1
- bullets.append((bullet_x, bullet_y))
- # Plane movement
- if plane_elapsed_time >= plane_move_delay and not paused:
- if key == curses.KEY_UP or key == ord('w'):
- plane_y -= 1
- elif key == curses.KEY_DOWN or key == ord('s'):
- plane_y += 1
- elif key == curses.KEY_LEFT or key == ord('a'):
- plane_x -= 1
- elif key == curses.KEY_RIGHT or key == ord('d'):
- plane_x += 1
- # Wrap around screen horizontally and vertically
- plane_x = plane_x % sw
- plane_y = plane_y % sh
- last_plane_move_time = current_time
- # Adjust FPS
- time.sleep(max(0, frame_delay - elapsed_time))
- # Start the game
- curses.wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement