I made the basic movement system and the player and honey assets and added a score system
This commit is contained in:
parent
3fb852fa94
commit
5bcc810c07
3 changed files with 60 additions and 2 deletions
BIN
honey.png
Normal file
BIN
honey.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 207 B |
62
main.py
62
main.py
|
|
@ -1,4 +1,62 @@
|
|||
#test2wrwrqa
|
||||
import random
|
||||
import pygame
|
||||
|
||||
pygame.init()
|
||||
|
||||
WIDTH, HEIGHT = 640, 480
|
||||
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
pygame.display.set_caption("Sugarmania")
|
||||
clock = pygame.time.Clock()
|
||||
font = pygame.font.SysFont(None, 36)
|
||||
|
||||
player_img = pygame.image.load("player.png").convert_alpha()
|
||||
player_img = pygame.transform.scale(player_img, (40, 60))
|
||||
player = pygame.Rect(300, 220, 40, 60)
|
||||
speed = 5
|
||||
|
||||
sugar_img = pygame.image.load("honey.png").convert_alpha()
|
||||
sugar_img = pygame.transform.scale(sugar_img, (50, 50))
|
||||
score = 0
|
||||
def new_sugar():
|
||||
return pygame.Rect(random.randint(0, WIDTH - 20),
|
||||
random.randint(0, HEIGHT - 20), 50, 50) #20,s
|
||||
sugar = new_sugar()
|
||||
|
||||
|
||||
fasdfas
|
||||
#game loop
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
||||
#movement
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
|
||||
player.x -= speed
|
||||
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
||||
player.x += speed
|
||||
if keys[pygame.K_UP] or keys[pygame.K_w]:
|
||||
player.y -= speed
|
||||
if keys[pygame.K_DOWN] or keys[pygame.K_s]:
|
||||
player.y += speed
|
||||
|
||||
#keep player in
|
||||
player.clamp_ip(screen.get_rect())
|
||||
|
||||
# score
|
||||
if player.colliderect(sugar):
|
||||
score += 1
|
||||
sugar = new_sugar()
|
||||
|
||||
screen.fill((255, 228, 240)) #screen
|
||||
screen.blit(sugar_img, sugar) #sugar
|
||||
screen.blit(player_img, player) #player
|
||||
text = font.render(f"score: {score}", True, (90, 30, 60))
|
||||
screen.blit(text, (10, 10))
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(60)
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
|
|
|||
BIN
player.png
Normal file
BIN
player.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 B |
Loading…
Add table
Add a link
Reference in a new issue