flush
This commit is contained in:
parent
090a41549d
commit
51bc4e97ab
150
NS.py
150
NS.py
|
@ -6,8 +6,9 @@ from copy import copy
|
|||
from glob import iglob
|
||||
from os.path import basename, join
|
||||
from threading import Thread
|
||||
from serial import Serial
|
||||
from serial import Serial, SerialException
|
||||
from serial.tools import list_ports
|
||||
from time import sleep
|
||||
|
||||
from pygame import Surface, Color
|
||||
from pygame.event import clear
|
||||
|
@ -75,7 +76,9 @@ class NS(Game, Animation):
|
|||
if self.serial_enabled():
|
||||
self.serial_kill = False
|
||||
self.serial_data = 0
|
||||
self.serial_reader = Serial(self.get_configuration("input", "arduino-port"), timeout=.1)
|
||||
self.serial_reader = Serial(self.get_configuration("input", "arduino-port"),
|
||||
timeout=.3)
|
||||
self.reset_arduino()
|
||||
# for port in list_ports.comports():
|
||||
# print port.device
|
||||
# print "---"
|
||||
|
@ -102,18 +105,38 @@ class NS(Game, Animation):
|
|||
def read_serial(self):
|
||||
while not self.serial_kill:
|
||||
name = self.get_configuration("input", "arduino-port")
|
||||
if name not in (port.device for port in list_ports.comports()):
|
||||
print "%s disconnected" % name
|
||||
output = self.serial_reader.readline().strip()
|
||||
if output:
|
||||
self.serial_data = int(output, 2)
|
||||
try:
|
||||
transmission = self.serial_reader.readline().strip()
|
||||
except SerialException:
|
||||
print "Serial not ready... passing..."
|
||||
transmission = ""
|
||||
if len(transmission) == 4:
|
||||
try:
|
||||
self.serial_data = int(transmission, 2)
|
||||
except ValueError:
|
||||
self.handle_garbage(transmission)
|
||||
self.reset_arduino()
|
||||
self.idle_elapsed = 0
|
||||
elif len(transmission) > 0:
|
||||
try:
|
||||
int(transmission, 2)
|
||||
except ValueError:
|
||||
self.handle_garbage(transmission)
|
||||
else:
|
||||
self.serial_data = 0
|
||||
|
||||
def handle_garbage(self, transmission):
|
||||
self.serial_data = 0
|
||||
print "Garbage detected: %s" % transmission
|
||||
self.serial_reader.reset_input_buffer()
|
||||
|
||||
def reset_arduino(self):
|
||||
self.serial_reader.dtr = False
|
||||
self.serial_reader.reset_input_buffer()
|
||||
self.serial_reader.dtr = True
|
||||
|
||||
def end(self, evt):
|
||||
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
|
||||
print "kill serial"
|
||||
self.serial_kill = True
|
||||
Game.end(self, evt)
|
||||
|
||||
|
@ -164,6 +187,8 @@ class NS(Game, Animation):
|
|||
lights[NS.LSW].pressed = pressed
|
||||
elif event.key == K_z:
|
||||
self.reset()
|
||||
elif event.key == K_a:
|
||||
self.reset_arduino()
|
||||
self.last_press = get_ticks()
|
||||
else:
|
||||
if self.get_delegate().compare(event, "reset-game"):
|
||||
|
@ -387,11 +412,11 @@ class Title(GameChild):
|
|||
self.get_game().sfx["confirm"].play()
|
||||
elif self.first_pressed:
|
||||
self.first_pressed_elapsed += self.get_game().time_filter.get_last_frame_duration()
|
||||
if self.first_pressed_elapsed > 4000:
|
||||
self.first_pressed = False
|
||||
self.first_pressed_elapsed = 0
|
||||
self.buttons[0].unhide()
|
||||
self.border.update()
|
||||
# if self.first_pressed_elapsed > 4000:
|
||||
# self.first_pressed = False
|
||||
# self.first_pressed_elapsed = 0
|
||||
# self.buttons[0].unhide()
|
||||
self.border.update()
|
||||
self.text.update()
|
||||
self.draw_scores()
|
||||
for button in self.buttons:
|
||||
|
@ -498,14 +523,17 @@ class Dialogue(Animation):
|
|||
|
||||
class Introduction(Animation):
|
||||
|
||||
TEXT = "Hey, you lizard slime bag. It's me Giant Tony. " + \
|
||||
"Do you think you\ncan skate like me? Prove it!", \
|
||||
"I'll even give you my board for this adventure. And ink my name\n" + \
|
||||
"on it. Now the power of Giant Tony pulses through you.", \
|
||||
"Before you go, show me you can scrape! Use your board to touch\n" + \
|
||||
"the glowing pads on the platform!", \
|
||||
"Good job, lizard scum! Maybe now you're ready to take on Kool\n" + \
|
||||
"Man and his friends. Don't let me down!"
|
||||
TEXT = (
|
||||
"Hey, you lizard slime bag. It's me Giant Tony. " + \
|
||||
"Do you think you\ncan skate like me? Prove it!",
|
||||
"I'll even give you my board for this adventure. And ink my name\n" + \
|
||||
"on it. Now the power of Giant Tony pulses through you.",
|
||||
# "Before you go, show me you can scrape! Use your board to touch\n" + \
|
||||
"Before you play, show me you can scrape! Use your board to touch\n" + \
|
||||
"the glowing pads on the platform!", \
|
||||
# "Good job, lizard scum! Maybe now you're ready to take on Kool\n" + \
|
||||
"Good job, slime bag! Maybe now you're ready to take on Kool\n" + \
|
||||
"Man and his friends. Don't let me down!")
|
||||
SKATEBOARD_START = -30, -20
|
||||
TUTORIAL_MOVES = NS.S, NS.NE, NS.N, NS.E
|
||||
|
||||
|
@ -550,8 +578,20 @@ class Introduction(Animation):
|
|||
dialogue.activate()
|
||||
dialogue.set_avatar(self.tony_avatar)
|
||||
dialogue.set_name("???")
|
||||
dialogue.show_text(self.TEXT[0])
|
||||
# dialogue.show_text(self.TEXT[0])
|
||||
dialogue.show_text(self.TEXT[2])
|
||||
self.text_index = 0
|
||||
# temporary dialogue skip
|
||||
dialogue.set_name("Tony")
|
||||
self.slime_bag.hide()
|
||||
self.halt(self.move_board)
|
||||
self.take_board()
|
||||
platform = self.get_game().platform
|
||||
platform.activate()
|
||||
platform.set_glowing(platform.get_buttons_from_edges(
|
||||
[self.TUTORIAL_MOVES[self.tutorial_index]]))
|
||||
self.get_game().chemtrails.activate()
|
||||
self.text_index = 2
|
||||
|
||||
def give_board(self):
|
||||
self.skateboard.location.center = self.SKATEBOARD_START
|
||||
|
@ -745,8 +785,8 @@ class AdvancePrompt(GameChild):
|
|||
def update(self):
|
||||
if self.first_pressed:
|
||||
self.first_pressed_elapsed += self.get_game().time_filter.get_last_frame_duration()
|
||||
if self.first_pressed_elapsed > 4000:
|
||||
self.cancel_first_press()
|
||||
# if self.first_pressed_elapsed > 4000:
|
||||
# self.cancel_first_press()
|
||||
for button in self.buttons:
|
||||
button.update()
|
||||
self.plus.update()
|
||||
|
@ -1239,6 +1279,7 @@ class Boss(Animation):
|
|||
self.backgrounds[0].load_from_path(self.get_resource("bg/bg001.png"))
|
||||
self.backgrounds[1].load_from_path(self.get_resource("bg/bg002.png"))
|
||||
self.backgrounds[2].load_from_path(self.get_resource("bg/bg003.png"))
|
||||
self.countdown = Countdown(self)
|
||||
|
||||
def cancel_flash(self):
|
||||
if self.level_index == 0:
|
||||
|
@ -1304,6 +1345,7 @@ class Boss(Animation):
|
|||
self.advance_prompt.reset()
|
||||
self.queue = None
|
||||
self.brandish_complete = True
|
||||
self.countdown.reset()
|
||||
|
||||
def deactivate(self):
|
||||
self.active = False
|
||||
|
@ -1313,6 +1355,7 @@ class Boss(Animation):
|
|||
|
||||
def combo(self):
|
||||
self.queue = None
|
||||
self.get_game().reset_arduino()
|
||||
self.play(self.brandish, delay=2500, play_once=True)
|
||||
|
||||
def brandish(self):
|
||||
|
@ -1529,6 +1572,8 @@ class Boss(Animation):
|
|||
else:
|
||||
dialogue.show_text("H-how? But you're only a lizard! How could you" +
|
||||
" manage to defeat\nall of us?")
|
||||
if self.player_defeated:
|
||||
self.countdown.activate()
|
||||
|
||||
def transition_to_battle(self):
|
||||
index = self.level_index + (not self.player_defeated)
|
||||
|
@ -1558,10 +1603,11 @@ class Boss(Animation):
|
|||
if self.active:
|
||||
self.backgrounds[self.level_index].update()
|
||||
dialogue = self.get_game().dialogue
|
||||
if dialogue.active:
|
||||
if dialogue.active and self.get_game().chemtrails.boys.amount > 0:
|
||||
if self.advance_prompt.check_first_press():
|
||||
self.advance_prompt.press_first()
|
||||
elif self.advance_prompt.check_second_press():
|
||||
self.countdown.deactivate()
|
||||
if dialogue.is_playing():
|
||||
dialogue.show_all()
|
||||
else:
|
||||
|
@ -1582,6 +1628,7 @@ class Boss(Animation):
|
|||
self.spoopy.update()
|
||||
self.sword.update()
|
||||
self.health.update()
|
||||
self.countdown.update()
|
||||
|
||||
def update_dialogue(self):
|
||||
if self.active:
|
||||
|
@ -1591,6 +1638,59 @@ class Boss(Animation):
|
|||
self.advance_prompt.update()
|
||||
|
||||
|
||||
class Countdown(GameChild):
|
||||
|
||||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
dsr = self.get_display_surface().get_rect()
|
||||
font = Font(self.get_resource(Dialogue.FONT_PATH), 76)
|
||||
self.heading = Sprite(self)
|
||||
self.heading.add_frame(font.render("CONTINUE?", True, (0, 0, 0), (255, 255, 255)))
|
||||
self.heading.location.midtop = dsr.centerx, 50
|
||||
self.game_over = Sprite(self)
|
||||
self.game_over.add_frame(font.render("GAME OVER", True, (0, 0, 0), (255, 255, 255)))
|
||||
self.game_over.location.center = dsr.centerx, dsr.centery - 40
|
||||
self.glyphs = []
|
||||
for ii in xrange(10):
|
||||
glyph = Sprite(self)
|
||||
frame = Surface((140, 140))
|
||||
frame.fill((255, 255, 255))
|
||||
digits = font.render("%i" % ii, True, (0, 0, 0), (255, 255, 255))
|
||||
rect = digits.get_rect()
|
||||
rect.center = frame.get_rect().center
|
||||
frame.blit(digits, rect)
|
||||
glyph.add_frame(frame)
|
||||
glyph.location.center = dsr.centerx, dsr.centery - 30
|
||||
self.glyphs.append(glyph)
|
||||
|
||||
def reset(self):
|
||||
self.deactivate()
|
||||
|
||||
def deactivate(self):
|
||||
self.active = False
|
||||
|
||||
def activate(self):
|
||||
self.remaining = 9999
|
||||
self.active = True
|
||||
|
||||
def end_game(self):
|
||||
self.get_game().reset(True)
|
||||
|
||||
def update(self):
|
||||
if self.active:
|
||||
if self.get_game().chemtrails.boys.amount > 0:
|
||||
self.heading.update()
|
||||
self.glyphs[int(self.remaining / 1000)].update()
|
||||
else:
|
||||
self.game_over.update()
|
||||
if not self.get_game().wipe.is_playing():
|
||||
if self.remaining <= 0:
|
||||
self.get_game().wipe.start(self.end_game)
|
||||
self.remaining = 0
|
||||
else:
|
||||
self.remaining -= self.get_game().time_filter.get_last_frame_duration()
|
||||
|
||||
|
||||
class Sword(Animation):
|
||||
|
||||
SHIFT = 15
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
|
@ -26,3 +26,11 @@
|
|||
254185
|
||||
209634
|
||||
150791
|
||||
200320
|
||||
148060
|
||||
159544
|
||||
193185
|
||||
246109
|
||||
171802
|
||||
150366
|
||||
248085
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
|
||||
// constants won't change:
|
||||
const long interval = 25; // 25 ms * 6 tests * 2 = 200 ms means 5 loops per second
|
||||
|
||||
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 {
|
||||
pinMode(buttons[i], INPUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
delay(interval);
|
||||
if (!digitalRead(buttons[B])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool testConnection(int A, int B) {
|
||||
return testConnection2(A, B) && testConnection2(B, A);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (testConnection(0, 1)) {
|
||||
Serial.println("0011");
|
||||
} else if (testConnection(0, 2)) {
|
||||
Serial.println("0101");
|
||||
} else if (testConnection(0, 3)) {
|
||||
Serial.println("1001");
|
||||
} else if (testConnection(1, 2)) {
|
||||
Serial.println("0110");
|
||||
} else if (testConnection(1, 3)) {
|
||||
Serial.println("1010");
|
||||
} else if (testConnection(2, 3)) {
|
||||
Serial.println("1100");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue