Python Forum
Why is it not printing out
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is it not printing out
#1
Im trying to make an own "collision" which you can first see in "world_Data" in the class world.coll. But the world data is not updating it and all the "1" is dirt and 0 nothing




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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class World():
    def __init__(self,world_data):
 
        self.tile_list = []
 
        dirt = pygame.image.load(os.path.join('pics', 'hej.png'))
        row_count = 0
        for row in world_data:
            col_count = 0
            for tile in row:
                if tile == 1:
                    img = pygame.transform.scale(dirt, (tile_size, tile_size))
                    img_rect = img.get_rect()
                    img_rect.x = col_count * tile_size
                    img_rect.y = row_count * tile_size
                    tile = (img, img_rect)
                    self.tile_list.append(tile)
 
                col_count += 1
            row_count += 1
 
 
    def draw(self):
        for tile in self.tile_list:
            WIN.blit(tile[0], tile[1])
 
    def coll(self,erik_move):
        if erik_move[1] > 500:
            world_data[0] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 
 
world_data = [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    ]
 
 
 
world = World(world_data)
 
 
 
 
def draw_grid():
    for line in range(0, 20):
        pygame.draw.line(WIN, (255, 255, 255), (0, line * tile_size), (WIDTH, line * tile_size))
        pygame.draw.line(WIN, (255, 255, 255), (line * tile_size, 0), (line * tile_size, HEIGHT))
 
 
 
font = pygame.font.SysFont("Times New Roman, Arial", 30)
text = font.render("BONK A BEAVER", True, BLACK)
 
 
ERIK = pygame.image.load(os.path.join('pics', 'erik2.png'))
ERIK = pygame.transform.scale(ERIK, (200, 200))
 
Backg = pygame.image.load(os.path.join('pics', 'sky.png'))
 
print(Backg)
FPS = 60
 
 
 
#Om du vill röra din surface, (bilden/surface, hastighet per frames  )
 
 
def key_pressed(keys_pressed, erik_move):
    if keys_pressed[pygame.K_a]:
        erik_move.x -= 5
    if keys_pressed[pygame.K_d]:
        erik_move.x += 5
    if keys_pressed[pygame.K_w]:
        erik_move.y -= 5
    if keys_pressed[pygame.K_s]:
        erik_move.y += 5
 
 
 
 
 
def erik_pos(erik_move, number):
    erik_move[0] = erik_move[0] + number
 
 
 
 
 
 
#Här bildas och uppdateras surface
def draw_window(erik_move):
    WIN.fill(BLACK)
    WIN.blit(ERIK, (erik_move.x, erik_move.y))
 
    world.draw()
    draw_grid()
 
    world.coll(erik_move)
    print(world_data[0])
    pygame.display.update()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020