Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar
🏠
Working from home

Patrick Kalkman PatrickKalkman

🏠
Working from home
View GitHub Profile
@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
@PatrickKalkman
PatrickKalkman / splash.py
Created June 12, 2021 12:37
The splash game state
class Splash(BaseState):
def __init__(self):
super(Splash, self).__init__()
self.title = self.font.render("PyGalaga", True, pygame.Color("blue"))
self.title_rect = self.title.get_rect(center=self.screen_rect.center)
self.next_state = "MENU"
self.time_active = 0
def update(self, dt):
self.time_active += dt
@PatrickKalkman
PatrickKalkman / run.py
Created June 12, 2021 10:35
the main game loop of the game
def run(self):
while not self.done:
dt = self.clock.tick(self.fps)
self.event_loop()
self.update(dt)
self.draw()
pygame.display.update()
@PatrickKalkman
PatrickKalkman / basestate.py
Created June 12, 2021 10:20
Base class for each state of the state machine
class BaseState(object):
def __init__(self):
self.done = False
self.quit = False
self.next_state = None
self.screen_rect = pygame.display.get_surface().get_rect()
self.font = pygame.font.Font(None, 32)
def startup(self):
pass
class BaseState(object):
def __init__(self):
self.done = False
self.quit = False
self.next_state = None
self.screen_rect = pygame.display.get_surface().get_rect()
self.font = pygame.font.Font(None, 32)
def startup(self):
pass
@PatrickKalkman
PatrickKalkman / drm.js
Created May 15, 2021 18:56
Add Widevine and Fairplay DRM
const cert = fetch("YOUR FAIRPLAY CERTIFICATE URL");
if (this.platform.SAFARI) {
this.player.configure({
preferredAudioLanguage: 'en-US',
drm: {
servers: {
'com.apple.fps.1_0': '[fairplay license server URL]',
},
advanced: {
@PatrickKalkman
PatrickKalkman / subtitles.js
Created May 15, 2021 18:23
Loading and selecting subtitles
let captionUrl = "http://amssamples.streaming.mediaservices.windows.net/bc57e088-27ec-44e0-ac20-a85ccbcd50da/TOS-en.vtt";
this.player
.load(videoUrl)
.then(() => {
this.player.addTextTrackAsync(captionUrl, "en", "subtitle", 'text/vtt').then(() => {{
const textTracks = this.player.getTextTracks();
if (textTracks.length > 0) {
this.player.setTextTrackVisibility(true);
this.player.selectTextTrack(textTracks[0]);
}