요새 총기 유투브를 즐겨보고 있다. (ex. FPSRussia, Kentucky Ballistic, etc.)
그러다 보니까 총기에 대한 관심과 함께 자연스럽게 이러한 궁금증이 생겼다.
한국전쟁이 다시 일어난다면, 용사들이 평균적으로 몇 발 쏘고 전사하게 될까?
매우 암울한 상상이지만, 전쟁이 일어나면 사람이 죽게 될 것이다. 특히 육군 병력 중 용사들의 희생이 엄청나게 될텐데, 전사하기 전까지 평균적으로 몇 발의 총알을 소모하게 되는지 궁금해졌다.
그래서 시뮬레이션을 해보자고 생각했고 다양한 시각화 툴을 찾아보았다. 그렇게 해서 골라진 후보는 파이썬(Python) 모듈 파이게임(pygame)과 유니티(Unity)였다. 안타깝게도 유니티가 훨씬 입체적인 환경을 제공해주지만(애초에 3차원 게임 만드는데 주로 사용되니까), 유니티를 써본 적이 없어서 파이썬을 이용하기로 했다.
그렇게 해서 대략적인 방향성을 생각하고 그에 맞는 정보를 찾기로 했다.
아직까지는 미숙한 상태이고 여기서 더 발전시켜서 시뮬레이션까지 가보자!
import pygame, sys
# Player character
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load("./images/soldier1.png")
self.image = pygame.transform.scale(self.image, (100,80))
self.rect = self.image.get_rect(center = (screen_width/2, screen_height/2))
def update(self):
self.rect.center = pygame.mouse.get_pos()
def create_bullet(self):
return Bullet(pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1] - 30)
# Bullet object
class Bullet(pygame.sprite.Sprite):
def __init__(self, pos_x, pos_y):
super().__init__()
self.image = pygame.transform.scale(pygame.image.load("./images/556bullet.png"), (10,5))
self.rect = self.image.get_rect(center = (pos_x, pos_y))
def update(self):
self.rect.x += 20
if self.rect.x >= screen_width:
self.kill()
# General setup
pygame.init()
clock = pygame.time.Clock()
# Setting up the main window
screen_width, screen_height = 1280, 960
# Display surface -> the main screen where everything is done
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.mouse.set_visible(False)
pygame.display.set_caption('War simulation')
player = Player()
player_group = pygame.sprite.Group()
player_group.add(player)
bullet_group = pygame.sprite.Group()
while True:
# Handling input
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
bullet_group.add(player.create_bullet())
# Updating the window
screen.fill((30,30,30))
bullet_group.draw(screen)
player_group.draw(screen)
player_group.update()
bullet_group.update()
pygame.display.flip()
clock.tick(120)