#--------------------- #Project: Zombie wave survival game(faith through fire) #Standard : 91883 (AS1.7) v.1 #School: Tauranga Boys Collage #Author: Bailyen R Tapsell #Date: July 5th 2024 #Python: 3.11.9 64-bit #Group: Black Blade Games #--------------------- import pygame from pygame.locals import * pygame.init() screen_width = 1000 screen_height = 1000 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption('platformer') #define game image tile_size = 50 #load images bg_img = pygame.image.load('floor.png') def draw_grid(): for line in range(0, 20): pygame.draw.line(screen, (255,255,255),(0, line * tile_size), (screen_width, line * tile_size)) pygame.draw.line(screen, (255,255,255),( line * tile_size,0), (line * tile_size, screen_height)) class Player(pygame.sprite.Sprite): def __init__(self, x, y): img = pygame.image.load('main man.png') self.image = pygame.transform.scale(img, (120, 120)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.vel_y = 0 def update(self): dx = 0 dy = 0 #get key presses key = pygame.key.get_pressed() if key[pygame.K_w]: dy -= 5 if key[pygame.K_d]: dx += 5 if key[pygame.K_a]: dx -= 5 if key[pygame.K_s]: dy += 5 #add gravity #check for collision #update player coordinates self.rect.x += dx self.rect.y += dy if self.rect.bottom > screen_height: self.rect.bottom = screen_height if self.rect.top > screen_height: self.rect.top = screen_height #priorities #1. gun working #2. health #3. zombies #4. waves #draw player onto screen screen.blit(self.image, self.rect) class World(): def __init__(self, data): self.tile_list = [] #load images dirt_img = pygame.image.load('building.png') grass_img = pygame.image.load('building.png') fireright_img = pygame.image.load('fire right.png') fireleft_img = pygame.image.load('fire left.png') firetop_img = pygame.image.load('fire top.png') firebottom_img = pygame.image.load('fire bottom.png') spikes_img = pygame.image.load('spikes.png') row_count = 0 for row in data: col_count = 0 for tile in row: if tile == 1: img = pygame.transform.scale(dirt_img, (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) if tile == 2: img = pygame.transform.scale(grass_img, (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) if tile == 3: img = pygame.transform.scale(fireright_img, (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) if tile == 4: img = pygame.transform.scale(fireleft_img, (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) if tile == 5: img = pygame.transform.scale(firetop_img, (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) if tile == 6: img = pygame.transform.scale(firebottom_img, (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) if tile == 7: img = pygame.transform.scale(spikes_img, (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: screen.blit(tile[0], tile[1]) world_data = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 1], [1, 4, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1], [1, 0, 0, 0, 1, 1, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1], [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ] player = Player(360, screen_height - 360) world = World(world_data) run = True while run == True: screen.blit(bg_img,(0,0)) world.draw() player.update() for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pygame.display.update() pygame.quit()