commands to units in fight stage
This commit is contained in:
parent
f5b3ba083f
commit
84a330fdca
2 changed files with 78 additions and 22 deletions
78
gui.py
78
gui.py
|
@ -3,6 +3,7 @@
|
||||||
from guilib import *
|
from guilib import *
|
||||||
import pygame
|
import pygame
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -1039,6 +1040,18 @@ def fight(screen, gs):
|
||||||
start_x += 20
|
start_x += 20
|
||||||
|
|
||||||
|
|
||||||
|
if gs.fight['action'] == 'selected_go':
|
||||||
|
selected_unit = gs.fight['units'][gs.fight['selected_unit']]
|
||||||
|
if selected_unit['type'] in ['pst']:
|
||||||
|
longness = 100
|
||||||
|
elif selected_unit['type'] in ['ptr']:
|
||||||
|
longness = 50
|
||||||
|
else:
|
||||||
|
longness = 200
|
||||||
|
|
||||||
|
x, y = gs.fight['selected_pos']
|
||||||
|
pygame.draw.circle(screen, (255, 0, 0), (x - 20, y + 20), longness, 5)
|
||||||
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
events = pygame.event.get()
|
events = pygame.event.get()
|
||||||
|
@ -1066,21 +1079,52 @@ def fight(screen, gs):
|
||||||
gs.game['fight_to'] = None
|
gs.game['fight_to'] = None
|
||||||
pygame.mouse.set_cursor(*pygame.cursors.arrow)
|
pygame.mouse.set_cursor(*pygame.cursors.arrow)
|
||||||
|
|
||||||
if gs.fight['action'] in ['looking']:
|
if gs.fight['action'] in ['looking', 'selected_go']:
|
||||||
for i in range(54):
|
for i in range(54):
|
||||||
for j in range(9):
|
for j in range(9):
|
||||||
index = gs.fight['fields'][i][j]
|
|
||||||
if isinstance(index, int):
|
|
||||||
x = 52 + i * 20
|
x = 52 + i * 20
|
||||||
y = 502 + j * 20
|
y = 502 + j * 20
|
||||||
|
index = gs.fight['fields'][i][j]
|
||||||
if x < x_m < x + 17 and y < y_m < y + 17:
|
if x < x_m < x + 17 and y < y_m < y + 17:
|
||||||
pygame.draw.rect(screen, (0, 0, 255), (x, y, 17, 17), 0)
|
pygame.draw.rect(screen, (0, 0, 255), (x, y, 17, 17), 0)
|
||||||
|
|
||||||
|
if isinstance(index, int):
|
||||||
if gs.fight['action'] == 'looking':
|
if gs.fight['action'] == 'looking':
|
||||||
gs.fight['selected_unit'] = index
|
gs.fight['selected_unit'] = index
|
||||||
gs.fight['selected_field'] = i, j
|
gs.fight['selected_field'] = i, j
|
||||||
gs.fight['selected_pos'] = x + 30, y - 10
|
gs.fight['selected_pos'] = x + 30, y - 10
|
||||||
gs.fight['action'] = 'selected'
|
gs.fight['action'] = 'selected'
|
||||||
|
|
||||||
|
if gs.fight['action'] == 'selected_go':
|
||||||
|
selected_unit = gs.fight['units'][gs.fight['selected_unit']]
|
||||||
|
if selected_unit['type'] in ['pst']:
|
||||||
|
longness = 120
|
||||||
|
elif selected_unit['type'] in ['ptr']:
|
||||||
|
longness = 40
|
||||||
|
else:
|
||||||
|
longness = 220
|
||||||
|
|
||||||
|
x_, y_ = gs.fight['selected_pos']
|
||||||
|
distance = int(math.sqrt((x_ - 20 - x_m)**2 + (y_ + 20 - y_m)**2))
|
||||||
|
|
||||||
|
if distance <= longness:
|
||||||
|
for i, log in enumerate(gs.fight['user_log']):
|
||||||
|
if log['unit'] == gs.fight['selected_unit']:
|
||||||
|
del gs.fight['user_log'][i]
|
||||||
|
break
|
||||||
|
|
||||||
|
gs.fight['user_log'].append({
|
||||||
|
'unit': gs.fight['selected_unit'],
|
||||||
|
'action': 'G',
|
||||||
|
'target': (x, y)
|
||||||
|
})
|
||||||
|
|
||||||
|
gs.fight['action'] = 'looking'
|
||||||
|
gs.fight['selected_unit'] = None
|
||||||
|
gs.fight['selected_field'] = None
|
||||||
|
gs.fight['selected_pos'] = None
|
||||||
|
|
||||||
|
|
||||||
if gs.fight['action'] == 'selected':
|
if gs.fight['action'] == 'selected':
|
||||||
selected_unit = gs.fight['units'][gs.fight['selected_unit']]
|
selected_unit = gs.fight['units'][gs.fight['selected_unit']]
|
||||||
if selected_unit['type'] in ['pst', 'ptr']:
|
if selected_unit['type'] in ['pst', 'ptr']:
|
||||||
|
@ -1099,7 +1143,20 @@ def fight(screen, gs):
|
||||||
x += 20
|
x += 20
|
||||||
# F - fortify
|
# F - fortify
|
||||||
if x < x_m < x + 20 and y < y_m < y + 20:
|
if x < x_m < x + 20 and y < y_m < y + 20:
|
||||||
pass
|
for i, log in enumerate(gs.fight['user_log']):
|
||||||
|
if log['unit'] == gs.fight['selected_unit']:
|
||||||
|
del gs.fight['user_log'][i]
|
||||||
|
break
|
||||||
|
|
||||||
|
gs.fight['user_log'].append({
|
||||||
|
'unit': gs.fight['selected_unit'],
|
||||||
|
'action': 'F'
|
||||||
|
})
|
||||||
|
|
||||||
|
gs.fight['action'] = 'looking'
|
||||||
|
gs.fight['selected_unit'] = None
|
||||||
|
gs.fight['selected_field'] = None
|
||||||
|
gs.fight['selected_pos'] = None
|
||||||
|
|
||||||
x += 20
|
x += 20
|
||||||
# G - go
|
# G - go
|
||||||
|
@ -1109,6 +1166,17 @@ def fight(screen, gs):
|
||||||
x += 20
|
x += 20
|
||||||
# S - shot
|
# S - shot
|
||||||
if x < x_m < x + 20 and y < y_m < y + 20:
|
if x < x_m < x + 20 and y < y_m < y + 20:
|
||||||
pass
|
for i, log in enumerate(gs.fight['user_log']):
|
||||||
|
if log['unit'] == gs.fight['selected_unit']:
|
||||||
|
del gs.fight['user_log'][i]
|
||||||
|
break
|
||||||
|
|
||||||
|
gs.fight['user_log'].append({
|
||||||
|
'unit': gs.fight['selected_unit'],
|
||||||
|
'action': 'S'
|
||||||
|
})
|
||||||
|
|
||||||
|
gs.fight['action'] = 'looking'
|
||||||
|
gs.fight['selected_unit'] = None
|
||||||
|
gs.fight['selected_field'] = None
|
||||||
|
gs.fight['selected_pos'] = None
|
||||||
|
|
16
guilib.py
16
guilib.py
|
@ -56,23 +56,10 @@ class GameSettings:
|
||||||
"""Object to save all game parameters during game."""
|
"""Object to save all game parameters during game."""
|
||||||
een = True # Game loop
|
een = True # Game loop
|
||||||
stage = 'start' # display stage of game (start, map, settings etc.)
|
stage = 'start' # display stage of game (start, map, settings etc.)
|
||||||
turn = 0 # Player starts
|
|
||||||
fullscreen = False # Fullscreen is off
|
|
||||||
|
|
||||||
countries = {} # Countries
|
countries = {} # Countries
|
||||||
maps = {} # Maps
|
maps = {} # Maps
|
||||||
ages = ['XIII', 'XIX']
|
ages = ['XIII', 'XIX']
|
||||||
log = [] # Game log
|
|
||||||
|
|
||||||
GREEN = (0, 180, 0)
|
|
||||||
RED = (180, 0, 0)
|
|
||||||
BLUE = (0, 0, 255)
|
|
||||||
BLACK = (0, 0, 0)
|
|
||||||
COLORS = [GREEN, RED, BLUE, BLACK]
|
|
||||||
|
|
||||||
PRINT = 0
|
|
||||||
LAST_POINT = 0
|
|
||||||
POINT = 0
|
|
||||||
|
|
||||||
HOME = os.path.expanduser("~")
|
HOME = os.path.expanduser("~")
|
||||||
HOME = os.path.join(HOME, '.rc_maumataskis')
|
HOME = os.path.join(HOME, '.rc_maumataskis')
|
||||||
|
@ -164,7 +151,8 @@ class GameSettings:
|
||||||
'selected_unit': None,
|
'selected_unit': None,
|
||||||
'selected_field': None,
|
'selected_field': None,
|
||||||
'selected_pos': None,
|
'selected_pos': None,
|
||||||
'action': 'looking'
|
'action': 'looking',
|
||||||
|
'user_log': []
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Reference in a new issue