Weiter arbeiten, aufteilen in Klassen und organisierung des codes
This commit is contained in:
parent
437d8e3c25
commit
f1b81eb92c
BIN
code/__pycache__/sprites.cpython-310.pyc
Normal file
BIN
code/__pycache__/sprites.cpython-310.pyc
Normal file
Binary file not shown.
42
code/simulation.py
Normal file
42
code/simulation.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import pygame
|
||||
import sprites
|
||||
|
||||
|
||||
pygame.init()
|
||||
|
||||
SCREEN_WIDTH = 1280
|
||||
SCREEN_HEIGHT = 720
|
||||
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
player = pygame.sprite.GroupSingle()
|
||||
player.add(sprites.Player())
|
||||
|
||||
top_street_boarder = pygame.Rect(0, 50, SCREEN_WIDTH, 4)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run = True
|
||||
while run:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
|
||||
screen.fill("Grey")
|
||||
player.draw(screen)
|
||||
player.update()
|
||||
|
||||
|
||||
#pygame.draw.rect(screen, (0, 0, 0), line)
|
||||
|
||||
#if stickman_rect.colliderect(line):
|
||||
# stickman_rect.y = 55
|
||||
|
||||
pygame.display.update()
|
||||
clock.tick(60)
|
||||
|
||||
pygame.quit()
|
29
code/sprites.py
Normal file
29
code/sprites.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import pygame
|
||||
|
||||
class Player(pygame.sprite.Sprite):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
player_right = pygame.image.load("images/stickman_right.png")
|
||||
player_right = pygame.transform.scale(player_right, (30, 67))
|
||||
player_left = pygame.image.load("images/stickman_left.png")
|
||||
player_left = pygame.transform.scale(player_left, (30, 67))
|
||||
self.player_direction = [player_right, player_left]
|
||||
|
||||
self.image = self.player_direction[0]
|
||||
self.rect = self.image.get_rect(topleft = (0, 55))
|
||||
|
||||
def player_inputs(self):
|
||||
key = pygame.key.get_pressed()
|
||||
if key[pygame.K_a]:
|
||||
self.rect.x -= 3
|
||||
self.image = self.player_direction[1]
|
||||
if key[pygame.K_d]:
|
||||
self.rect.x += 3
|
||||
self.image = self.player_direction[0]
|
||||
if key[pygame.K_s]:
|
||||
self.rect.y += 3
|
||||
if key[pygame.K_w]:
|
||||
self.rect.y -= 3
|
||||
|
||||
def update(self):
|
||||
self.player_inputs()
|
Binary file not shown.
Before Width: | Height: | Size: 46 KiB |
BIN
images/stickman_left.png
Normal file
BIN
images/stickman_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
BIN
images/stickman_right.png
Normal file
BIN
images/stickman_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
|
@ -1,32 +0,0 @@
|
|||
import pygame
|
||||
|
||||
pygame.init()
|
||||
|
||||
SCREEN_WIDTH = 1280
|
||||
SCREEN_HEIGHT = 720
|
||||
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
screen.fill("Grey")
|
||||
stickman = pygame.image.load("images/stickman.png")
|
||||
stickman = pygame.transform.scale(stickman, (30.072, 67.2))
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run = True
|
||||
while run:
|
||||
|
||||
key = pygame.key.get_pressed()
|
||||
if key[pygame.K_a] == True:
|
||||
print("a")
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
screen.blit(stickman, (0,0))
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
pygame.quit()
|
Loading…
Reference in a new issue