diff --git a/NS.py b/NS.py index f19f904..edb43a9 100644 --- a/NS.py +++ b/NS.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from random import randint, choice +from random import randint, choice, random from math import pi from copy import copy from glob import iglob @@ -9,16 +9,17 @@ from threading import Thread from serial import Serial, SerialException from serial.tools import list_ports from time import sleep +from PIL import Image from pygame import Surface, Color, mixer from pygame.event import clear from pygame.mixer import Sound from pygame.image import load, fromstring -from pygame.transform import rotate, flip +from pygame.transform import rotate, flip, scale from pygame.time import get_ticks from pygame.font import Font from pygame.draw import aalines, lines -from pygame.gfxdraw import aapolygon, arc, polygon, aaellipse, ellipse, filled_ellipse +from pygame.gfxdraw import aapolygon, arc, polygon, aaellipse, ellipse, filled_ellipse, filled_circle from pygame.locals import * from lib.pgfw.pgfw.Game import Game @@ -212,12 +213,12 @@ class NS(Game, Animation): print("auto arduino reset triggered") self.reset_arduino() self.no_reset_elapsed = 0 - self.title.update() self.introduction.update() self.ending.update() self.boss.update() self.platform.update() self.chemtrails.update() + self.title.update() self.boss.update_dialogue() self.wipe.update() self.idle_elapsed += self.time_filter.get_last_frame_duration() @@ -336,6 +337,42 @@ class Tony(Sprite): self.add_frame(frame) +class Video(Sprite): + + def __init__(self, parent): + Sprite.__init__(self, parent, 100) + pattern = join(self.get_resource("gif"), "Boarding_*.gif") + self.gifs = [] + for path in iglob(pattern): + self.gifs.append(Image.open(path)) + print(self.gifs[-1].info) + self.gif = self.gifs[1] + self.mask = Surface((320, 320), SRCALPHA) + rect = self.mask.get_rect() + filled_circle(self.mask, rect.centerx, rect.centery, rect.centerx, (255, 255, 255)) + + def update(self): + if random() < .01: + while True: + selection = choice(self.gifs) + if selection != self.gif: + self.gif = selection + break + if random() < .005: + self.toggle_hidden() + self.gif.seek((self.gif.tell() + 1) % self.gif.n_frames) + frame = scale( + fromstring(self.gif.convert("RGBA").tobytes(), self.gif.size, "RGBA"), + (self.mask.get_width(), int(self.gif.width * self.gif.height / self.mask.get_width()))) + copy = self.mask.copy() + rect = frame.get_rect() + rect.bottom = copy.get_rect().bottom + copy.blit(frame, rect, None, BLEND_RGBA_MIN) + self.clear_frames() + self.add_frame(copy) + Sprite.update(self) + + class Title(GameChild): UNLOCK_MOVES = NS.N, NS.NW, NS.E, NS.S @@ -347,7 +384,8 @@ class Title(GameChild): ds = self.get_display_surface() dsr = ds.get_rect() self.plank.location.center = dsr.center - self.angle = choice((pi / 4, 3 * pi / 4, 5 * pi / 4, 7 * pi / 4)) + # self.angle = choice((pi / 4, 3 * pi / 4, 5 * pi / 4, 7 * pi / 4)) + self.angle = 7 * pi / 4 self.background = Sprite(self) self.background.load_from_path(self.get_resource("Title_tile.png"), True) for y in range(0, dsr.h + self.background.location.h, self.background.location.h): @@ -362,6 +400,7 @@ class Title(GameChild): for x in range(0, dsr.w, thickness): frame.fill(palette[(offset + x) % len(palette)], (x, 0, thickness, dsr.h)) self.effect.add_frame(frame) + self.video = Video(self) def reset(self): self.first_pressed = False @@ -452,6 +491,24 @@ class Title(GameChild): if self.first_pressed_elapsed > 1000 * 60 * 1: self.reset() platform.update() + self.get_game().chemtrails.update() + # bounce the gif around the screen + if self.video.location.right > dsr.right or self.video.location.left < dsr.left: + self.angle = reflect_angle(self.angle, 0) + if self.video.location.right > dsr.right: + self.video.move(dsr.right - self.video.location.right) + else: + self.video.move(dsr.left - self.video.location.left) + if self.video.location.bottom > dsr.bottom or self.video.location.top < dsr.top: + self.angle = reflect_angle(self.angle, pi) + if self.video.location.bottom > dsr.bottom: + self.video.move(dy=dsr.bottom - self.video.location.bottom) + else: + self.video.move(dy=dsr.top - self.video.location.top) + dx, dy = get_delta(self.angle, 5, False) + self.video.move(dx, dy) + if not platform.get_pressed(): + self.video.update() self.draw_scores() diff --git a/config b/config index 01403b2..04b1bcd 100644 --- a/config +++ b/config @@ -26,7 +26,7 @@ sfx-volume = .8 [input] buffer = 0 arduino-port = /dev/ttyACM0 -serial = no +serial = yes [time] timer-max-time = 10000 diff --git a/resource/gif/Boarding_0.gif b/resource/gif/Boarding_0.gif new file mode 100644 index 0000000..f358415 Binary files /dev/null and b/resource/gif/Boarding_0.gif differ diff --git a/resource/gif/Boarding_1.gif b/resource/gif/Boarding_1.gif new file mode 100644 index 0000000..0139a2f Binary files /dev/null and b/resource/gif/Boarding_1.gif differ diff --git a/resource/gif/Boarding_2.gif b/resource/gif/Boarding_2.gif new file mode 100644 index 0000000..752c6a2 Binary files /dev/null and b/resource/gif/Boarding_2.gif differ diff --git a/resource/gif/Boarding_3.gif b/resource/gif/Boarding_3.gif new file mode 100644 index 0000000..a95ad5a Binary files /dev/null and b/resource/gif/Boarding_3.gif differ diff --git a/resource/gif/Boarding_4.gif b/resource/gif/Boarding_4.gif new file mode 100644 index 0000000..b6a1fc7 Binary files /dev/null and b/resource/gif/Boarding_4.gif differ diff --git a/resource/scores b/resource/scores index a92d9c1..7c9c0b8 100644 --- a/resource/scores +++ b/resource/scores @@ -17,3 +17,5 @@ 312561 173960 237842 +171298 +164711 diff --git a/www/Boarding_0.gif b/www/Boarding_0.gif deleted file mode 100644 index f358415..0000000 Binary files a/www/Boarding_0.gif and /dev/null differ diff --git a/www/Boarding_0.gif b/www/Boarding_0.gif new file mode 120000 index 0000000..9cdd11b --- /dev/null +++ b/www/Boarding_0.gif @@ -0,0 +1 @@ +../resource/gif/Boarding_0.gif \ No newline at end of file diff --git a/www/Boarding_1.gif b/www/Boarding_1.gif deleted file mode 100644 index 0139a2f..0000000 Binary files a/www/Boarding_1.gif and /dev/null differ diff --git a/www/Boarding_1.gif b/www/Boarding_1.gif new file mode 120000 index 0000000..ca44342 --- /dev/null +++ b/www/Boarding_1.gif @@ -0,0 +1 @@ +../resource/gif/Boarding_1.gif \ No newline at end of file diff --git a/www/Boarding_2.gif b/www/Boarding_2.gif deleted file mode 100644 index 752c6a2..0000000 Binary files a/www/Boarding_2.gif and /dev/null differ diff --git a/www/Boarding_2.gif b/www/Boarding_2.gif new file mode 120000 index 0000000..92b008e --- /dev/null +++ b/www/Boarding_2.gif @@ -0,0 +1 @@ +../resource/gif/Boarding_2.gif \ No newline at end of file diff --git a/www/Boarding_3.gif b/www/Boarding_3.gif deleted file mode 100644 index a95ad5a..0000000 Binary files a/www/Boarding_3.gif and /dev/null differ diff --git a/www/Boarding_3.gif b/www/Boarding_3.gif new file mode 120000 index 0000000..e4ddf9c --- /dev/null +++ b/www/Boarding_3.gif @@ -0,0 +1 @@ +../resource/gif/Boarding_3.gif \ No newline at end of file diff --git a/www/Multiplay_Closing-Flan.gif b/www/Multiplay_Closing-Flan.gif deleted file mode 100644 index b6a1fc7..0000000 Binary files a/www/Multiplay_Closing-Flan.gif and /dev/null differ diff --git a/www/Multiplay_Closing-Flan.gif b/www/Multiplay_Closing-Flan.gif new file mode 120000 index 0000000..7a57ce4 --- /dev/null +++ b/www/Multiplay_Closing-Flan.gif @@ -0,0 +1 @@ +../resource/gif/Boarding_4.gif \ No newline at end of file