This commit is contained in:
Frank DeMarco 2018-11-21 01:19:29 -05:00
parent 51bc4e97ab
commit 86f3aef797
29 changed files with 208 additions and 45 deletions

88
NS.py
View File

@ -10,7 +10,7 @@ from serial import Serial, SerialException
from serial.tools import list_ports
from time import sleep
from pygame import Surface, Color
from pygame import Surface, Color, mixer
from pygame.event import clear
from pygame.mixer import Sound
from pygame.image import load, fromstring
@ -43,6 +43,7 @@ class NS(Game, Animation):
FRONT = 300
STEP = .4
IDLE_TIMEOUT = 60000 * 5
CHANNEL_COUNT = 8
def __init__(self):
Game.__init__(self)
@ -58,6 +59,7 @@ class NS(Game, Animation):
}
})
Animation.__init__(self, self)
mixer.init(44100, -16, self.CHANNEL_COUNT, 4096)
self.load_sfx()
self.subscribe(self.respond, KEYDOWN)
self.subscribe(self.respond, KEYUP)
@ -107,6 +109,7 @@ class NS(Game, Animation):
name = self.get_configuration("input", "arduino-port")
try:
transmission = self.serial_reader.readline().strip()
print transmission
except SerialException:
print "Serial not ready... passing..."
transmission = ""
@ -114,6 +117,7 @@ class NS(Game, Animation):
try:
self.serial_data = int(transmission, 2)
except ValueError:
print "Value error checking four digit serial transmission"
self.handle_garbage(transmission)
self.reset_arduino()
self.idle_elapsed = 0
@ -121,6 +125,7 @@ class NS(Game, Animation):
try:
int(transmission, 2)
except ValueError:
print "Received a non-four digit serial transmission"
self.handle_garbage(transmission)
else:
self.serial_data = 0
@ -265,13 +270,13 @@ class Meter(GameChild):
def __init__(self, parent):
GameChild.__init__(self, parent)
def setup(self, background, rect, indent, color, units):
def setup(self, background, rect, indent, color, units, path):
self.background = background
self.rect = rect
self.icons = []
x = rect.left + indent
base = get_color_swapped_surface(
load(self.get_resource("HUD_circle.png")).convert_alpha(),
load(self.get_resource(path)).convert_alpha(),
(0, 0, 0), color)
while x <= self.rect.right - base.get_width() - self.SPACING:
icon = Sprite(self)
@ -416,7 +421,7 @@ class Title(GameChild):
# self.first_pressed = False
# self.first_pressed_elapsed = 0
# self.buttons[0].unhide()
self.border.update()
self.border.update()
self.text.update()
self.draw_scores()
for button in self.buttons:
@ -539,6 +544,11 @@ class Introduction(Animation):
def __init__(self, parent):
Animation.__init__(self, parent)
self.words = []
for word in "hey you lizard slime bag show me you can scrape".split(" "):
font = Font(self.get_resource(Dialogue.FONT_PATH), 96)
sprite = RainbowSprite(self, font.render(word, True, (255, 0, 0)), 30)
self.words.append(sprite)
self.tony = load(self.get_resource("Big_Tony.png")).convert()
self.skateboard = Sprite(self)
self.skateboard.load_from_path(self.get_resource("Introduction_skateboard.png"), True)
@ -551,7 +561,7 @@ class Introduction(Animation):
self.tony_avatar = load(self.get_resource("Introduction_tony_avatar.png")).convert()
self.advance_prompt = AdvancePrompt(self)
self.skip_prompt = SkipPrompt(self, self.start_wipe)
self.register(self.start, self.move_board, self.take_board)
self.register(self.start, self.move_board, self.take_board, self.speak)
def reset(self):
self.deactivate()
@ -561,8 +571,12 @@ class Introduction(Animation):
self.skateboard.hide()
self.text_index = 0
self.tutorial_index = 0
self.words_index = 0
self.advance_prompt.reset()
self.skip_prompt.reset()
for word in self.words:
word.location.center = self.get_display_surface().get_rect().centerx, 100
word.hide()
def deactivate(self):
self.active = False
@ -570,8 +584,18 @@ class Introduction(Animation):
def activate(self):
self.active = True
self.play(self.start, delay=3000, play_once=True)
self.words[0].unhide()
self.play(self.speak)
# self.get_game().platform.unpress()
def speak(self):
for ii in xrange(self.words_index + 1):
self.words[ii].move(0, 12)
if ii == self.words_index and self.words[ii].location.bottom > self.get_display_surface().get_rect().bottom - 40:
if self.words_index < len(self.words) - 1:
self.words_index += 1
self.words[self.words_index].unhide()
def start(self):
self.advance_prompt.cancel_first_press()
dialogue = self.get_game().dialogue
@ -620,7 +644,7 @@ class Introduction(Animation):
def update(self):
if self.active:
Animation.update(self)
dialogue = self.get_game().dialogue
# dialogue = self.get_game().dialogue
wipe = self.get_game().wipe
if not wipe.is_playing() and not self.is_playing(self.start) and not self.text_index == 2:
if self.advance_prompt.check_first_press():
@ -648,27 +672,30 @@ class Introduction(Animation):
self.start_wipe()
# self.get_game().platform.unpress()
self.advance_prompt.cancel_first_press()
elif self.text_index == 2:
elif not wipe.is_playing() and self.text_index == 2:
platform = self.get_game().platform
if platform.get_edge_pressed() == self.TUTORIAL_MOVES[self.tutorial_index]:
self.tutorial_index += 1
self.get_game().sfx["land_0"].play()
if self.tutorial_index == len(self.TUTORIAL_MOVES):
self.text_index += 1
self.advance_prompt.cancel_first_press()
# self.text_index += 1
# self.advance_prompt.cancel_first_press()
platform.set_glowing([])
dialogue.show_text(self.TEXT[self.text_index])
self.start_wipe()
# dialogue.show_text(self.TEXT[self.text_index])
else:
platform.set_glowing(platform.get_buttons_from_edges(
[self.TUTORIAL_MOVES[self.tutorial_index]]))
self.get_display_surface().blit(self.tony, (0, 0))
self.slime_bag.update()
self.skateboard.update()
for word in self.words:
word.update()
self.get_game().platform.update()
self.get_game().dialogue.update()
if not wipe.is_playing() and not self.is_playing(self.start) and \
not self.text_index == 2:
self.advance_prompt.update()
# self.get_game().dialogue.update()
# if not wipe.is_playing() and not self.is_playing(self.start) and \
# not self.text_index == 2:
# self.advance_prompt.update()
if not wipe.is_playing() and not self.text_index == 2:
self.skip_prompt.update()
@ -1146,7 +1173,7 @@ class Chemtrails(Sprite):
if not boss.is_playing(boss.show_introduction_dialogue):
self.timer.update()
self.life.update()
self.boys.update()
# self.boys.update()
def attack(self):
boss = self.get_game().boss
@ -1216,7 +1243,7 @@ class Timer(Meter):
rect = background.get_rect()
rect.bottomright = dsr.right - 6, dsr.bottom - 4
self.setup(background, rect, 53, (0, 0, 255),
self.get_configuration("time", "timer-start-time"))
self.get_configuration("time", "timer-start-time"), "scrapeIcons/scrapeIcons_07.png")
def add_time(self, amount):
self.change(amount)
@ -1233,7 +1260,7 @@ class Life(Meter):
background = load(self.get_resource("HUD_health.png")).convert()
rect = background.get_rect()
rect.bottomleft = 172, dsr.bottom - 4
self.setup(background, rect, 70, (255, 0, 0), 3)
self.setup(background, rect, 70, (255, 0, 0), 3, "scrapeIcons/scrapeIcons_03.png")
def decrease(self):
self.get_game().sfx["hurt"].play()
@ -1252,7 +1279,7 @@ class Boys(Meter):
background = load(self.get_resource("HUD_lives.png")).convert()
rect = background.get_rect()
rect.bottomleft = 6, dsr.bottom - 4
self.setup(background, rect, 60, (0, 255, 0), 3)
self.setup(background, rect, 60, (0, 255, 0), 3, "scrapeIcons/scrapeIcons_01.png")
class Boss(Animation):
@ -1355,7 +1382,8 @@ class Boss(Animation):
def combo(self):
self.queue = None
self.get_game().reset_arduino()
if self.get_game().serial_enabled():
self.get_game().reset_arduino()
self.play(self.brandish, delay=2500, play_once=True)
def brandish(self):
@ -1798,10 +1826,24 @@ class Health(Meter):
def __init__(self, parent):
Meter.__init__(self, parent)
dsr = self.get_display_surface().get_rect()
background = load(self.get_resource("HUD_boss.png")).convert()
rect = background.get_rect()
rect.midtop = dsr.centerx, self.OFFSET
self.setup(background, rect, 52, (255, 0, 255), 100)
self.background = load(self.get_resource("HUD_boss.png")).convert()
self.rect = self.background.get_rect()
self.rect.midtop = dsr.centerx, self.OFFSET
def setup(self):
level_index = self.get_game().boss.level_index
if level_index == 0:
icon_index = 22
elif level_index == 1:
icon_index = 17
elif level_index == 2:
icon_index = 19
Meter.setup(self, self.background, self.rect, 52, (255, 0, 255), 100,
"scrapeIcons/scrapeIcons_%i.png" % icon_index)
def reset(self):
self.setup()
Meter.reset(self)
def decrease(self, damage):
self.change(-damage)

View File

@ -32,8 +32,8 @@ def move_to_executable():
if is_python_3():
launch_alternative(["python2", "python2.7", "python2.6"])
if maxint >> 33:
launch_alternative(["python-32", "python2-32", "python2.7-32", "python2.6-32"])
# if maxint >> 33:
# launch_alternative(["python-32", "python2-32", "python2.7-32", "python2.6-32"])
if not can_import("pygame"):
launch_alternative(["python2.7", "python2.6"])

@ -1 +1 @@
Subproject commit 41b4df6326afbad64aa5dc00ac5d3dc854e8096f
Subproject commit 498755ef0e4cadfe3784363e5eb0ec1aff016631

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -15,22 +15,6 @@
171204
256769
312561
242763
230604
234298
335281
156682
234931
184682
237113
254185
209634
150791
200320
148060
159544
193185
246109
171802
150366
248085
137266
125811
127948

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

137
serial/serial.ino Normal file
View File

@ -0,0 +1,137 @@
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 500; // interval at which to blink (milliseconds)
int pushButton1 = 2;
int pushButton2 = 4;
int pushButton3 = 6;
int pushButton4 = 11;
int buttons[4] = {
pushButton1,
pushButton2,
pushButton3,
pushButton4
};
void setup() {
// set the digital pin as output:
Serial.begin(9600);
pinMode(pushButton1, OUTPUT);
digitalWrite(pushButton1, LOW);
pinMode(pushButton2, INPUT_PULLUP);
pinMode(pushButton3, INPUT_PULLUP);
pinMode(pushButton4, INPUT_PULLUP);
}
bool testConnection2(int A, int B) {
for (int i = 0; i < 4; i++) {
if (i == A) {
pinMode(buttons[i], OUTPUT);
digitalWrite(buttons[i], LOW);
} else {
// digitalWrite(buttons[i], HIGH);
pinMode(buttons[i], INPUT_PULLUP);
}
}
// delay(10);
if (!digitalRead(buttons[B])) {
return true;
} else {
return false;
}
}
bool testConnection(int A, int B) {
return testConnection2(A, B) && testConnection2(B, A);
}
// int lastNumber = -1;
void loop() {
if (testConnection(0, 1)) {
// if (lastNumber != 01) {
// lastNumber = 01;
Serial.println("0011");
// }
} else if (testConnection(0, 2)) {
// if (lastNumber != 02) {
// lastNumber = 02;
Serial.println("0101");
// }
} else if (testConnection(0, 3)) {
// if (lastNumber != 03) {
// lastNumber = 03;
Serial.println("1001");
// }
} else if (testConnection(1, 2)) {
// if (lastNumber != 12) {
// lastNumber = 12;
Serial.println("0110");
// }
} else if (testConnection(1, 3)) {
// if (lastNumber != 13) {
// lastNumber = 13;
Serial.println("1010");
// }
} else if (testConnection(2, 3)) {
// if (lastNumber != 23) {
// lastNumber = 23;
Serial.println("1100");
// }
// } else {
// if (lastNumber != 0) {
// lastNumber = 0;
// Serial.println("0000");
// }
}
}
/*
for (int ii = 0; ii < 4; ii++)
{
for (int jj = 0; jj < 4; jj++)
{
if (jj == ii)
{
pinMode(buttons[jj], OUTPUT);
digitalWrite(buttons[jj], LOW);
}
else
{
pinMode(buttons[jj], INPUT_PULLUP);
}
}
for (int jj = ii; jj < 4; jj++)
{
if (!(ii == jj) && !digitalRead(buttons[jj]))
{
for (int kk = 3; kk >= 0; kk--)
{
if (kk == ii || kk == jj)
{
Serial.print(1);
}
else
{
Serial.print(0);
}
}
Serial.print("\n");
received_input = true;
break;
}
}
// if (received_input)
// {
// break;
// }
}
*/