diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2017-10-21 17:40:10 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2017-10-21 17:40:10 +0700 |
commit | daae5de9b7531a5401c88b1c3e5c0e6109b9e40b (patch) | |
tree | 1cd960c5cb5c1c6467f009f05507edd0c64eac82 /brutalmaze/weapons.py | |
parent | 81d0b68811283f35645d16bdec3aa7eae621cd02 (diff) | |
download | brutalmaze-daae5de9b7531a5401c88b1c3e5c0e6109b9e40b.tar.gz |
Partially implement long-ranged attacks
Diffstat (limited to 'brutalmaze/weapons.py')
-rw-r--r-- | brutalmaze/weapons.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/brutalmaze/weapons.py b/brutalmaze/weapons.py new file mode 100644 index 0000000..108b042 --- /dev/null +++ b/brutalmaze/weapons.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# characters.py - module for weapon classes +# This file is part of brutalmaze +# +# brutalmaze is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# brutalmaze is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with brutalmaze. If not, see <http://www.gnu.org/licenses/>. +# +# Copyright (C) 2017 Nguyễn Gia Phong + +__doc__ = 'brutalmaze module for weapon classes' + +from math import pi, cos, sin + +from pygame.time import get_ticks + +from .constants import * +from .utils import randsign, regpoly, fill_aapolygon, pos, sign + + +class Bullet: + """Object representing a bullet.""" + def __init__(self, surface, x, y, angle, color): + self.surface = surface + self.x, self.y, self.angle, self.color = x, y, angle, color + self.fall_time = get_ticks() + BULLET_LIFETIME + + def update(self, fps, distance): + """Update the bullet.""" + s = distance * 8 / fps + self.x += s * cos(self.angle) + self.y += s * sin(self.angle) + hexagon = regpoly(6, distance // 4, self.angle, self.x, self.y) + fill_aapolygon(self.surface, hexagon, self.color) + + def place(self, x, y, step): + """Move the bullet by (x, y) (in steps).""" + self.x += x * step + self.y += y * step |