Unity Learn home
18
31
Searching for Diamonds
9.7 Kviews
The robot is walking through the desert and collecting the gems.
Media
1
1
L
LeviAryani
3 days ago
Nice
f
flawlex07
3 days ago
nice
t
talhaff442
7 days ago
import pygame import sys # Initialize pygame.init() WIDTH, HEIGHT = 800, 400 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Street Fight") clock = pygame.time.Clock() # Colors WHITE = (255, 255, 255) RED = (200, 0, 0) BLUE = (0, 0, 200) BLACK = (0, 0, 0) # Players player1 = pygame.Rect(100, 300, 50, 50) player2 = pygame.Rect(650, 300, 50, 50) player1_hp, player2_hp = 100, 100 font = pygame.font.SysFont(None, 36) def draw(): screen.fill(WHITE) pygame.draw.rect(screen, RED, player1) pygame.draw.rect(screen, BLUE, player2) # Health bars pygame.draw.rect(screen, RED, (50, 30, player1_hp * 2, 20)) pygame.draw.rect(screen, BLUE, (WIDTH - 250, 30, player2_hp * 2, 20)) # Win condition if player1_hp <= 0: text = font.render("Player 2 Wins!", True, BLACK) screen.blit(text, (WIDTH//2 - 100, HEIGHT//2)) elif player2_hp <= 0: text = font.render("Player 1 Wins!", True, BLACK) screen.blit(text, (WIDTH//2 - 100, HEIGHT//2)) pygame.display.flip() def fight(p1, p2): global player1_hp, player2_hp if p1.colliderect(p2): player2_hp -= 1 def fight_back(p2, p1): global player1_hp if p2.colliderect(p1): player1_hp -= 1 # Game loop while True: keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() # Player 1 movement if keys[pygame.K_a]: player1.x -= 5 if keys[pygame.K_d]: player1.x += 5 if keys[pygame.K_w]: player1.y -= 5 if keys[pygame.K_s]: player1.y += 5 if keys[pygame.K_SPACE]: fight(player1, player2) # Player 2 movement if keys[pygame.K_LEFT]: player2.x -= 5 if keys[pygame.K_RIGHT]: player2.x += 5 if keys[pygame.K_UP]: player2.y -= 5 if keys[pygame.K_DOWN]: player2.y += 5 if keys[pygame.K_RETURN]: fight_back(player2, player1) draw() clock.tick(60)
E
EyezakGD
8 days ago
This is fire ngl
C
Coty
17 days ago
Love the space direction here. Very Mars vibe with vegetation. Cool looking robot as well.