8000 Update · pythonarcade/demo@2431f76 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2431f76

Browse files
author
Paul V Craven
committed
Update
1 parent f2d125f commit 2431f76

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

camera/camera_view.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ def load_texture_pair(filename):
3535
"""
3636
Load a texture pair, with the second being a mirror image.
3737
"""
38+
texture = arcade.load_texture(filename)
3839
return [
39-
arcade.load_texture(filename),
40-
arcade.load_texture(filename, flipped_horizontally=True),
40+
texture,
41+
texture.flip_vertically(),
4142
]
4243

4344
class PlayerCharacter(arcade.Sprite):

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def create_views(self):
3333
view = StartView(3.0)
3434
self.view_list.append(view)
3535

36+
from spatial_hash.spatial_hash import SpatialHashDemo
37+
view = SpatialHashDemo(4.0)
38+
self.view_list.append(view)
39+
3640
from draw_sprites.draw_sprites import DrawSprites
3741
view = DrawSprites(3.0)
3842
self.view_list.append(view)

minimap/minimap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ def load_texture_pair(filename):
4242
"""
4343
Load a texture pair, with the second being a mirror image.
4444
"""
45+
texture = arcade.load_texture(filename)
4546
return [
46-
arcade.load_texture(filename),
47-
arcade.load_texture(filename, flipped_horizontally=True),
47+
texture,
48+
texture.flip_vertically(),
4849
]
4950

5051
class PlayerCharacter(arcade.Sprite):

platformer_engine/platformer_engine.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def load_texture_pair(filename):
2929
"""
3030
Load a texture pair, with the second being a mirror image.
3131
"""
32+
texture = arcade.load_texture(filename)
3233
return [
33-
arcade.load_texture(filename),
34-
arcade.load_texture(filename, flipped_horizontally=True),
34+
texture,
35+
texture.flip_vertically(),
3536
]
3637

3738

spatial_hash/spatial_hash.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import random
2+
import arcade
3+
from base_view import BaseView
4+
5+
SCREEN_WIDTH = 800
6+
SCREEN_HEIGHT = 600
7+
COIN_COUNT = 500
8+
RECT_WIDTH = 100
9+
RECT_HEIGHT = 100
10+
11+
12+
class SpatialHashDemo(BaseView):
13+
""" Main application class. """
14+
15+
def __init__(self, time_on_screen):
16+
super().__init__(time_on_screen)
17+
self.rect = (0, RECT_WIDTH, RECT_HEIGHT, 0)
18+
self.coin_list = arcade.SpriteList(use_spatial_hash=True)
19+
for i in range(COIN_COUNT):
20+
coin = arcade.SpriteCircle(7, arcade.color_from_hex_string("#E96479"))
21+
coin.position = (
22+
random.randrange(SCREEN_WIDTH),
23+
random.randrange(SCREEN_HEIGHT),
24+
)
25+
self.coin_list.append(coin)
26+
arcade.set_background_color(arcade.color_from_hex_string("#F5E9CF"))
27+
self.change_x = 2
28+
self.change_y = 1
29+
30+
def on_draw(self):
31+
self.clear()
32+
self.coin_list.draw()
33+
34+
arcade.draw_lrtb_rectangle_outline(*self.rect, arcade.color_from_hex_string("#4D455D"), border_width=4)
35+
for y in range(0, SCREEN_HEIGHT, self.coin_list.spatial_hash.cell_size):
36+
for x in range(0, SCREEN_WIDTH, self.coin_list.spatial_hash.cell_size):
37+
arcade.draw_rectangle_outline(
38+
x + self.coin_list.spatial_hash.cell_size // 2,
39+
y + self.coin_list.spatial_hash.cell_size // 2,
40+
self.coin_list.spatial_hash.cell_size,
41+
self.coin_list.spatial_hash.cell_size,
42+
color=arcade.color_from_hex_string("#4D455D"),
43+
)
44+
45+
def on_update(self, delta_time):
46+
""" Movement and game logic """
47+
""" Handle Mouse Motion """
48+
l, r, t, b = self.rect
49+
l += self.change_x
50+
r += self.change_x
51+
t += self.change_y
52+
b += self.change_y
53+
self.rect = (l, r, t, b)
54+
55+
for sprite in self.coin_list:
56+
sprite.color = arcade.color_from_hex_string("#7DB9B6")
57+
58+
l, r, t, b = self.rect
59+
sprites = self.coin_list.spatial_hash.get_sprites_near_rect((l, r, b, t))
60+
for sprite in sprites:
61+
sprite.color = arcade.color_from_hex_string("#E96479")
62+

0 commit comments

Comments
 (0)
0