Skip to content

Commit f7a88d7

Browse files
Moving to arcade (basic game created)
1 parent 7e86980 commit f7a88d7

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

Assets/spawn area.png

-7.01 KB
Binary file not shown.

Code/Game.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,86 @@
11
import asyncio
22
import random
3-
import threading
4-
3+
import time
54
import arcade
6-
import keyboard
5+
from PIL import Image
6+
77

8-
s_width = 1280
9-
s_height = 720
8+
s_width, s_height = arcade.window_commands.get_display_size()
109
s_title = "Aim Trainer"
1110

1211

12+
image = Image.open("../Assets/quit_screen.png")
13+
img_final = image.resize((s_width,s_height))
14+
img_final.save('quitscreen.png')
1315
cursorx = 0
1416
cursory = 0
15-
targetX = random.randint(250, 1616 - 10)
16-
targetY = random.randint(10, 1080 - 74)
17+
targetX = random.randint((s_width/4)-26,(s_width/4)*3+26)
18+
targetY = random.randint(26,s_height-26)
1719
target = arcade.Sprite("../Assets/obj.png", center_x= targetX, center_y=targetY)
1820
cursor = arcade.Sprite("../Assets/cursor.png", center_x= 100, center_y=100)
19-
#collide = arcade.check_for_collision()
21+
quit_button = arcade.Sprite("../Assets/quit.png", center_x=(s_width/8)*7.5, center_y=s_height-50)
22+
quit_press = False
23+
score = 0
24+
hitsound = arcade.load_sound("../Assets/hit.mp3")
25+
goodbye = arcade.load_sound("../Assets/goodbye.mp3",True)
26+
#bye = arcade.Sprite("../Assets/quit_screen.png",center_x=(s_width/2),center_y=(s_height/2))
2027

2128

2229
def draw_objects():
30+
quit_button.draw()
31+
arcade.draw_text(f"Score = {score}",10,s_height-76,arcade.color.RED_ORANGE,38)
32+
arcade.draw_rectangle_outline((s_width/2),(s_height/2),((s_width/4)*3),s_height,arcade.color.RED_ORANGE,10)
2333
target.draw()
2434
cursor.draw()
25-
35+
#async def bye(a):
36+
#if a == True:
37+
#bye.draw()
2638

2739
class gam(arcade.Window):
2840
def __init__(self, s_width, s_height, s_title):
2941
super().__init__(s_width, s_height, s_title, fullscreen=True, resizable=False, update_rate=1 / 165,
30-
antialiasing=False,visible=True)
42+
antialiasing=True,visible=True)
3143
self.set_mouse_visible(False)
3244
arcade.set_background_color(arcade.color.BLACK)
3345
self.clicked = False
46+
#self.draw = False
3447

3548
def on_draw(self):
3649
arcade.start_render()
3750
draw_objects()
51+
#asyncio.run(bye(self.draw))
3852
def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
3953
cursor.center_x = x
4054
cursor.center_y = y
4155
def on_update(self, delta_time: float):
4256
global target, targetY,targetX
43-
global cursor
57+
global cursor, score, quit_press, quit_button, bye
4458
target.update()
4559
cursor.update()
4660
collide = arcade.check_for_collision(target,cursor)
4761
if collide == True and self.clicked == True:
48-
target.center_y = random.randint(16, 1080 - 74)
49-
target.center_x = random.randint(266, 1616 - 10)
62+
hitsound.play()
63+
target.center_y = random.randint(26,s_height-26)
64+
target.center_x = random.randint((s_width/4)-26,(s_width/4)*3+26)
5065
self.clicked = False
66+
score+=1
67+
self.quit = arcade.check_for_collision(quit_button,cursor)
68+
if self.quit == True and quit_press == True:
69+
arcade.close_window()
70+
goodbye.play()
71+
time.sleep(4.75)
72+
exit()
5173
def on_key_release(self, symbol, modifiers):
52-
if symbol == arcade.key.Z or symbol == arcade.key.X:
53-
self.clicked = True
54-
74+
collide = arcade.check_for_collision(target,cursor)
75+
if collide == True:
76+
if symbol == arcade.key.Z or symbol == arcade.key.X :
77+
self.clicked = True
78+
def on_mouse_press(self, x: float, y: float, button, modifiers: int):
79+
global quit_press, quit_button
80+
self.quit = arcade.check_for_collision(quit_button, cursor)
81+
if self.quit == True:
82+
if button == arcade.MOUSE_BUTTON_LEFT:
83+
quit_press = True
5584

5685
gam(s_width, s_height, s_title)
5786
arcade.run()

Laucher.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
from subprocess import call
21
import os
2+
from subprocess import call
3+
34
ph = os.path.join("../Aim-Trainer/Code/Game.py")
5+
6+
47
class CallPy(object):
5-
def __init__(self, path = ph, path_2="../Aim-trainer-main/Code/Game.py"):
6-
self.path = path
7-
self.path_2 = path_2
8-
def call_file(self):
9-
call(["Python", "{}".format(self.path)])
10-
def call_2(self):
11-
call(["Python","{}".format(self.path_2)])
8+
def __init__(self, path=ph, path_2="../Aim-trainer-main/Code/Game.py"):
9+
self.path = path
10+
self.path_2 = path_2
11+
12+
def call_file(self):
13+
call(["Python", "{}".format(self.path)])
14+
15+
def call_2(self):
16+
call(["Python", "{}".format(self.path_2)])
17+
18+
1219
if __name__ == "__main__":
1320
c = CallPy()
1421
try:
1522
c.call_file()
1623
except NotADirectoryError:
17-
c.call_2()
24+
c.call_2()

0 commit comments

Comments
 (0)