Facebook
From Edhyjox, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 231
  1. from random import random, randint# imports
  2. from math import sqrt
  3. import pygame, time, os
  4. from pygame.locals import *
  5. pygame.init()
  6.  
  7.  
  8.  
  9. def main():
  10.     screen_size_x = 1920
  11.     screen_size_y = 1080
  12.  
  13.     screen_mid_x = 960
  14.     screen_mid_y = 540
  15.  
  16.     os.environ['SDL_VIDEO_CENTERED'] = '1' # initialize SDL environment
  17.     sys_font = pygame.font.Font('ressources/fonts/sys_font.ttf', 25) # load game font
  18.     screen = pygame.display.set_mode((screen_size_x, screen_size_y), pygame.FULLSCREEN) # creating a fullscreen FHD window
  19.     clock = pygame.time.Clock() # set key repeatition and initialise a clock
  20.     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
  21.     pygame.key.set_repeat(50, 50)
  22.  
  23.     cam = 2
  24.     map_size = 20000
  25.  
  26.     for i in range(10000): # for 10 000 values
  27.         object_x.append((random() * map_size) - int(map_size/2)); object_y.append((random() * map_size) - int(map_size/2))# create coordinates
  28.         object_color.append(tuple(int(random()*256) for _ in range(3))) # create color
  29.  
  30.     while run: # main loop
  31.         screen.fill((0,0,0))
  32.         screen.blit(sys_font.render('FPS : ' + str(int(clock.get_fps())), True, (255, 255, 255), None), (1720, 20)) # display FPS
  33.         screen.blit(sys_font.render('Masse : ' + str(player_size), True, (255, 255, 255), None), (20, 60)) # display FPS
  34.         screen.blit(sys_font.render('Cam : ' + str(cam), True, (255, 255, 255), None), (20, 20)) # display FPS
  35.        
  36.         mouse_x, mouse_y = pygame.mouse.get_pos()
  37.        
  38.         #cam = 2  + ( 1 / player_size) NE MARCHE PAS
  39.        
  40.         dist_center_mouse_x = mouse_x - screen_mid_x
  41.         dist_center_mouse_y = mouse_y - screen_mid_y
  42.        
  43.         dist = sqrt(dist_center_mouse_x * dist_center_mouse_x + dist_center_mouse_y * dist_center_mouse_y )
  44.        
  45.         acceleration = 5 if dist > 400 else 5 * (dist/400) # get acceleration
  46.        
  47.         pos_player_x += (int(mouse_x - 959.5) / screen_mid_x) * acceleration
  48.         pos_player_y += (int(mouse_y - 539.5) / screen_mid_y) * acceleration # mouse player
  49.        
  50.         for i in range(len(object_color)):
  51.  
  52.             _tx = (object_x[i] - pos_player_x) * cam # to calculate if
  53.  
  54.             if (_tx < 0) or (_tx > screen_size_x):
  55.                continue
  56.             _ty = (object_y[i] - pos_player_y) * cam
  57.             if (_ty < 0) or (_ty > screen_size_y):
  58.                continue
  59.             _vx = _tx - screen_mid_x ; _vy = _ty - screen_mid_y
  60.  
  61.             print('_vx : ', _vx)
  62.  
  63.  
  64.             if sqrt(_vx * _vx + _vy * _vy ) <= player_size :
  65.                 object_x[i] = (random() * map_size) - int(map_size/2)
  66.                 object_y[i] = (random() * map_size) - int(map_size/2)
  67.                 player_size += 1
  68.            
  69.             pygame.draw.circle(screen, object_color[i], (int(_tx), int(_ty)), int(5 * cam))
  70.  
  71.         pygame.draw.circle(screen, color, (screen_mid_x,screen_mid_y), int(player_size * cam)) # player
  72.  
  73.         for e in pygame.event.get(): # check event
  74.             if e.type == KEYDOWN :
  75.                 if e.key == K_a :
  76.                     run = False # stop main loop if 'a' key pressed
  77.                 elif e.key == K_e :
  78.                     player_size += 1
  79.  
  80.         pygame.display.update()
  81.         clock.tick(60) # build frame with 60 frame per second limitation
  82.  
  83. if __name__ == '__main':
  84.     main()