bouncing scrape gif bubble
67
NS.py
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from random import randint, choice
|
from random import randint, choice, random
|
||||||
from math import pi
|
from math import pi
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from glob import iglob
|
from glob import iglob
|
||||||
|
@ -9,16 +9,17 @@ from threading import Thread
|
||||||
from serial import Serial, SerialException
|
from serial import Serial, SerialException
|
||||||
from serial.tools import list_ports
|
from serial.tools import list_ports
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from pygame import Surface, Color, mixer
|
from pygame import Surface, Color, mixer
|
||||||
from pygame.event import clear
|
from pygame.event import clear
|
||||||
from pygame.mixer import Sound
|
from pygame.mixer import Sound
|
||||||
from pygame.image import load, fromstring
|
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.time import get_ticks
|
||||||
from pygame.font import Font
|
from pygame.font import Font
|
||||||
from pygame.draw import aalines, lines
|
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 pygame.locals import *
|
||||||
|
|
||||||
from lib.pgfw.pgfw.Game import Game
|
from lib.pgfw.pgfw.Game import Game
|
||||||
|
@ -212,12 +213,12 @@ class NS(Game, Animation):
|
||||||
print("auto arduino reset triggered")
|
print("auto arduino reset triggered")
|
||||||
self.reset_arduino()
|
self.reset_arduino()
|
||||||
self.no_reset_elapsed = 0
|
self.no_reset_elapsed = 0
|
||||||
self.title.update()
|
|
||||||
self.introduction.update()
|
self.introduction.update()
|
||||||
self.ending.update()
|
self.ending.update()
|
||||||
self.boss.update()
|
self.boss.update()
|
||||||
self.platform.update()
|
self.platform.update()
|
||||||
self.chemtrails.update()
|
self.chemtrails.update()
|
||||||
|
self.title.update()
|
||||||
self.boss.update_dialogue()
|
self.boss.update_dialogue()
|
||||||
self.wipe.update()
|
self.wipe.update()
|
||||||
self.idle_elapsed += self.time_filter.get_last_frame_duration()
|
self.idle_elapsed += self.time_filter.get_last_frame_duration()
|
||||||
|
@ -336,6 +337,42 @@ class Tony(Sprite):
|
||||||
self.add_frame(frame)
|
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):
|
class Title(GameChild):
|
||||||
|
|
||||||
UNLOCK_MOVES = NS.N, NS.NW, NS.E, NS.S
|
UNLOCK_MOVES = NS.N, NS.NW, NS.E, NS.S
|
||||||
|
@ -347,7 +384,8 @@ class Title(GameChild):
|
||||||
ds = self.get_display_surface()
|
ds = self.get_display_surface()
|
||||||
dsr = ds.get_rect()
|
dsr = ds.get_rect()
|
||||||
self.plank.location.center = dsr.center
|
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 = Sprite(self)
|
||||||
self.background.load_from_path(self.get_resource("Title_tile.png"), True)
|
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):
|
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):
|
for x in range(0, dsr.w, thickness):
|
||||||
frame.fill(palette[(offset + x) % len(palette)], (x, 0, thickness, dsr.h))
|
frame.fill(palette[(offset + x) % len(palette)], (x, 0, thickness, dsr.h))
|
||||||
self.effect.add_frame(frame)
|
self.effect.add_frame(frame)
|
||||||
|
self.video = Video(self)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.first_pressed = False
|
self.first_pressed = False
|
||||||
|
@ -452,6 +491,24 @@ class Title(GameChild):
|
||||||
if self.first_pressed_elapsed > 1000 * 60 * 1:
|
if self.first_pressed_elapsed > 1000 * 60 * 1:
|
||||||
self.reset()
|
self.reset()
|
||||||
platform.update()
|
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()
|
self.draw_scores()
|
||||||
|
|
||||||
|
|
||||||
|
|
2
config
|
@ -26,7 +26,7 @@ sfx-volume = .8
|
||||||
[input]
|
[input]
|
||||||
buffer = 0
|
buffer = 0
|
||||||
arduino-port = /dev/ttyACM0
|
arduino-port = /dev/ttyACM0
|
||||||
serial = no
|
serial = yes
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
timer-max-time = 10000
|
timer-max-time = 10000
|
||||||
|
|
After Width: | Height: | Size: 5.3 MiB |
After Width: | Height: | Size: 8.1 MiB |
After Width: | Height: | Size: 5.0 MiB |
After Width: | Height: | Size: 6.4 MiB |
After Width: | Height: | Size: 5.2 MiB |
|
@ -17,3 +17,5 @@
|
||||||
312561
|
312561
|
||||||
173960
|
173960
|
||||||
237842
|
237842
|
||||||
|
171298
|
||||||
|
164711
|
||||||
|
|
Before Width: | Height: | Size: 5.3 MiB After Width: | Height: | Size: 30 B |
|
@ -0,0 +1 @@
|
||||||
|
../resource/gif/Boarding_0.gif
|
Before Width: | Height: | Size: 5.3 MiB After Width: | Height: | Size: 30 B |
Before Width: | Height: | Size: 8.1 MiB After Width: | Height: | Size: 30 B |
|
@ -0,0 +1 @@
|
||||||
|
../resource/gif/Boarding_1.gif
|
Before Width: | Height: | Size: 8.1 MiB After Width: | Height: | Size: 30 B |
Before Width: | Height: | Size: 5.0 MiB After Width: | Height: | Size: 30 B |
|
@ -0,0 +1 @@
|
||||||
|
../resource/gif/Boarding_2.gif
|
Before Width: | Height: | Size: 5.0 MiB After Width: | Height: | Size: 30 B |
Before Width: | Height: | Size: 6.4 MiB After Width: | Height: | Size: 30 B |
|
@ -0,0 +1 @@
|
||||||
|
../resource/gif/Boarding_3.gif
|
Before Width: | Height: | Size: 6.4 MiB After Width: | Height: | Size: 30 B |
Before Width: | Height: | Size: 5.2 MiB After Width: | Height: | Size: 30 B |
|
@ -0,0 +1 @@
|
||||||
|
../resource/gif/Boarding_4.gif
|
Before Width: | Height: | Size: 5.2 MiB After Width: | Height: | Size: 30 B |