-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2edd0b9
commit a73b777
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pygame | ||
from math import radians, cos, sin | ||
|
||
|
||
class Bullet: | ||
def __init__(self, x, y, hdg, color): | ||
self.x = x | ||
self.y = y | ||
self.radius = 10 | ||
self.draw_x = self.x - self.radius | ||
self.draw_y = self.y - self.radius | ||
self.heading = hdg | ||
self.speed = 7 | ||
self.x_vel = 0 | ||
self.y_vel = 0 | ||
self.color = color | ||
|
||
def render(self, window): | ||
pygame.draw.ellipse(window, self.color, (self.draw_x, self.draw_y, self.radius * 2, self.radius * 2)) | ||
|
||
def update(self): | ||
self.x_vel = cos(radians(self.heading)) * self.speed | ||
self.y_vel = sin(radians(self.heading)) * self.speed | ||
|
||
self.x += self.x_vel | ||
self.y += self.y_vel | ||
|
||
self.draw_x = self.x - self.radius | ||
self.draw_y = self.y - self.radius |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters