• API
• FAQ
• Tools
• Archive
daily pastebin goal
81%
SHARE
TWEET

# Untitled

a guest Aug 13th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import pygame
2. import math
3. pygame.init()
4.
6.     return degrees * (math.pi / 180.0)
7.
8. class Projectile(pygame.sprite.Sprite):
9.     def __init__(self, boss, ddx, ddy):
10.         self.shotsound = pygame.mixer.Sound('src/sound/weapons/rifle.ogg')
11.         pygame.sprite.Sprite.__init__(self)
12.
14.         """Owner of the shot"""
15.         self.boss = boss
16.         clock = pygame.time.Clock()
17.         self.bulletspeed = 20.0 # pixel per second ?
18.         self.ddx = ddx
19.         self.ddy = ddy
20.         self.pos = [0,0]
21.
23.         self.lifetime = 5 # 5 seconds
24.         self.angle = self.boss.angle_to_pointer
25.
26.         self.pos[0] = self.boss.rect.centerx
27.         self.pos[1] = self.boss.rect.centery
28.         self.calculate_origin()
30.
31.         self.startlength = 0
32.         self.maxlength = 5
33.         self.dx = self.ddx * self.bulletspeed
34.         self.dy = self.ddy * self.bulletspeed
35.
36.     def calculate_origin(self):
37.         # - spawn bullet at end of turret barrel instead tank center -
38.         # cannon is around Tank.side long, calculatet from Tank center
39.         # later subtracted 20 pixel from this distance
40.         # so that bullet spawns closer to tank muzzle
41.         self.pos[0] +=  math.cos(degrees_to_radians(self.boss.angle_to_pointer)) * (self.boss.rect.width-20)
42.         self.pos[1] +=  math.sin(degrees_to_radians(-self.boss.angle_to_pointer)) * (self.boss.rect.width-20)
43.
44.
45.     def update(self, block_group):
46.         self.block_group = block_group
47.         self.pos[0] += self.dx * 0.2 #0.016
48.         self.pos[1] += self.dy * 0.2 #0.016
49.
50.         self.rect.centerx = round(self.pos[0],0)
51.         self.rect.centery = round(self.pos[1],0)
53.         if self.rect.x >= 720:
54.             self.kill()
55.         elif self.rect.x <= 0:
56.             self.kill()
57.         elif self.rect.y >= 560:
58.             self.kill()
59.         elif self.rect.y <= 0:
60.             self.kill()
61.
62.         if pygame.sprite.spritecollide(self, self.block_group, False):
63.            self.kill()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top