├── ReadMe.md
├── app.png
├── assets
├── arrow.png
├── game_background.png
├── gayyyy_sound.mp3
├── highscore.txt
├── new_game_button.png
└── player0.png
├── fonts
└── ghostclan.ttf
└── main.py
/ReadMe.md:
--------------------------------------------------------------------------------
1 | # Headhunting
2 |
3 | [](https://forthebadge.com) [](https://forthebadge.com) [](https://forthebadge.com)
4 |
5 |
6 | Headhunting is a simple 2d vertical Arcade Survival and Avoidance Game made using python and pygame.
7 |
8 |
9 |
10 |
11 |
12 | ## How to Download
13 |
14 | Download this project from here [Download Headhunting](!)
15 |
16 |
17 | ## Requirements
18 |
19 | Use the package manager [pip](https://pip.pypa.io/en/stable/) to install following packages :-
20 | * Pygame
21 |
22 | ```bash
23 | pip install pygame
24 | ```
25 |
26 | pygame is already installed in pydroid3, no installation required.
27 |
28 | ## Usage
29 |
30 | Navigate and click main.py to run the game. Then tap on the screen to start playing the game. The objective of the game is to destroy as much enemy planes or choppers as possible without getting destroyed.
31 |
32 | Controls:
33 | * Press left arrow key to go left
34 | * Press right arrow key to go right
35 | * Press space key to go shoot
36 | * Press esc key to quit
37 |
38 | When playing with mouse or on pydroid3
39 | * Press left half of game window to go left
40 | * Press right half of game window to go right
41 | * Click on player plane to shoot
42 |
43 | Max volumn for better experience, enjoy bitches!
44 |
45 | ## Contributing
46 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
47 |
48 | Please make sure to update tests as appropriate.
49 |
--------------------------------------------------------------------------------
/app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/app.png
--------------------------------------------------------------------------------
/assets/arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/assets/arrow.png
--------------------------------------------------------------------------------
/assets/game_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/assets/game_background.png
--------------------------------------------------------------------------------
/assets/gayyyy_sound.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/assets/gayyyy_sound.mp3
--------------------------------------------------------------------------------
/assets/highscore.txt:
--------------------------------------------------------------------------------
1 | 16
--------------------------------------------------------------------------------
/assets/new_game_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/assets/new_game_button.png
--------------------------------------------------------------------------------
/assets/player0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/assets/player0.png
--------------------------------------------------------------------------------
/fonts/ghostclan.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cuddles47/1st-pygame-project/5e4823ec7e9b2775c9c3ad893a1aa3a1187ea30e/fonts/ghostclan.ttf
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | import sys
3 | import random
4 | import os
5 |
6 | # Constants
7 | WIDTH, HEIGHT = 1280, 720
8 | CIRCLE_RADIUS = 28
9 | CIRCLE_SPEED = 13
10 | ARROW_LENGTH = 100
11 | ARROW_SPEED = 14
12 | SPAWN_PROBABILITY = 0.185
13 |
14 | # Initialize Pygame
15 | pygame.init()
16 |
17 | # Load images and set up the screen
18 | screen = pygame.display.set_mode((WIDTH, HEIGHT))
19 | pygame.display.set_caption("My First Pygame Project")
20 |
21 | background_image = pygame.image.load("game_background.png")
22 | background_image = pygame.transform.scale(background_image, (WIDTH, HEIGHT))
23 |
24 | player_image = pygame.image.load("player0.png")
25 | player_image = pygame.transform.scale(player_image, (2 * CIRCLE_RADIUS, 2 * CIRCLE_RADIUS))
26 |
27 | arrow_image = pygame.image.load("arrow.png")
28 | arrow_image = pygame.transform.scale(arrow_image, (ARROW_LENGTH, ARROW_LENGTH))
29 |
30 | # Sound
31 | sound = pygame.mixer.Sound('gayyyy_sound.mp3')
32 | sound.set_volume(1)
33 |
34 | # Classes
35 | class Circle:
36 | def __init__(self):
37 | self.x = WIDTH // 2
38 | self.y = HEIGHT // 2
39 | self.hitbox = pygame.Rect(self.x - CIRCLE_RADIUS, self.y - CIRCLE_RADIUS, 2 * CIRCLE_RADIUS, 2 * CIRCLE_RADIUS)
40 |
41 | def move(self, keys):
42 | if keys[pygame.K_a] and self.x > CIRCLE_RADIUS:
43 | self.x -= CIRCLE_SPEED
44 | if keys[pygame.K_d] and self.x < WIDTH - CIRCLE_RADIUS:
45 | self.x += CIRCLE_SPEED
46 | if keys[pygame.K_w] and self.y > CIRCLE_RADIUS:
47 | self.y -= CIRCLE_SPEED
48 | if keys[pygame.K_s] and self.y < HEIGHT - CIRCLE_RADIUS:
49 | self.y += CIRCLE_SPEED
50 | self.hitbox.topleft = (self.x - CIRCLE_RADIUS, self.y - CIRCLE_RADIUS)
51 |
52 | def draw(self):
53 | screen.blit(player_image, (self.x - CIRCLE_RADIUS, self.y - CIRCLE_RADIUS))
54 |
55 | class Arrow:
56 | def __init__(self):
57 | self.x = 0
58 | self.y = random.randint(0, HEIGHT)
59 | self.image = arrow_image
60 | self.image_rect = self.image.get_rect()
61 | self.image_rect.topleft = (self.x, self.y - self.image_rect.height // 2)
62 | self.colliding = False
63 |
64 | def move(self):
65 | self.x += ARROW_SPEED
66 | self.image_rect.topleft = (self.x, self.y - self.image_rect.height // 2)
67 |
68 | def draw(self):
69 | screen.blit(self.image, self.image_rect)
70 |
71 | def check_collision(self, circle):
72 | if self.colliding:
73 | return False
74 |
75 | distance = ((self.x - circle.x) ** 2 + (self.y - circle.y) ** 2) ** 0.5
76 | if distance < (CIRCLE_RADIUS + ARROW_LENGTH / 2):
77 | self.colliding = True
78 | return True
79 | return False
80 |
81 | # Initialize game variables
82 | player_circle = Circle()
83 | arrows = []
84 | game_over = False
85 | score = 0
86 | high_score = 0
87 | start_time = 0
88 |
89 | if os.path.isfile("highscore.txt"):
90 | with open("highscore.txt", "r") as file:
91 | high_score = int(file.read())
92 |
93 | options_menu = False
94 | running = True
95 | clock = pygame.time.Clock()
96 |
97 | while running:
98 | for event in pygame.event.get():
99 | if event.type == pygame.QUIT:
100 | running = False
101 | if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
102 | options_menu = not options_menu
103 |
104 | if not options_menu:
105 | keys = pygame.key.get_pressed()
106 |
107 | if start_time == 0:
108 | start_time = pygame.time.get_ticks()
109 | elapsed_time = (pygame.time.get_ticks() - start_time) // 1000
110 |
111 | if random.random() < SPAWN_PROBABILITY:
112 | arrows.append(Arrow())
113 |
114 | for arrow in arrows[:]:
115 | arrow.move()
116 | if arrow.x > WIDTH:
117 | arrows.remove(arrow)
118 |
119 | for arrow in arrows:
120 | if arrow.check_collision(player_circle):
121 | game_over = True
122 | break
123 |
124 | score = elapsed_time
125 |
126 | if score > high_score:
127 | high_score = score
128 |
129 | screen.blit(background_image, (0, 0))
130 |
131 | for arrow in arrows:
132 | arrow.draw()
133 |
134 | player_circle.move(keys)
135 | player_circle.draw()
136 |
137 | font = pygame.font.Font(None, 36)
138 | text = font.render(f"Time: {elapsed_time} seconds", True, (0, 0, 0))
139 | screen.blit(text, (10, 10))
140 |
141 | font = pygame.font.Font(None, 24)
142 | text = font.render(f"Score: {score} High Score: {high_score}", True, (0, 0, 0))
143 | screen.blit(text, (10, 40))
144 |
145 | if options_menu:
146 | font = pygame.font.Font(None, 48)
147 | text = font.render("OPTIONS", True, (0, 0, 0))
148 | screen.blit(text, (WIDTH // 2 - text.get_width() // 2, HEIGHT // 2 - text.get_height() // 2))
149 |
150 | font = pygame.font.Font(None, 36)
151 | text = font.render("Press ESC to resume", True, (0, 0, 0))
152 | screen.blit(text, (WIDTH // 2 - text.get_width() // 2, HEIGHT // 2 + 50))
153 |
154 | pygame.display.flip()
155 | clock.tick(60)
156 |
157 | if game_over:
158 | font = pygame.font.Font(None, 72)
159 | text = font.render("YOU LOSE", True, (255, 0, 0))
160 | screen.blit(text, (WIDTH // 2 - text.get_width() // 2, HEIGHT // 2 - text.get_height() // 2))
161 | sound.play()
162 | pygame.display.flip()
163 |
164 | with open("highscore.txt", "w") as file:
165 | file.write(str(high_score))
166 |
167 | while True:
168 | for event in pygame.event.get():
169 | if event.type == pygame.QUIT:
170 | pygame.quit()
171 | sys.exit()
172 | if event.type == pygame.KEYDOWN:
173 | if event.key == pygame.K_ESCAPE:
174 | options_menu = not options_menu
175 | elif options_menu and event.key == pygame.K_r:
176 | options_menu = False
177 | game_over = False
178 | arrows = []
179 | start_time = pygame.time.get_ticks()
180 | elapsed_time = 0
181 | score = 0
182 | elif options_menu and event.key == pygame.K_q:
183 | pygame.quit()
184 | sys.exit()
185 |
--------------------------------------------------------------------------------