Facebook
From Social Motmot, 4 Years ago, written in Python.
This paste is a reply to Agar.io from Edhyjox - go back
Embed
Viewing differences between Agar.io and Re: Agar.io
from random import random, randint# imports
from math import sqrt
import pygame, time, os
from pygame.locals import *
pygame.init()

screen_size_x = 1920
screen_size_y = 1080

screen_mid_x = 960
screen_mid_y = 540

os.environ['SDL_VIDEO_CENTERED'] = '1' # initialize SDL environment
sys_font = pygame.font.Font('ressources/fonts/sys_font.ttf', 25) # load game font
screen = pygame.display.set_mode((screen_size_x, screen_size_y), pygame.FULLSCREEN) # creating a fullscreen FHD window
clock = pygame.time.Clock() # set key repeatition and initialise a clock
    
def main():

    color, player_size, pos_player_x, pos_player_y, object_x, object_y, object_color, run = (255, 255, 255), 25, 0, 0, [], [], [], True # initialize variable
    pygame.key.set_repeat(50, 50)

    cam = 2
    map_size = 20000

    for i in range(10000): # for 10 000 values
        object_x.append((random() * map_size) - int(map_size/2)); object_y.append((random() * map_size) - int(map_size/2))# create coordinates
        object_color.append(tuple(int(random()*256) for _ in range(3))) # create color

    while run: # main loop
        screen.fill((0,0,0))
        screen.blit(sys_font.render('FPS : ' + str(int(clock.get_fps())), True, (255, 255, 255), None), (1720, 20)) # display FPS
        screen.blit(sys_font.render('Masse : ' + str(player_size), True, (255, 255, 255), None), (20, 60)) # display FPS
        screen.blit(sys_font.render('Cam : ' + str(cam), True, (255, 255, 255), None), (20, 20)) # display FPS
        
        mouse_x, mouse_y = pygame.mouse.get_pos()
        
        #cam = 2  + ( 1 / player_size) NE MARCHE PAS
        
        dist_center_mouse_x = mouse_x - screen_mid_x
        dist_center_mouse_y = mouse_y - screen_mid_y
        
        dist = sqrt(dist_center_mouse_x * dist_center_mouse_x + dist_center_mouse_y * dist_center_mouse_y )
        
        acceleration = 5 if dist > 400 else 5 * (dist/400) # get acceleration
        
        pos_player_x += (int(mouse_x - 959.5) / screen_mid_x) * acceleration
        pos_player_y += (int(mouse_y - 539.5) / screen_mid_y) * acceleration # mouse player
        
        for i in range(len(object_color)):

            _tx = (object_x[i] - pos_player_x) * cam # to calculate if 

            if (_tx < 0) or (_tx > screen_size_x): 
               continue
            _ty = (object_y[i] - pos_player_y) * cam
            if (_ty < 0) or (_ty > screen_size_y):
               continue
            _vx = _tx - screen_mid_x ; _vy = _ty - screen_mid_y

            print('_vx : ', _vx)


            if sqrt(_vx * _vx + _vy * _vy ) <= player_size :
                object_x[i] = (random() * map_size) - int(map_size/2)
                object_y[i] = (random() * map_size) - int(map_size/2)
                player_size += 1
            
            pygame.draw.circle(screen, object_color[i], (int(_tx), int(_ty)), int(5 * cam))

        pygame.draw.circle(screen, color, (screen_mid_x,screen_mid_y), int(player_size * cam)) # player

        for e in pygame.event.get(): # check event
            if e.type == KEYDOWN :
                if e.key == K_a :
                    run = False # stop main loop if 'a' key pressed
                elif e.key == K_e :
                    player_size += 1

        pygame.display.update()
        clock.tick(60) # build frame with 60 frame per second limitation

if __name__ == '__main__':
    main()