-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwall.py
72 lines (69 loc) · 4.07 KB
/
wall.py
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
"""Module chứa đối tượng Wall, là tập hợp các ô vuông mà khi Snake chạm vào, game sẽ kết thúc"""
import pygame, sys, random
from pygame.locals import *
import setting as st
class Wall:
def __init__(self, map):
self.position = []
if map == 1:
for i in range(0, st.SCREEN_HEIGHT, st.UNIT):
for j in range(0, st.SCREEN_WIDTH, st.UNIT):
if i == 0 or i == st.SCREEN_HEIGHT-st.UNIT:
self.position.append([j, i])
else:
if j == 0 or j == st.SCREEN_WIDTH-st.UNIT:
self.position.append([j, i])
elif map == 2:
for i in range(0, st.SCREEN_HEIGHT, st.UNIT):
if i < st.SCREEN_HEIGHT*7//20 or i >= st.SCREEN_HEIGHT*13//20:
for j in range(0,st.SCREEN_WIDTH, st.UNIT):
if i == st.SCREEN_HEIGHT*7//20-st.UNIT or i == st.SCREEN_HEIGHT*13//20:
if j >= st.SCREEN_WIDTH//3 and j < st.SCREEN_WIDTH*2//3:
self.position.append([j, i])
elif i == 0 or i == st.SCREEN_HEIGHT-st.UNIT:
if j < st.SCREEN_WIDTH//3 or j >= st.SCREEN_WIDTH*2//3:
self.position.append([j, i])
else:
if j == 0 or j == st.SCREEN_WIDTH-st.UNIT:
self.position.append([j, i])
elif map == 3:
for i in range(0, st.SCREEN_HEIGHT, st.UNIT):
for j in range(0, st.SCREEN_WIDTH, st.UNIT):
if i <= st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//5 - st.UNIT and j == st.SCREEN_WIDTH//3 + st.UNIT:
self.position.append([j, i])
if i >= st.SCREEN_HEIGHT//5 and j == st.SCREEN_WIDTH - st.SCREEN_WIDTH//3 - 2 * st.UNIT:
self.position.append([j, i])
if i == st.SCREEN_HEIGHT//5 and j <= st.SCREEN_WIDTH//3 - 2 * st.UNIT:
self.position.append([j, i])
if i == st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//5 - st.UNIT and j >= st.SCREEN_WIDTH - st.SCREEN_WIDTH//3 + st.UNIT:
self.position.append([j, i])
elif map == 4:
for i in range(0, st.SCREEN_HEIGHT, st.UNIT):
for j in range(0, st.SCREEN_WIDTH, st.UNIT):
if i == 0 or i == st.SCREEN_HEIGHT-st.UNIT:
self.position.append([j, i])
if i <= st.SCREEN_HEIGHT//5 or i >= st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//5 - st.UNIT:
if j == 0 or j == st.SCREEN_WIDTH-st.UNIT:
self.position.append([j, i])
if i == st.SCREEN_HEIGHT//5 + st.UNIT or i == st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//5 - 2 * st.UNIT:
if j > st.SCREEN_HEIGHT//5 and j < st.SCREEN_WIDTH - st.SCREEN_HEIGHT//5 - st.UNIT:
self.position.append([j, i])
elif map == 5:
for i in range(0, st.SCREEN_HEIGHT, st.UNIT):
for j in range(0, st.SCREEN_WIDTH, st.UNIT):
if i == st.SCREEN_HEIGHT//2 - st.UNIT:
if j <= st.SCREEN_WIDTH//2 - 4 * st.UNIT or j >= st.SCREEN_WIDTH//2:
self.position.append([j, i])
if i == st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//4 - st.UNIT:
self.position.append([j, i])
if i <= st.SCREEN_HEIGHT//2 - 5 * st.UNIT:
if j == st.SCREEN_WIDTH//2:
self.position.append([j, i])
if i >= st.SCREEN_HEIGHT - st.SCREEN_HEIGHT//4 - st.UNIT:
if j == st.SCREEN_WIDTH//2:
self.position.append([j, i])
def draw(self, surface):
for point in self.position:
img = pygame.image.load("assets/images/wall.png")
img = pygame.transform.scale(img, (st.UNIT, st.UNIT))
surface.blit(img, point)