当前位置:网站首页>PyGame electronic warfare simulation effect
PyGame electronic warfare simulation effect
2022-07-22 17:08:00 【Zhichao_ ninety-seven】
use pygame Made a basic scene , The forward and steering of the jammer can be controlled through the keyboard , So as to observe the change of the jamming range of the jammer .
If you need picture materials, download them here : Picture material
( It's not easy to make , Please pay attention )
effect :
pygame Electronic warfare simulation
Code :
import pygame,sys,math
# 1. Initialization operation
pygame.init()
# 2. Create game window
window_size_width = 1807
window_size_height = 826
window = pygame.display.set_mode((window_size_width,window_size_height))
window.fill((255,255,255)) # Set the background color
background=pygame.image.load("resource/images/map.png")
background_transfrom = pygame.transform.scale(background,(window_size_width,window_size_height))
window.blit(background_transfrom,(0,0)) # Parameters : Apply colours to a drawing object , coordinate
pygame.display.flip() # First refresh
# Set game title
pygame.display.set_caption(' Electronic warfare simulation ')
# Draw a rectangular
pygame.draw.rect(window,(0,255,0),(50,400,1700,400),2) # Parameters : On which object , Line color , Rectangle range ( Abscissa , Ordinate , Width , Height ), Line width
# Create a font object
font = pygame.font.Font("C:/Windows/Fonts/STXINWEI.TTF",30) # Parameters : The font file , font size
# Create text object
text = font.render(" shipment 8 Jammer activity range ",True,(255,0,0)) # Parameters : Written content ,True, Text color , The background color
# Zoom and rotate
text_rotozoom = pygame.transform.rotozoom(text, 0, 1) # Parameters : The goal is , Rotation Angle , Zoom ratio
w,h = text_rotozoom.get_size() # Get text size
window.blit(text_rotozoom,(window_size_width-350,window_size_height-400 ))
# Put the radar car 1
leida1 = pygame.image.load("resource/images/ Radar vehicle .png")
leida1_x, leida1_y = 930,100 # Radar initial coordinates
leida1_rotozoom = pygame.transform.rotozoom(leida1, 0, 0.05) # rotate 、 The zoom
window.blit(leida1_rotozoom,(leida1_x, leida1_y)) # Show
pygame.draw.circle(window,(0,0,255),(leida1_x, leida1_y),220,0) # radar 1 Radiation range
# Put the radar car 2
leida2 = pygame.image.load("resource/images/ Radar vehicle .png")
leida2_x, leida2_y = 800,90 # Radar initial coordinates
leida2_rotozoom = pygame.transform.rotozoom(leida2, 0, 0.05) # rotate 、 The zoom
window.blit(leida2_rotozoom,(leida2_x, leida2_y)) # Show
pygame.draw.circle(window,(0,0,255),(leida2_x, leida2_y),220,0) # radar 2 Radiation range
# Place J 20
plane_j20 = pygame.image.load("resource/images/ fighters 20.png")
plane_j20_x, plane_j20_y = 930,560 # fighters 20 Initial coordinates
plane_j20_r = 290 # Initial rotation angle of the aircraft
plane_j20_v = 0.1 # The speed of the plane
plane_j20_rotozoom = pygame.transform.rotozoom(plane_j20, plane_j20_r, 0.2) # rotate 、 The zoom
window.blit(plane_j20_rotozoom,(plane_j20_x, plane_j20_y)) # Show
# Release and transport 8 Jammer
plane = pygame.image.load("resource/images/ shipment 8 Jammer .png")
plane_x, plane_y = 1200,600 # Aircraft initial coordinates
plane_r = 270 # Initial rotation angle of the aircraft
r = plane_r - 270 # Initial angle
add_r = 1 # Increased angle per turn
plane_v = 1 # The speed of the plane
is_move = False # Whether to move
is_turn = False # Whether to turn
plane_rotozoom = pygame.transform.rotozoom(plane, plane_r, 0.3) # rotate 、 The zoom
window.blit(plane_rotozoom,(plane_x, plane_y)) # Show
pygame.draw.circle(window,(0,0,255),(plane_x, plane_y),500,1) # shipment 8 Interference range
pygame.display.update() # Refresh
# 3. Keep the game running
while True:
window.blit(background_transfrom, (0, 0)) # Refresh the background
window.blit(text_rotozoom, (window_size_width - 350, window_size_height - 400)) # Refresh text
window.blit(plane_rotozoom, (plane_x, plane_y)) # Refresh shipment 8 Jammer
window.blit(leida1_rotozoom, (leida1_x, leida1_y)) # Refresh the radar 1
pygame.draw.circle(window, (255, 0, 0), (leida1_x, leida1_y), 220, 1) # radar 1 Radiation range
window.blit(leida2_rotozoom, (leida2_x, leida2_y)) # Refresh the radar 2
pygame.draw.circle(window, (255, 0, 0), (leida2_x, leida2_y), 220, 1) # radar 2 Radiation range
pygame.draw.circle(window, (0, 0, 255), (plane_x, plane_y), 500, 1) # shipment 8 Interference range
# Draw line
points = []
for y in range(120, 560, 10):
x = 650 + y / 2
points.append([x, y])
for i in range(0, len(points), 2):
pygame.draw.line(window, (255, 0, 0), (points[i][0], points[i][1]), (points[i + 1][0], points[i + 1][1]),3) # Parameters : On which object , Color , The starting point of the line , The end of the line
if plane_j20_y > 120:
plane_j20_y = plane_j20_y - 2*plane_j20_v
plane_j20_x = plane_j20_x - 1*plane_j20_v
else:
plane_j20_x, plane_j20_y = 930, 560
window.blit(plane_j20_rotozoom, (plane_j20_x, plane_j20_y))
# Draw a rectangular
pygame.draw.rect(window, (0, 255, 0), (50, 400, 1700, 400), 2) # Parameters : On which object , Line color , Rectangle range ( Abscissa , Ordinate , Width , Height ), Line width
if is_move == True:
if 90 > r >= 0:
plane_y = plane_y - plane_v * math.cos((r) * (math.pi / 180))
plane_x = plane_x - plane_v * math.sin((r) * (math.pi / 180))
elif 180 > r >= 90:
plane_y = plane_y - plane_v * math.cos((r) * (math.pi / 180))
plane_x = plane_x - plane_v * math.sin((r) * (math.pi / 180))
elif 270 > r >= 180:
plane_y = plane_y - plane_v * math.cos((r) * (math.pi / 180))
plane_x = plane_x - plane_v * math.sin((r) * (math.pi / 180))
elif 360 > r >= 270:
plane_y = plane_y - plane_v * math.cos((r) * (math.pi / 180))
plane_x = plane_x - plane_v * math.sin((r) * (math.pi / 180))
window.blit(plane_rotozoom, (plane_x, plane_y))
pygame.display.update()
if is_turn == True:
print(" Current rotation angle :{}".format(r))
r = r + add_r
if r > 360:
r = r - 360
elif r < 0:
r = r + 360
plane_rotozoom = pygame.transform.rotozoom(plane, r + 270, 0.3)
window.blit(plane_rotozoom, (plane_x, plane_y))
pygame.display.update()
# 4. Detect events
for event in pygame.event.get():
# Respond accordingly to the event
if event.type == pygame.QUIT: # If you click the close button
sys.exit()
if event.type == pygame.KEYDOWN: # Press the keyboard
if chr(event.key) == "q": # Counter clockwise rotation
is_turn = True
elif chr(event.key) == "w": # Advance towards the specified angle
is_move = True
elif event.type == pygame.KEYUP:
is_move = False
is_turn = False
pygame.display.update()
边栏推荐
- [open hand] hande enterprise PAAS platform hzero heavy open source!
- 汉得数字平台体系及试用知多少?
- 5. SSH Remote Service
- Mecol Studio - the third assignment of harmonyos application development training
- 【网页性能优化】-—— 关于图片懒加载
- 1143. Longest common subsequence
- Hande apaas low code platform Feida 2.3.0 release was officially released!
- tensorflow 神经网络实现鸢尾花分类
- 2022/7/19-日报
- numpy.ascontiguousarray
猜你喜欢
QT warning: c4819: this file contains characters that cannot be represented in the current code page (936). Please save the file in Unicode format to prevent data loss
[open hand] hande enterprise PAAS platform hzero heavy open source!
lvs看这篇就够了
Hande integrated platform Jixing otter version 1.4.0 was officially released!
JWT学习
Codeforce d2. RGB substring (hard version) sliding window
Yuanqi Digitalization: existing mode or open source innovation Lixia action
[vs] how to check where the thread is blocked
【OPEN HAND】汉得企业级PaaS平台HZERO重磅开源!
Qt5.9.2初次导入使用msvc2017_64编译器遇到的问题记录
随机推荐
Concis组件库 | 暗黑模式设计
tf.get_ default_ graph
14_响应模型
ffmpeg-rk3399 ffplay 学习分析
Blob URL DataURL
Cross domain problem (CORS) detailed description and solution
QT warning: c4819: this file contains characters that cannot be represented in the current code page (936). Please save the file in Unicode format to prevent data loss
ES6 template string
Qt warning: C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
opencv支持H264视频编码
Mecol Studio - harmonyos second assignment
数据湖:数据湖技术架构演进
[red team] att & CK - browser extension for persistence
TensorFlow 预测日销量
[open hand] hande enterprise PAAS platform hzero heavy open source!
[paper translation] generalized radio representation learning via cross supervision between images
Make good use of these seven tips in code review, and it is easy to establish your opposition alliance
pygame 电子战模拟效果
JWT学习
MySQL query plan key_ How to calculate len