Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar

Patrick Kalkman PatrickKalkman

View GitHub Profile
@PatrickKalkman
PatrickKalkman / Dockerfile
Created June 20, 2021 07:55
Microsoft .NET Non Root Docker image
# We use the alpine as base image
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine-amd64
# Create a group and user
RUN addgroup --gid 1000 -S app && adduser --uid 1000 -S app -G app
# Create the work dir and set permissions as WORKDIR set the permissions as root
RUN mkdir /home/app/net && chown -R app:app /home/app/net
WORKDIR /home/app/net
@PatrickKalkman
PatrickKalkman / calculate_rotation.py
Created June 13, 2021 11:57
Calculcate the rotation of the enemy space ship
def calculate_rotation(self, previous_point, current_point):
dx = current_point.xpos - previous_point.xpos
dy = current_point.ypos - previous_point.ypos
return math.degrees(math.atan2(dx, dy)) + 180
@PatrickKalkman
PatrickKalkman / shoot.py
Created June 13, 2021 10:02
The enemy space ship shoots a rocket towards the player
def enemy_shoots(self):
nr_of_enemies = len(self.all_enemies)
if nr_of_enemies > 0:
enemy_index = random.randint(0, nr_of_enemies - 1)
start_rocket = None
for index, enemy in enumerate(self.all_enemies):
if index == enemy_index:
start_rocket = enemy.rect.center
if start_rocket[1] < 400:
@PatrickKalkman
PatrickKalkman / StarField.py
Created June 13, 2021 06:57
The background star field
class StarField():
def __init__(self):
self.star_field_slow = self.create_stars(50)
self.star_field_medium = self.create_stars(35)
self.star_field_fast = self.create_stars(30)
def create_stars(self, number_of_stars):
stars = []
for _ in range(number_of_stars):
star_loc_x = random.randrange(0, constants.SCREEN_WIDTH)
@PatrickKalkman
PatrickKalkman / controlhandlermover.py
Created June 13, 2021 06:10
class to move control handles and points
class ControlHandlerMover():
def __init__(self,
control_point_quartet_collection: ControlPointQuartetCollection,
path_point_selector: PathPointSelector):
self.control_point_quartet_collection = control_point_quartet_collection
self.path_point_selector = path_point_selector
def move_control_handler(self, control_point_handler: ControlPointHandler, x: int, y: int):
dx = self.control_point_quartet_collection.get_control_point(control_point_handler).x - x
dy = self.control_point_quartet_collection.get_control_point(control_point_handler).y - y
@PatrickKalkman
PatrickKalkman / pathpointcalculator.py
Created June 12, 2021 20:20
Calculating the points of the bezier curve
class PathPointCalculator():
@staticmethod
def calculate_path_point(control_point_quartet: ControlPointQuartet,
time_to_calculate: float):
time: float = time_to_calculate - int(time_to_calculate)
cx: float = 3.0 * (control_point_quartet.get_point(1).x -
control_point_quartet.get_point(0).x)
cy: float = 3.0 * (control_point_quartet.get_point(1).y -
@PatrickKalkman
PatrickKalkman / controlpointcollectionfactory.py
Created June 12, 2021 19:45
creating the control points of the bezier curves
class ControlPointCollectionFactory():
@staticmethod
def create_collection1():
control_point_quartet_collection = ControlPointQuartetCollection()
control_point_quartet_collection.add(ControlPointQuartet(
513, -15,
700, 151,
888, 650,
@PatrickKalkman
PatrickKalkman / collision.py
Created June 12, 2021 18:09
using group collide to detect collisions
result = pygame.sprite.groupcollide(self.all_rockets, self.all_enemies, True, True)
if result:
for key in result:
self.score += 120
if self.score > self.high_score:
self.high_score = self.score
self.all_sprites.add(Explosion(self.explosion_sprites, key.rect[0], key.rect[1]))
self.kill_sound.play()
@PatrickKalkman
PatrickKalkman / shoot_rocket.py
Created June 12, 2021 15:02
The method to scoot a rocket
def shoot_rocket(self):
rocket = Rocket(self.sprites, 0, -15)
rocket.rect.centerx = self.player.rect.centerx
self.all_rockets.add(rocket)
self.all_sprites.add(rocket)
self.shoot_sound.play()
@PatrickKalkman
PatrickKalkman / player.py
Created June 12, 2021 13:09
The player sprite class
class Player(pygame.sprite.Sprite):
def __init__(self, sprites):
super(Player, self).__init__()
self.timer = 0
self.interval = 2
self.number_of_images = 6
self.images = sprites.load_strip([0, 130, 48, 45], self.number_of_images, -1)
self.surf = self.images[0]
self.rect = self.surf.get_rect(center=(constants.SCREEN_WIDTH / 2, constants.SCREEN_HEIGHT - 40))
self.image_index = 0