forked from nicholscrawford/FrogGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_builder.py
More file actions
91 lines (76 loc) · 2.87 KB
/
Copy pathmap_builder.py
File metadata and controls
91 lines (76 loc) · 2.87 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import threading
import main
from pynput import keyboard
current_mapcomponent = None
current_mapcomponent_x = None
current_mapcomponent_y = None
current_mapcomponent_color = None
current_mapcomponent_width = None
current_mapcomponent_height = None
def on_press(key):
global current_mapcomponent
global current_mapcomponent_x
global current_mapcomponent_y
global current_mapcomponent_color
global current_mapcomponent_width
global current_mapcomponent_height
if str(key) == "'n'":
print(
f"MapComponent({current_mapcomponent_width}, {current_mapcomponent_height}, {current_mapcomponent_color}, {current_mapcomponent_x}, {current_mapcomponent_y}),"
)
if current_mapcomponent is not None:
current_mapcomponent.reset_image(
current_mapcomponent_width,
current_mapcomponent_height,
(0, 0, 255),
current_mapcomponent_x,
current_mapcomponent_y,
)
current_mapcomponent_x = main.camera_position.x + main.WINDOW_WIDTH / 2
current_mapcomponent_y = main.camera_position.y + main.WINDOW_HEIGHT / 2
current_mapcomponent_color = (255, 0, 0)
current_mapcomponent_width = 200
current_mapcomponent_height = 20
current_mapcomponent = main.MapComponent(
current_mapcomponent_width,
current_mapcomponent_height,
current_mapcomponent_color,
current_mapcomponent_x,
current_mapcomponent_y,
)
main.map_components.append(current_mapcomponent)
main.all_sprites.add(current_mapcomponent)
main.collision_sprites.add(current_mapcomponent)
if str(key) == "Key.left":
current_mapcomponent_x -= 10
if str(key) == "Key.right":
current_mapcomponent_x += 10
if str(key) == "Key.up":
current_mapcomponent_y -= 10
if str(key) == "Key.down":
current_mapcomponent_y += 10
if str(key) == "'w'":
current_mapcomponent_height -= 10
if str(key) == "'s'":
current_mapcomponent_height += 10
if str(key) == "'a'":
current_mapcomponent_width -= 10
if str(key) == "'d'":
current_mapcomponent_width += 10
current_mapcomponent.reset_image(
current_mapcomponent_width,
current_mapcomponent_height,
current_mapcomponent_color,
current_mapcomponent_x,
current_mapcomponent_y,
)
if __name__ == "__main__":
host = "0.0.0.0"
port = 5000 # You can use any port you like, but make sure it's not already in use
# Start the game loop in a separate thread
game_thread = threading.Thread(target=main.game_loop)
game_thread.start()
keyboard_listener = keyboard.Listener(on_press=on_press)
keyboard_listener.start()
# Start the Flask-SocketIO server
main.socketio.run(main.app, host=host, port=port)