During this project, I was inspired to make this game, because I wanted to make an interactive project, that would attract the attention of the newer generations of "ipad kids." Reaching out to them and conveying them information is quite challenging, unless, you teach them through a game. In this game I struggled with different syntax, but I persevered in the end. Despite, how simple the game looks, I feel extremely accomplished of making this project.
Here is my code, because the upload doesn't work.
import pygame import random
pygame.init() numpoint = 0 screen = pygame.display.set_mode((1000, 600)) pygame.display.set_caption("Point Counter:" + str(numpoint))
Iiiimages
bg = (24, 230, 29, 100) image_sprite = pygame.image.load("waterbottle.png") image_person = pygame.image.load("bob.gif") image = pygame.transform.scale(image_person, (90, 90))
trashx = random.randint(150, 800) trashy = random.randint(100, 450)
position where it starts
y = 50 x = 100
image2 = pygame.transform.scale(image_sprite, (90, 90))
sped of te thingy
speed = 0.5
Game loop also start of hard part
running = True while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False
# if press movey thingey
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= speed
if keys[pygame.K_RIGHT]:
x += speed
if keys[pygame.K_UP]:
y -= speed
if keys[pygame.K_DOWN]:
y += speed
# boundaries
if x < 0:
x = 0
if x > 850:
x = 850
if y < 0:
y = 0
if y > 420:
y = 420
# color of them screen
screen.fill(bg)
# blit = spawn in
screen.blit(image, (50 + x, 50 + y))
screen.blit(image2, (trashx, trashy))
# updateing them display
# coord is within 50 of x and y then remake
if abs((50 + x) - trashx) < 50 and abs((50 + y) - trashy) < 50:
numpoint = numpoint + 1
pygame.display.set_caption("Point Counter:" + str(numpoint))
trashx = random.randint(150, 600) # Move water bottle to a new random position
trashy = random.randint(100, 500)
pygame.display.flip()
Quit Pygame
pygame.quit()
Built With
- python
- vscode
Log in or sign up for Devpost to join the conversation.