def start(screen, level): # Init level_objects = [] lines = [] with open(f"levels/{level}.txt") as file: for line in file: lines.append(line) for i in range(len(lines) - 1, -1, -1): for j in range(len(lines[0]) - 1): if lines[i][j] == "0": continue elif lines[i][j] == "1": level_objects.append( TerrainObject(screen, "ground.png", Type.GENTIL)) elif lines[i][j] == "2": level_objects.append( TerrainObject(screen, "saw.png", Type.MECHANT)) level_objects[-1].sprite.left = j * 64 level_objects[-1].sprite.bottom = screen.size[1] - (len(lines) - 1 - i) * 64 player = sprite.Player(screen, level_objects) player.bottom = screen.size[1] - 80 player.left = 80 # Game loop event = SDL_Event() while True: if player.is_dead: player = sprite.Player(screen, level_objects) player.bottom = screen.size[1] - 80 player.left = 80 while SDL_PollEvent(ctypes.byref(event)): if event.type == SDL_QUIT: TTF_Quit() SDL_Quit() quit() if event.type == SDL_KEYDOWN: if event.key.keysym.scancode == SDL_SCANCODE_ESCAPE: # Quitter return False elif event.key.keysym.scancode == SDL_SCANCODE_R: return True for sp in level_objects: sp.sprite.tick() player.tick() screen.clear() for sp in level_objects: screen.copy(sp.sprite) screen.copy(player) screen.render()
def __init__(self): self.frame_delay = 0 ok,fail=pygame.init() self.sock,self.remote = args.init() self.screen = pygame.display.set_mode() self.game_surface = pygame.Surface((glb.game_screen_width,glb.game_screen_height)) self.border = pygame.Surface((glb.border_width,glb.border_height)) self.clock = pygame.time.Clock() self.blocks = [] self.player = sprite.Player() self.opponent = sprite.Opponent() self.ball = sprite.Ball() self.oball = sprite.Ball() self.border.fill((255,255,255)) self.frame_counter = 10 self.rthread = threading.Thread(target = self.receive) self.rthread.start() if fail: print(f"Initialization passed = {ok} failed = {fail} ") for x in range (int(glb.columns/2)): for y in range (glb.rows): self.blocks.append(sprite.Block(True, x*glb.block_width, y*glb.block_height, glb.block_width, glb.block_height)) for x in range (int(glb.columns/2), glb.columns): for y in range (glb.rows): self.blocks.append(sprite.Block(False, x*glb.block_width, y*glb.block_height, glb.block_width, glb.block_height))
def EntityLoop(): global Players, name deleteItems = [] for item in Items: image = sprite.Player(screen, (0, 0, 0), 50, item.x - scrollX + 25, item.y - scrollY + 25, True, 0, item.degrees) image.image = itemImages[itemIDs[item.ID]] image.update() item.degrees += 1 if round(player.x) > image.x - 50 and round(player.x) < image.x + 50: if round(player.y) > image.y - 50 and round( player.y) < image.y + 50: item.pickUp() deleteItems.append(item) for item in deleteItems: DeleteItemAsync(item) Items.remove(item) for Player in Players: if Player.name != name: image = sprite.Sprite(screen, (0, 0, 0), 50, Player.x - scrollX, Player.y - scrollY) image.updateImage() sprite.text(str(Player.name), Player.x - scrollX - ((len(Player.name) * 20) / 2), Player.y - scrollY - 40)
def __init__(self): pygame.init() self.surf = pygame.display.set_mode(cfg.dim) self.clock = pygame.time.Clock() self.fps = 60 self.running = True self.player = sprite.Player() self.bees = pygame.sprite.Group()
def main_loop(): pygame.init() display = pygame.display.set_mode((600, 600)) sprite.init(display) display_area = display.get_rect() clock = pygame.time.Clock() player = pygame.sprite.GroupSingle() player_shots = pygame.sprite.Group() baddies = pygame.sprite.Group() sprite.Player(display_area, pygame.K_w, player) sprite.Enemy((20, 20), player.sprite, display_area, baddies) display.blit(sprite.player_image, (0, 0)) def stop(): global running running = False while running: time = clock.tick() / 1000.0 # Handle Events for event in pygame.event.get(): if event.type == pygame.QUIT: stop() if event.type == pygame.MOUSEBUTTONDOWN: player.sprite.fire(player_shots, baddies) player.update(time) player_shots.update(time) baddies.update(time) # Draw display.fill((0, 0, 0)) player.draw(display) player_shots.draw(display) baddies.draw(display) pygame.display.update()
def drawHotbar(): for x in range(9): pointer = sprite.Player(screen, (255, 255, 255), 50, 50, 25, False, 0) if selectedSlot == x + 1: pointer.image = yellowPointer else: pointer.image = hotbarSlot pointer.x = (x * 50) + 25 pointer.update() if inventory[x + 1] != 0: pointer.image = itemImages[itemIDs[inventory[x + 1].ID]] pointer.update() if inventory[x + 1].tool == False: sprite.text(str(inventory[x + 1].count), (x * 50) + 25, 25) if inventory[selectedSlot] != 0: pointer.image = itemImages[itemIDs[inventory[selectedSlot].ID]] pointer.x = player.x pointer.y = player.y Mx, My = pygame.mouse.get_pos() direction = sprite.getDirection((pointer.x, pointer.y), (Mx, My)) pointer.direction = direction pointer.step(50) pointer.update() changeHotbar()
import time import random as r import asyncio from pygame.locals import (K_UP, K_DOWN, K_LEFT, K_RIGHT, K_ESCAPE, K_w, K_s, K_a, K_d, KEYDOWN, QUIT, K_f) import farm_client import google.protobuf.json_format as json_format import os sprite.init(inputFont="Minecraft") screen = sprite.setScreen(1440, 760) player = sprite.Player(screen, (255, 255, 255), 50, 0, 0, False, 5) player.realX = player.x player.realY = player.y scrollX = 0 scrollY = 0 Map = grid.Grid(100, 100) lock = 0 Itemlock = 0 Playerlock = 0 PlayerSendlock = 0 name = os.environ.get("USER") hotbarSlot = sprite.newImage('pointer.png') yellowPointer = sprite.newImage('yellowPointer.png') selectedSlot = 1 Items = [] Players = []
import pygame as pg import const import sprite import lane page = 1 # 1=menu, 2=game, 3= background = pg.display.set_mode((const.WIDTH, const.HEIGHT)) elementsgame = pg.sprite.Group() elementsmenu = pg.sprite.Group() Lhama1 = sprite.Player( pg.image.load('../../media/sprite/Skin0Test.png').convert_alpha()) Fundo1Game = sprite.Fundo( pg.image.load('../../media/img/FundoTest.png').convert_alpha()) Fundo1Menu = sprite.Fundo( pg.image.load('../../media/img/MenuTest.png').convert_alpha()) Enemy1 = sprite.Enemy(2) Enemy2 = sprite.Enemy(1) Enemy3 = sprite.Enemy(3) Guacamole1 = sprite.Point(3) Lane1 = lane.Lane(1, const.WIDTH / 2 - 150) Lane2 = lane.Lane(2, const.WIDTH / 2) Lane3 = lane.Lane(3, const.WIDTH / 2 + 150) lanes = [Lane1, Lane2, Lane3]