import pygame
import random
import time
# CREATED BY BRANDEN WATTS
# PEOPLE ARE FREE TO DOWNLOAD THIS DEMO
# PLEASE DO NOT SELL OR DISTRUBITE MY STUFF AS IF YOU MADE IT
# THATS BAD BUSINESS
# I PROVIDE FREE INSIGHTS INTO THE WORLD WE CREATE TOGETHER
# LETS RESPECT EACH OTHER
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
gamestate, tickercount = 0, 0
PLAYER_POS_X, PLAYER_POS_Y = 640, 360
pygame.key.set_repeat(5)
pygame.mouse.set_visible(False)
bulletprocess = []
targetlist = []
targetsdestroyed = 0
testfont16 = pygame.font.Font("C:/Users/brats/Desktop/pleasedothis/font/JMH Typewriter-Bold.otf", 16)
class BulletTime:
def init(self, width, height, color, radius, position):
self.width = width
self.height = height
self.color = color
self.radius = radius
self.position = [PLAYER_POS_X, PLAYER_POS_Y]
self.target = (pygame.mouse.get_pos())
self.speed = random.randint(100, 300)
bulletprocess.append(self)
class TargetCreator:
def init(self, xpos, ypos):
self.xpos = xpos
self.ypos = ypos
targetlist.append(self)
def createBullet():
BulletTime(0, 0, [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)], random.randint(3, 6), (0, 0))
def createTarget():
TargetCreator(random.randint(50, 1230), random.randint(50, 670))
while running:
# KEYSTROKE CENTRAL
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if gamestate == 0 and event.key == pygame.K_w: PLAYER_POS_Y -= 1
if gamestate == 0 and event.key == pygame.K_a: PLAYER_POS_X -= 1
if gamestate == 0 and event.key == pygame.K_s: PLAYER_POS_Y += 1
if gamestate == 0 and event.key == pygame.K_d: PLAYER_POS_X += 1
elif event.type == pygame.MOUSEBUTTONDOWN: PLAYER_POS_X, PLAYER_POS_Y = pygame.mouse.get_pos()
# PRINT TO SCREEN #
screen.fill((10, 10, 10))
pygame.draw.circle(screen, [0, 0, 0], (PLAYER_POS_X, PLAYER_POS_Y), 10)
pygame.draw.circle(screen, [255, 0, 0], (PLAYER_POS_X, PLAYER_POS_Y), 8)
pygame.draw.circle(screen, [255, 255, 255], (PLAYER_POS_X, PLAYER_POS_Y), 6)
if bulletprocess is not []:
for item in bulletprocess:
pygame.draw.circle(screen, item.color, item.position, item.radius)
if targetlist is not []:
for item in targetlist:
pygame.draw.circle(screen, [255, 0, 0], (item.xpos, item.ypos), 10)
pygame.draw.circle(screen, [255, 255, 255], (item.xpos, item.ypos), 8)
pygame.draw.circle(screen, [255, 0, 0], (item.xpos, item.ypos), 6)
pygame.draw.circle(screen, [255, 255, 255], (item.xpos, item.ypos), 4)
pygame.draw.circle(screen, [255, 0, 0], (item.xpos, item.ypos), 2)
# CURSOR
pygame.draw.circle(screen, [0, 0, 0], pygame.mouse.get_pos(), 6)
pygame.draw.circle(screen, [190, 0, 0], pygame.mouse.get_pos(), 3)
#TARGET DESTROYED COUNTER
tdcountvar = testfont16.render(f"Targets Destroyed: {targetsdestroyed}", False, [255, 255, 255], None)
screen.blit(tdcountvar, (10, 10))
# PRINT TO SCREEN #
pygame.display.flip()
#BULLET MOVEMENT CALCULATIONS
for item in bulletprocess:
positionxvar, positionyvar, targetxvar, targetyvar = item.position[0], item.position[1], item.target[0], item.target[1]
item.position = (positionxvar + (tickercount/item.speed)*(targetxvar - positionxvar), positionyvar + (tickercount/item.speed)*(targetyvar - positionyvar))
if abs(positionxvar - targetxvar) <= 5 and abs(positionyvar - targetyvar) <= 5: bulletprocess.pop(bulletprocess.index(item))
#COLLISION DETECTION BULLET AND TARGET
for bulletv in bulletprocess:
for targetv in targetlist:
if abs(bulletv.position[0] - targetv.xpos) <= 10 and abs(bulletv.position[1] - targetv.ypos) <= 10: targetlist.pop(targetlist.index(targetv)); targetsdestroyed += 1
# TICKER CLOCK FOR EVEN MORE PRECISION LAYER 2
if tickercount % 15 == 0:
for length in range(0, random.randint(2,5)):
createBullet()
tickercount = 0
if tickercount % 60 == 0:
createTarget()
tickercount += 1
clock.tick(60) # limits FPS to 60
pygame.quit()