Skip to content

Commit

Permalink
Pospieszne konczenie pracy
Browse files Browse the repository at this point in the history
  • Loading branch information
barnij committed Jun 22, 2019
1 parent 5f7afbd commit e7e348e
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 87 deletions.
62 changes: 61 additions & 1 deletion blast.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import pygame
import pygame.gfxdraw
from enums import Direction
from enums import Color
from settings import ARENAHEIGHT, CHAIN


class Blast(pygame.sprite.Sprite):
def __init__(self, owner):
super().__init__()
self.image = None
self.owner = owner
self.enemy = owner.enemy
self.time = None
self.rect = None
self.speed = 1
self.vector = [0, 0]
self.timetodestroy = 2000
self.damage = 0

def update(self):
if self.time is not None:
if pygame.time.get_ticks() - self.time >= self.timetodestroy:
self.kill()

if self.rect is not None:
arenaheight_q = ARENAHEIGHT - CHAIN - self.image.get_height()

if self.rect.y > arenaheight_q:
self.kill()

self.rect.x += self.vector[0]
self.rect.y += self.vector[1]

Expand Down Expand Up @@ -77,7 +86,7 @@ def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([30, 30])
self.image.set_alpha(50)
self.image.fill((192, 192, 192))
self.image.fill(Color.SILVER.value)
#self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
Expand All @@ -86,6 +95,7 @@ def __init__(self, owner, direction):
self.time = pygame.time.get_ticks()
self.knifecorrection(direction)
self.timetodestroy = 150
self.damage = 120

def knifecorrection(self, direction):
if direction == Direction.GORA:
Expand All @@ -110,3 +120,53 @@ def knifecorrection(self, direction):
elif direction == Direction.DOLPRAWO:
self.rect.x -= 10
self.rect.y += 10


class PistolBlast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([5, 5])
self.image.fill(Color.RED.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 5
self.time = pygame.time.get_ticks()
self.correction(direction)
self.timetodestroy = 1000
self.damage = 100


class TompsonBlast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([5, 5])
self.image.fill(Color.RED.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 7
self.time = pygame.time.get_ticks()
self.correction(direction)
self.timetodestroy = 2000
self.damage = 200


class Mp40Blast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([10, 10])
self.image.fill(Color.RED.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 6
self.time = pygame.time.get_ticks()
self.correction(direction)
self.timetodestroy = 3000
self.damage = 300


5 changes: 5 additions & 0 deletions characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def __init__(self):
super().__init__()
self.org_image = None
self.image = None
self.selectedgun = None
self.direction = Direction.GORA
self.rect = pygame.Rect((0, 0), [40, 40])
self.rect.x = ARENAWIDTH//2
self.rect.y = ARENAHEIGHT//2
self.maxhp = 1000
self.hp = self.maxhp
self.enemy = False

def set_position(self, x: int, y: int, d: Direction):
self.rect.x = x
Expand Down Expand Up @@ -54,3 +56,6 @@ def update(self, x: int, y: int, d: Direction):
self.image = rot_center(self.org_image, 135)
elif d is Direction.DOLPRAWO:
self.image = rot_center(self.org_image, -135)

def damage(self, n):
self.hp -= n
62 changes: 57 additions & 5 deletions enemy.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
import pygame
from characters import Character
from textures import img
from enums import Direction
from weapons import Pistol, Tompson, Mp40


class Enemy1(Character):
class Enemy(Character):
def __init__(self, x, y):
super().__init__()
self.image = self.org_image = img.enemy1
self.rect.x = x
self.rect.y = y
self.hp = 100
self.selectedgun = None
self.last_attack = 0
self.period = 0
self.enemy = True
self.pointsdamage = 0
self.points = 0

def damage(self, n):
super().damage(n)
if self.hp <= 0:
self.kill()
return True
return False

def attack(self, blasts):
if pygame.time.get_ticks() - self.last_attack < self.period:
return
blasts.add(self.selectedgun.blast(self, self.direction))
self.last_attack = pygame.time.get_ticks()

def draw(self, screen):
self.selectedgun.drawmini(self, screen)


class Enemy1(Enemy):
def __init__(self, x, y):
super().__init__(x, y)
self.image = self.org_image = img.enemy1
self.hp = 500
self.selectedgun = Pistol(0, 0)
self.period = 2000
self.pointsdamage = 5
self.points = 10


class Enemy2(Enemy):
def __init__(self, x, y):
super().__init__(x, y)
self.image = self.org_image = img.enemy2
self.hp = 1000
self.selectedgun = Tompson(0, 0)
self.period = 500
self.pointsdamage = 7
self.points = 20


class Enemy3(Enemy):
def __init__(self, x, y):
super().__init__(x, y)
self.image = self.org_image = img.enemy3
self.hp = 1500
self.selectedgun = Mp40(0, 0)
self.selectedgun.blast.speed = 12
self.period = 500
self.pointsdamage = 9
self.points = 35
9 changes: 9 additions & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ class Color(Enum):
GRAY = (128, 128, 128)
PURPLE = (128, 0, 128)
ORANGE = (255, 165, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)


class Spawn(Enum):
FIRST = (100, 50)
SECOND = (100, 500)
THIRD = (600, 50)
FOURTH = (600, 500)
Binary file added font/Terminus.ttf
Binary file not shown.
Binary file modified images/enemy1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/enemy2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/enemy3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gameover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/healthbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/knife_gun1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/mp40_gun4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/pistol_gun2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/tompson_gun3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 78 additions & 1 deletion interactive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pygame
import random
from blast import KnifeBlast
from enums import Direction
from settings import KROK
from interface import ManageInterface
Expand Down Expand Up @@ -29,6 +28,12 @@ def move(keys, player):
player.hp -= 10


def moveenemies(enemies, player, sprites):
enemies = enemies.sprites()
for enemy in enemies:
moveenemy(enemy, player, sprites)


def moveenemy(enemy, player, sprites):
krok = KROK/2
oldx = enemy.rect.x
Expand Down Expand Up @@ -106,9 +111,46 @@ def movecorrection(enemy, sprites):
def attack(keys, player, sprites, inter):
if not keys[pygame.K_SPACE] or pygame.time.get_ticks() - inter.last_attack < 500:
return

sq = inter.get_actual_square()

if sq.ammo <= 0:
return

inter.get_actual_square().ammo -= 1
sprites.add(player.selectedgun.blast(player, player.direction))
inter.last_attack = pygame.time.get_ticks()

if sq.ammo <= 0:
sq.active = False


def InAreaToAttack(player, enemy) -> bool:
d = enemy.direction
px = player.rect.x
py = player.rect.y
ex = enemy.rect.x
ey = enemy.rect.y
if d == Direction.PRAWO and px > ex and ey <= py <= ey + 40:
return True
if d == Direction.LEWO and px < ex and ey >= py >= ey - 40:
return True
if d == Direction.GORA and py < ey and ex <= px <= ex + 40:
return True
if d == Direction.DOL and py > ey and ex >= px >= ex - 40:
return True
if d != Direction.PRAWO and d != Direction.LEWO and d != Direction.GORA and d != Direction.DOL:
t = random.randrange(1000)
return True if t < 50 else False
return False


def attackenemy(enemies, player, blasts):
enemies = enemies.sprites()
for enemy in enemies:
if InAreaToAttack(player, enemy):
enemy.attack(blasts)


def changeweapon(keys, inter: ManageInterface, player):
what = None
Expand All @@ -123,3 +165,38 @@ def changeweapon(keys, inter: ManageInterface, player):

if what is not None:
inter.select_square(what, player)


def reacttoblast(blasts, characters, inter) -> bool:
intersecdic = pygame.sprite.groupcollide(characters, blasts, False, False)
for character, blastlist in intersecdic.items():
for blast in blastlist:
if character.enemy is not blast.enemy:
if character.enemy:
if character.damage(blast.damage):
inter.addpoints(character.pointsdamage)
else:
inter.addpoints(character.points)
else:
if character.damage(blast.damage):
return True
blast.kill()
return False


def spawnweapon(weapons, activeinits):
rx = random.randrange(100, 900)
ry = random.randrange(100, 500)
init = activeinits[random.randrange(len(activeinits))]
weapons.add(init(rx, ry))


def getweapon(weapons, player, inter):
weapons = weapons.sprites()
for weapon in weapons:
if pygame.sprite.collide_rect(weapon, player):
square = inter.get_square_with_gun(weapon)
if not square.active:
square.active = True
square.ammo += weapon.plusammo
weapon.kill()
Loading

0 comments on commit e7e348e

Please sign in to comment.