-
Notifications
You must be signed in to change notification settings - Fork 1
/
my_movement.py
82 lines (78 loc) · 2.15 KB
/
my_movement.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
72
73
74
75
76
77
78
79
80
81
82
# move.py
import pygame
import time
import random
import math
class movement():
def move(self, p, b, dt, screen):
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
# if keystroke is pressed check its left or right
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
p.player_movX = (dt * p.player_vel)
elif event.key == pygame.K_LEFT:
p.player_movX = -(dt * p.player_vel)
# elif event.key == pygame.K_UP:
# player_movY = -(dt * player_vel)
# elif event.key == pygame.K_DOWN:
# player_movY = (dt * player_vel)
elif event.key == pygame.K_SPACE:
if b.bullet_state == 'ready':
b.shoot(p, screen)
elif event.key == pygame.K_ESCAPE:
print("Escape key.")
else:
pass
if event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
pass
elif event.key == pygame.K_ESCAPE:
return False
print("Existing the Game.")
elif event.key == pygame.K_RIGHT:
p.player_movX = 0
elif event.key == pygame.K_LEFT:
p.player_movX = 0
# elif event.key == pygame.K_UP:
# player_movY = 0
# elif event.key == pygame.K_DOWN:
# player_movY = 0
return True
# main file code
"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# if keystroke is pressed check its left or right
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
p.player_movX = (dt * p.player_vel)
print("right")
elif event.key == pygame.K_LEFT:
print("left")
p.player_movX = -(dt * p.player_vel)
elif event.key == pygame.K_SPACE:
if b.bullet_state == 'ready':
b.shoot(p, screen)
elif event.key == pygame.K_ESCAPE:
print("Escape key.")
else:
pass
if event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
pass
elif event.key == pygame.K_ESCAPE:
running = False
print("Existing the Game.")
elif event.key == pygame.K_RIGHT:
p.player_movX = 0
elif event.key == pygame.K_LEFT:
p.player_movX = 0
# elif event.key == pygame.K_UP:
# player_movY = 0
# elif event.key == pygame.K_DOWN:
# player_movY = 0
"""
# collision