Nitpick here and there
This commit is contained in:
parent
a7c92163c0
commit
a82f3b5f14
12
README.md
12
README.md
|
@ -1,12 +1,20 @@
|
|||
# axuy
|
||||
|
||||
Mininalist first-person shooter
|
||||
Mininalist peer-to-peer first-person shooter
|
||||
|
||||
![icon](https://raw.githubusercontent.com/McSinyx/axuy/master/axuy/icon.png)
|
||||
|
||||
## Goals
|
||||
|
||||
* To be written in pure Python and thus be portable
|
||||
* Easy to read codebase as well as easy on resources
|
||||
* Logically generate visuals
|
||||
* Be functional when possible
|
||||
* P2P communication based on calculated *trust*
|
||||
|
||||
## Installation
|
||||
|
||||
The game is still under development. For testing, first install GLFW version 3.3
|
||||
The game is still work-in-progress. For testing, first install GLFW version 3.3
|
||||
(or higher), then install the game in editable mode:
|
||||
|
||||
```sh
|
||||
|
|
16
axuy/misc.py
16
axuy/misc.py
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Axuy. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from functools import wraps
|
||||
from itertools import (chain, combinations_with_replacement,
|
||||
permutations, product)
|
||||
from random import choices, shuffle
|
||||
|
@ -40,6 +41,14 @@ def color(code, value):
|
|||
return COLORS[code] * (value + 1) * 0.5
|
||||
|
||||
|
||||
def forever(func):
|
||||
"""Return a function that calls func forever."""
|
||||
@wraps(func)
|
||||
def loop(*args, **kwargs):
|
||||
while True: func(*args, **kwargs)
|
||||
return loop
|
||||
|
||||
|
||||
def mapidgen(replacement=False):
|
||||
"""Return a randomly generated map ID."""
|
||||
mapid = list(range(48))
|
||||
|
@ -102,10 +111,3 @@ def placeable(space, x, y, z, r):
|
|||
{twelve(x-r), twelve(x), twelve(x+r)},
|
||||
{twelve(y-r), twelve(y), twelve(y+r)},
|
||||
{nine(z-r), nine(z), nine(z+r)}))
|
||||
|
||||
|
||||
def whilst(func, cond=lambda:True):
|
||||
"""Call func until cond is broken."""
|
||||
def loop(*args, **kwargs):
|
||||
while cond(): func(*args, **kwargs)
|
||||
return loop
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Axuy. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
__version__ = '0.0.4'
|
||||
__version__ = '0.0.5'
|
||||
__doc__ = 'Axuy main loop'
|
||||
|
||||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
|
@ -24,7 +24,7 @@ from pickle import dumps, loads
|
|||
from socket import socket, SOCK_DGRAM, SOL_SOCKET, SO_REUSEADDR
|
||||
from threading import Event, Thread
|
||||
|
||||
from .misc import mapgen, mapidgen, whilst
|
||||
from .misc import forever, mapgen, mapidgen
|
||||
from .pico import Picobot
|
||||
from .view import ConfigReader, View
|
||||
|
||||
|
@ -68,7 +68,7 @@ class Peer:
|
|||
conn.send(dumps((mapid, self.peers+[self.addr])))
|
||||
conn.close()
|
||||
|
||||
@whilst
|
||||
@forever
|
||||
def push(self):
|
||||
"""Send own state to peers."""
|
||||
self.updated.wait()
|
||||
|
@ -80,7 +80,7 @@ class Peer:
|
|||
self.sock.sendto(data, peer)
|
||||
self.updated.clear()
|
||||
|
||||
@whilst
|
||||
@forever
|
||||
def pull(self):
|
||||
"""Receive peers' state."""
|
||||
data, addr = self.sock.recvfrom(1<<16)
|
||||
|
|
14
axuy/pico.py
14
axuy/pico.py
|
@ -200,6 +200,11 @@ class Picobot:
|
|||
"""Whether the pico is dead."""
|
||||
return self.health < 0
|
||||
|
||||
@property
|
||||
def forward(self):
|
||||
"""Direction in a NumPy array."""
|
||||
return self.rot[-1]
|
||||
|
||||
@property
|
||||
def pos(self) -> np.float32:
|
||||
"""Position in a NumPy array."""
|
||||
|
@ -230,8 +235,9 @@ class Picobot:
|
|||
"""Rotate yaw radians around y-axis
|
||||
and pitch radians around x-axis.
|
||||
"""
|
||||
self.rot = (matrix33.create_from_x_rotation(pitch)
|
||||
@ matrix33.create_from_y_rotation(yaw) @ self.rot)
|
||||
self.rot = (matrix33.create_from_x_rotation(pitch, dtype=np.float32)
|
||||
@ matrix33.create_from_y_rotation(yaw, dtype=np.float32)
|
||||
@ self.rot)
|
||||
|
||||
def update(self, right=0, upward=0, forward=0):
|
||||
"""Recover health point and try to move in the given direction."""
|
||||
|
@ -252,6 +258,6 @@ class Picobot:
|
|||
"""Shoot in the forward direction."""
|
||||
if self.recoil_t or self.dead: return
|
||||
self.recoil_t = 1.0 / RPS
|
||||
self.recoil_u = [0, 0, -1] @ self.rot
|
||||
self.recoil_u = -self.forward
|
||||
self.shards[max(self.shards, default=0) + 1] = Shard(
|
||||
self.addr, self.space, self.pos, self.rot)
|
||||
self.addr, self.space, self.pos + self.forward*RPICO, self.rot)
|
||||
|
|
|
@ -49,6 +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
|
||||
|
||||
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],
|
||||
|
@ -573,7 +574,11 @@ class View:
|
|||
|
||||
self.context.screen.use()
|
||||
self.context.clear()
|
||||
self.edge['abrtn'].value = (self.fov*self.health) ** -CONWAY
|
||||
if self.camera.dead:
|
||||
abrtn = ABRTN_MAX
|
||||
else:
|
||||
abrtn = min(ABRTN_MAX, (self.fov*self.health) ** -CONWAY)
|
||||
self.edge['abrtn'].value = abrtn
|
||||
self.edge['zoom'].value = (self.zmlvl + 1.0) / 100
|
||||
self.combine.render(moderngl.TRIANGLES)
|
||||
glfw.swap_buffers(self.window)
|
||||
|
|
Loading…
Reference in New Issue