Allow lunging by shooting backward

This commit is contained in:
Nguyễn Gia Phong 2019-09-20 20:27:04 +07:00
parent 84f829628b
commit 91a6b54e04
3 changed files with 21 additions and 9 deletions

View File

@ -254,10 +254,18 @@ class Picobot:
if self.placeable(y=y): self.y = y % 12
if self.placeable(z=z): self.z = z % 9
def shoot(self):
"""Shoot in the forward direction."""
def shoot(self, backward=False):
"""Shoot in the forward direction unless specified otherwise."""
if self.recoil_t or self.dead: return
self.recoil_t = 1.0 / RPS
self.recoil_u = -self.forward
self.shards[max(self.shards, default=0) + 1] = Shard(
self.addr, self.space, self.pos + self.forward*RPICO, self.rot)
index = max(self.shards, default=0) + 1
if backward:
self.recoil_u = self.forward
self.shards[index] = Shard(self.addr, self.space,
-self.pos - self.recoil_u*RPICO,
-self.rot)
else:
self.recoil_u = -self.forward
self.shards[index] = Shard(self.addr, self.space,
self.pos - self.recoil_u*RPICO,
self.rot)

View File

@ -16,6 +16,7 @@ Move backward: s
Move left: a
Move right: d
Primary: MOUSE_BUTTON_1
Secondary: MOUSE_BUTTON_2
# Mouse speed relative to FOV and DPI,
# in radians per inch at FOV of 60 with a 800 DPI mouse.
Mouse speed: 3

View File

@ -41,7 +41,7 @@ from .misc import abspath, color, neighbors
CONTROL_ALIASES = (('Move left', 'left'), ('Move right', 'right'),
('Move forward', 'forward'), ('Move backward', 'backward'),
('Primary', '1st'))
('Primary', '1st'), ('Secondary', '2nd'))
MOUSE_PATTERN = 'MOUSE_BUTTON_[1-{}]'.format(glfw.MOUSE_BUTTON_LAST + 1)
INVALID_CONTROL_ERR = '{}: {} is not recognized as a valid control key'
GLFW_VER_WARN = 'Your GLFW version appear to be lower than 3.3, '\
@ -49,7 +49,7 @@ GLFW_VER_WARN = 'Your GLFW version appear to be lower than 3.3, '\
ZMIN, ZMAX = -1.0, 1.0
CONWAY = 1.303577269034
ABRTN_MAX = 1.0
ABRTN_MAX = 0.42069
QUAD = np.float32([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]).tobytes()
OXY = np.float32([[0, 0, 0], [1, 0, 0], [1, 1, 0],
@ -399,8 +399,11 @@ class View:
Present as a callback for GLFW MouseButton event.
"""
if button == self.mouse['1st'] and action == glfw.PRESS:
self.camera.shoot()
if action == glfw.PRESS:
if button == self.mouse['1st']:
self.camera.shoot()
elif button == self.mouse['2nd']:
self.camera.shoot(backward=True)
@property
def width(self) -> int: