This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.py
71 lines (53 loc) · 1.95 KB
/
process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import pygame
import game_objects
from engine.vec2 import Vec2
from pygame.locals import *
import sound_manager as sounds
def collision(player):
if len(game_objects.Enemy.List) >= 1:
for enemy in game_objects.Enemy.List:
bullets = game_objects.Bullet.List
collision = pygame.sprite.spritecollide(enemy, bullets, False)
if collider(collision):
enemy.health -= enemy.damage(player.heft)
def collider(list_objects):
for hit in list_objects:
hit.destroy(game_objects.Bullet)
return True
return False
def keyboard(player, dt, key, last_key):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == pygame.K_e:
# depois implementos outros tipos de tiro
pass
key_direction = Vec2(0, 0)
if key[K_a]:
key_direction.x = -1
elif key[K_d]:
key_direction.x = +1
elif key[K_w]:
key_direction.y = -1
elif key[K_s]:
key_direction.y = +1
ray = player.rect.x + key_direction.x
if key[K_SPACE] and key[K_SPACE] is not last_key[K_SPACE]:
game_objects.Bullet(player.rect.x, player.rect.y,
'assets/sprites/fireb.png')
game_objects.Bullet(player.rect.x+player.rect.width, player.rect.y,
'assets/sprites/fireb.png')
# sounds.fx['primaryw'].play(player.rect.x, 800)
key_direction.normalize()
if ray < 0:
player.rect.x = 0
elif ray + player.rect.width > 800:
player.rect.x = 800 - player.rect.width
player.rect.x += key_direction.x * player.speed * dt
player.rect.y += key_direction.y * player.speed * dt