-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovement.py
More file actions
66 lines (56 loc) · 1.69 KB
/
movement.py
File metadata and controls
66 lines (56 loc) · 1.69 KB
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
import keyboard
import random
import time
import main
def move_player(character, field):
"""
Take in arrow key press and increment
X or Y position
"""
increment = character.speed
while True:
try:
if keyboard.is_pressed("left arrow") and character.x_pos > (
0 + increment + 1
):
character.x_pos -= increment
if keyboard.is_pressed("right arrow") and character.x_pos < (
field.x_size - increment
):
character.x_pos += increment
if keyboard.is_pressed("down arrow") and character.y_pos < (
field.y_size - increment
):
character.y_pos += increment
if keyboard.is_pressed("up arrow") and character.y_pos > (
0 + increment + 1
):
character.y_pos -= increment
time.sleep(0.0001)
except:
pass
def move_point(point, field):
"""
Generate 2 random numbers cooresponding to X and Y movement
If num1 = 0 move left
If num1 = 1 move right
If num2 = 0 move up
If num2 = 1 move down
"""
while True:
num1 = random.randrange(2)
num2 = random.randrange(2)
try:
if num1 == 0 and point.x_pos > 1:
point.x_pos -= 1
if num1 == 1 and point.x_pos < field.x_size:
point.x_pos += 1
if num2 == 0 and point.y_pos > 1:
point.y_pos -= 1
if num2 == 1 and point.y_pos < field.y_size:
point.y_pos += 1
time.sleep(1)
except:
pass
if __name__ == "__main__":
main.main()