-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
29 lines (24 loc) · 899 Bytes
/
bullet.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
from settings import *
import pygame
class Bullet:
def __init__(self, bullet_image, pos, screen):
self.pos = pygame.math.Vector2(pos)
self.speed = bullet_speed
self.screen = screen
self.direction = pygame.math.Vector2(1, 0)
self.img = bullet_image
self.img_height = self.img.get_height()
self.img_width = self.img.get_width()
def move(self, dt):
self.pos.x += dt * self.speed * self.direction.x
self.pos.y += dt * self.speed * self.direction.y
def render(self):
self.screen.blit(
self.img, (self.pos.x - self.img_height / 2, self.pos.y - self.img_height / 2))
def update(self, dt):
self.move(dt)
if self.direction.magnitude() > 0:
self.direction.normalize()
if self.pos.x > screen_width + self.img_width:
return False
return True