|
1 | 1 | import asyncio |
2 | 2 | import random |
3 | | -import threading |
4 | | - |
| 3 | +import time |
5 | 4 | import arcade |
6 | | -import keyboard |
| 5 | +from PIL import Image |
| 6 | + |
7 | 7 |
|
8 | | -s_width = 1280 |
9 | | -s_height = 720 |
| 8 | +s_width, s_height = arcade.window_commands.get_display_size() |
10 | 9 | s_title = "Aim Trainer" |
11 | 10 |
|
12 | 11 |
|
| 12 | +image = Image.open("../Assets/quit_screen.png") |
| 13 | +img_final = image.resize((s_width,s_height)) |
| 14 | +img_final.save('quitscreen.png') |
13 | 15 | cursorx = 0 |
14 | 16 | 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) |
17 | 19 | target = arcade.Sprite("../Assets/obj.png", center_x= targetX, center_y=targetY) |
18 | 20 | 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)) |
20 | 27 |
|
21 | 28 |
|
22 | 29 | 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) |
23 | 33 | target.draw() |
24 | 34 | cursor.draw() |
25 | | - |
| 35 | +#async def bye(a): |
| 36 | + #if a == True: |
| 37 | + #bye.draw() |
26 | 38 |
|
27 | 39 | class gam(arcade.Window): |
28 | 40 | def __init__(self, s_width, s_height, s_title): |
29 | 41 | 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) |
31 | 43 | self.set_mouse_visible(False) |
32 | 44 | arcade.set_background_color(arcade.color.BLACK) |
33 | 45 | self.clicked = False |
| 46 | + #self.draw = False |
34 | 47 |
|
35 | 48 | def on_draw(self): |
36 | 49 | arcade.start_render() |
37 | 50 | draw_objects() |
| 51 | + #asyncio.run(bye(self.draw)) |
38 | 52 | def on_mouse_motion(self, x: float, y: float, dx: float, dy: float): |
39 | 53 | cursor.center_x = x |
40 | 54 | cursor.center_y = y |
41 | 55 | def on_update(self, delta_time: float): |
42 | 56 | global target, targetY,targetX |
43 | | - global cursor |
| 57 | + global cursor, score, quit_press, quit_button, bye |
44 | 58 | target.update() |
45 | 59 | cursor.update() |
46 | 60 | collide = arcade.check_for_collision(target,cursor) |
47 | 61 | 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) |
50 | 65 | 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() |
51 | 73 | 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 |
55 | 84 |
|
56 | 85 | gam(s_width, s_height, s_title) |
57 | 86 | arcade.run() |
0 commit comments