-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteors.py
63 lines (48 loc) · 2.06 KB
/
meteors.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
import weakref
import numpy as np
import pygame as p
class Meteor:
meteors = weakref.WeakSet()
def __init__(self, typeX, vel, xsize):
self.type = typeX
self.mSize = 0
self.damage = 10
if self.type == 0:
self.mSize = 75
self.damage = 10
self.sprite = p.image.load("vfx/sprites/meteor1.png")
elif self.type == 1:
self.damage = 5
self.mSize = 50
self.sprite = p.image.load("vfx/sprites/meteor2.png")
self.vel = vel
self.size = (self.mSize, self.mSize)
self.pos = (np.random.randint(20 ,xsize-20), 0)
self.cann = p.transform.scale(self.sprite, self.size)
self.angle = 0
self.hitbox = (self.pos[0]-self.size[0]/2, self.pos[1]-self.size[1]/2, \
self.mSize-10, self.mSize-10)
self.sprite_rect = None
self.__class__.meteors.add(self)
def UpdatePos(self):
self.hitbox = (self.pos[0]-self.size[0]/2, self.pos[1]-self.size[1]/2, \
self.mSize-10, self.mSize-10)
self.pos = (self.pos[0], self.pos[1]+self.vel)
self.angle = (self.angle+1*np.sqrt(self.vel*3))%360
def Draw(self, win, hitbox=False):
self.sprite = p.transform.rotate(self.cann, self.angle)
self.sprite_rect = self.sprite.get_rect()
self.sprite_rect.center = self.pos
win.blit(self.sprite, self.sprite_rect)
if hitbox:
p.draw.rect(win, (255, 0, 0), (self.pos[0]+self.hitbox[2]/2, \
self.pos[1]-self.hitbox[3]/2, 3, self.hitbox[3]))
p.draw.rect(win, (255, 255, 0), (self.pos[0]-self.hitbox[2]/2, \
self.pos[1]-self.hitbox[3]/2, 3, self.hitbox[3]))
p.draw.rect(win, (255, 255, 255), (self.pos[0]-self.hitbox[2]/2, \
self.pos[1]+self.hitbox[3]/2, self.hitbox[2], 3))
p.draw.rect(win, (255, 0, 255), (self.pos[0]-self.hitbox[2]/2, \
self.pos[1]-self.hitbox[3]/2, self.hitbox[2], 3))
@classmethod
def getMeteors(cls):
return cls.meteors