Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import time
- pygame.init()
- display_width = 700
- display_height = 700
- clock = pygame.time.Clock()
- FPS = 30
- gameDisplay = pygame.display.set_mode((display_width, display_height))
- pygame.display.set_caption("radarSim")
- font = pygame.font.SysFont(None, 25)
- white = pygame.Color(255, 255, 255)
- black = pygame.Color(0, 0, 0)
- red = pygame.Color(255, 0, 0)
- green = pygame.Color(0, 255, 0)
- blue = pygame.Color(0, 0, 255)
- grey = pygame.Color(200, 200, 200)
- detection_area = [100, 100]
- detection_size = [500, 500]
- speed = [1]
- pulsing = False
- self_radius = [10]
- priority_loc = [554, 94]
- speed_loc = [435, 94, 470, 94]
- targets_loc = [165, 94, 240, 94]
- targets = [0]
- grid_color = [white, grey, black]
- foreign_loc = [0, 0]
- foreign_color = [red]
- target_set = False
- foreign_size = [20]
- def text_objects(text, color, text_x, text_y):
- textSurface = font.render(text, True, color)
- return textSurface, textSurface.get_rect()
- def message_to_screen(msg, color, text_x, text_y):
- textSurf, textRect = text_objects(msg, color, text_x, text_y)
- textRect.center = (text_x, text_y)
- gameDisplay.blit(textSurf, textRect)
- class Pulses:
- def __init__(self, x, y, radius=10, size=1, color=red):
- self.x = x
- self.y = y
- self.size = size
- self.color = color
- self.speed = speed
- def draw(self):
- pygame.draw.rect(gameDisplay, grid_color[0], (detection_area[0], detection_area[1], detection_size[0], detection_size[1]), 1)
- pygame.draw.line(gameDisplay, grid_color[1], (355, 100), (355, 600), 1)
- pygame.draw.line(gameDisplay, grid_color[1], (100, 350), (600, 350), 1)
- pygame.draw.circle(gameDisplay, white, (self.x, self.y), self_radius[0], self.size)
- Pulses.pulse(self)
- def pulse(self):
- pygame.draw.circle(gameDisplay, white, (self.x, self.y), 10, self.size)
- if pulsing:
- if self_radius[0] < 245:
- circleRect = pygame.draw.circle(gameDisplay, self.color, (self.x, self.y), self_radius[0], self.size)
- self_radius[0] += speed[0]
- for circle in circleRect:
- if circleRect[0] < foreign_loc[0]:
- if circleRect[1] > foreign_loc[1]:
- if circleRect[2] > foreign_loc[0]:
- if circleRect[3] < foreign_loc[1]:
- print("possible collision:", circleRect)
- else:
- self_radius[0] = 10
- pygame.draw.circle(gameDisplay, self.color, (self.x, self.y), self_radius[0], self.size)
- self_radius[0] += speed[0]
- else:
- self_radius[0] = 10
- def change_color(self):
- if self_radius[0] == 0:
- message_to_screen("Priority = 0", white, priority_loc[0], priority_loc[1])
- elif self_radius[0] <= 85:
- message_to_screen("Priority = 0", white, priority_loc[0], priority_loc[1])
- self.color = red
- elif self_radius[0] <= 170:
- message_to_screen("Priority = 1", white, priority_loc[0], priority_loc[1])
- self.color = green
- elif self_radius[0] <= 250:
- message_to_screen("Priority = 2", white, priority_loc[0], priority_loc[1])
- self.color = white
- elif self_radius[0] >= 250:
- message_to_screen("Priority = 2", white, priority_loc[0], priority_loc[1])
- self.color = white
- emitter1 = Pulses(355, 350)
- def event_(mod):
- global pulsing
- if mod == "k_up":
- if speed[0] >= 5:
- pass
- else:
- speed[0] += 1
- elif mod == "k_down":
- if speed[0] <= 1:
- speed[0] = 1
- pulsing = False
- else:
- speed[0] -= 1
- elif mod == "toggle":
- pulsing = not pulsing
- speed[0] = 1
- elif mod == "grid":
- if grid_color[0] == white:
- grid_color[0] = black
- grid_color[1] = black
- else:
- grid_color[0] = white
- grid_color[1] = grey
- elif mod == "target_vis":
- if foreign_color[0] == black:
- foreign_color[0] = red
- else:
- foreign_color[0] = black
- def display_text():
- message_to_screen("Targets Located:", white, targets_loc[0], targets_loc[1])
- message_to_screen(str(targets[0]), white, targets_loc[2], targets_loc[3])
- message_to_screen("Speed:", white, speed_loc[0], speed_loc[1])
- message_to_screen(str(speed[0]), white, speed_loc[2], speed_loc[3])
- def foreign_object():
- global target_set
- foreign_loc[0] = 200
- foreign_loc[1] = 400
- pygame.draw.rect(gameDisplay, foreign_color[0], (foreign_loc[0], foreign_loc[1],
- foreign_size[0], foreign_size[0]), 1)
- # pygame.draw.rect(gameDisplay, foreign_color[0], (foreign_loc[0], foreign_loc[1],
- # foreign_size[0], foreign_size[0]), 1)
- # if not target_set:
- # foreign_loc[0] = random.randrange(100, 501)
- # foreign_loc[1] = random.randrange(100, 501)
- # target_set = True
- # else:
- # pass
- def game_loop():
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_UP:
- event_("k_up")
- elif event.key == pygame.K_DOWN:
- event_("k_down")
- elif event.key == pygame.K_SPACE:
- event_("toggle")
- elif event.key == pygame.K_g:
- event_("grid")
- elif event.key == pygame.K_t:
- event_("target_vis")
- else:
- pass
- gameDisplay.fill(black)
- foreign_object()
- emitter1.draw()
- emitter1.change_color()
- display_text()
- pygame.display.update()
- clock.tick(FPS)
- still_playing = True
- while still_playing:
- game_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement