-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_planets.py
70 lines (53 loc) · 2.09 KB
/
game_planets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# chargement des modules
from random import randrange
import pygame
import pygame.gfxdraw
from pygame.math import Vector2
from game_sprites import *
from game_surfaces import *
from game_camera import *
# initialisation de pygame
if not pygame.get_init():
pygame.init()
# liste des planètes
planets = list()
# classe Planêtes
class Planet:
def __init__(self, **kwargs):
# récupère les arguments
self.position = kwargs.get("position", Vector2(0, 0))
self.rotation = kwargs.get("rotation", 0)
self.rotation_speed = kwargs.get("rotation_speed", 0)
self.size = kwargs.get("size", 32)
self.size = max(32, self.size)
self.gravity_range = kwargs.get("gravity_range", max(self.size*3, 64))
self.gravity_force = kwargs.get("gravity_force", 0.01)
self.gravity_alpha = True
self.gravity_color = pygame.Color(
randrange(0, 128),
randrange(0, 128),
randrange(0, 128),
128)
def update(self):
self.rotation += self.rotation_speed
if self.rotation <= -360 or self.rotation >= 360:
self.rotation %= 360
self.draw()
def draw(self):
sprite = pygame.transform.scale(sprite_planet, [self.size * 2, self.size * 2])
sprite = pygame.transform.rotate(sprite, self.rotation)
x = self.position.x - sprite.get_width() // 2 - camera.position.x
y = self.position.y - sprite.get_height() // 2 - camera.position.y
display.blit(sprite, [x, y])
def drawGravityRanges(self):
""" dessine le cercle de la portée de gravitation """
self.gravity_color.a += 1 if self.gravity_alpha else -1
if self.gravity_color.a >= 255:
self.gravity_alpha = False
self.gravity_color.a = 254
elif self.gravity_color.a <= 128:
self.gravity_alpha = True
self.gravity_color.a = 129
x = int(self.position.x - camera.position.x)
y = int(self.position.y - camera.position.y)
pygame.gfxdraw.circle(display, x, y, self.gravity_range, self.gravity_color)