Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- import random
- # import os
- # import time
- pygame.init()
- pygame.display.set_caption("Agar.io")
- name = input("Player name: ")
- line_draw = input("do you want to draw a line? ")
- width = 600
- height = 600
- vel = 0.5
- rows = 20
- w = 500
- screen = pygame.display.set_mode((height, width))
- red = (255, 0, 0)
- dim_red = (55, 0, 0)
- green = (0, 255, 0)
- yellow = (255, 255, 0)
- blue = (0, 0, 255)
- dim_blue = (0, 0, 55)
- cyan = (0, 255, 255)
- white = (255, 255, 255)
- magenta = (255, 0, 255)
- black = (0, 0, 0)
- background_color = green
- player_position = [265, 265]
- player_color = [0, 0, 255]
- player_size = 20
- food_position = [random.randint(1, height), random.randint(1, width)]
- food_sizes_list = [7, 7, 7, 7, 7, 7, 8, 8, 8, 9, 10, 10, 11, 12, 13, 14]
- food_size = random.choice(food_sizes_list)
- food_colors = [red, blue, white, cyan, dim_blue, dim_red, yellow, magenta]
- food_color = random.choice(food_colors)
- food_list = [food_position]
- myFont = pygame.font.SysFont("arial", 30)
- my_name = pygame.font.SysFont("arial", 30)
- def detect_collision(player_pos, food_pos):
- p_x = player_pos[0]
- p_y = player_pos[1]
- e_x = food_pos[0]
- e_y = food_pos[1]
- if ((e_x >= p_x) and e_x < (p_x + player_size)) or ((p_x >= e_x) and p_x < (e_x + food_size)):
- if ((e_y >= p_y)and e_y < (p_y + player_size)) or ((p_y >= e_y) and p_y < (e_y + food_size)):
- return True
- return False
- game_over = False
- while not game_over:
- class Player:
- def draw_player(self):
- pygame.draw.rect(screen, player_color, (player_position[0], player_position[1], player_size, player_size))
- if detect_collision(player_position, food_position):
- player_size += food_size / 2
- food_position = [random.randint(1, height), random.randint(1, width)]
- food_size = random.choice(food_sizes_list)
- food_color = random.choice(food_colors)
- class Food:
- def draw_food(self):
- pygame.draw.rect(screen, food_color, (food_position[0], food_position[1], food_size, food_size))
- x = food_position[0]
- y = food_position[1]
- mouse_pos = pygame.mouse.get_pos()
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT]: # and food_position[0] > 0:
- x += vel
- elif keys[pygame.K_RIGHT]: # and food_position[0] < width - food_size:
- x -= vel
- elif keys[pygame.K_UP]: # and food_position[1] > 0:
- y += vel
- elif keys[pygame.K_DOWN]: # and food_position[1] < height - food_size:
- y -= vel
- elif keys[pygame.K_x]:
- sys.exit()
- food_position = [x, y]
- class Line:
- def draw_line(self):
- pygame.draw.line(screen, white, player_position, mouse_pos)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- screen.fill(background_color)
- pygame.display.update()
- text = "Player size: " + str(player_size)
- label = myFont.render(text, 1, black)
- screen.blit(label, (width - 600, height - 40))
- name_label = name
- label_name = my_name.render(name_label, 1, black)
- screen.blit(label_name, (player_position[0], player_position[1] - 50))
- player = Player()
- player.draw_player()
- food = Food()
- food.draw_food()
- if line_draw.lower() == "yes":
- line = Line()
- line.draw_line()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement