Ejemplo n.º 1
0
 def __init__(self):
     self.running = True
     self.game_started = False
     self.game_over = False
     self.score = 0
     self.window = Window(self, 900, 600, 'Arkanoid')
     self.game_objects = {'ball': None, 'platform': None, 'plates': []}
Ejemplo n.º 2
0
 def show(self, target=None, parent=None):
     window = Window(height=10, width=20, begin_top=20, begin_left=40)
     # window = pycurses.newwin(10, 20, 20, 20)
     for x in self.context:
         if not isinstance(x, Dom):
             raise pycurses.error('dom\'s context must be dom.')
         x.show(target=window, parent=self)
     window.refresh()
Ejemplo n.º 3
0
class WindowTest(GeneralTest):
    def setUp(self):

        self.window = Window(self._mock_app(), 900, 600, 'Title')
        self.window.UI = MagicMock(UI)

    def tearDown(self):
        self.window = None

    def test_display(self):
        screen = Mock()

        screen.fill = MagicMock()
        self.window.screen = screen

        self.window.display()

        self.window.screen.fill.assert_called_with(self.window.colors['black'])
        self.window.app.game_objects['ball'].draw.assert_called()
        self.window.app.game_objects['platform'].draw.assert_called()
        self.window.app.game_objects['plates'][0].draw.assert_called()
Ejemplo n.º 4
0
from src.Window import *

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    ex = Window()
    sys.exit(app.exec_())
Ejemplo n.º 5
0
    def setUp(self):

        self.window = Window(self._mock_app(), 900, 600, 'Title')
        self.window.UI = MagicMock(UI)
Ejemplo n.º 6
0
# Samples for internal use only. Just test data for test Results
#[fs,data] = wavfile.read('15 Sample 15Sec.wav')
[fs, data] = wavfile.read("09 Sample 15sec.wav")  # ,dtype=float)
data = data[2048:2048+4096:]

# Check input data
data = Conversion.input_check(data)
t = np.arange(0, len(data) / fs, 1 / fs)

# Calculate RMS and Crest Factor
rmssig = RMS.RMS(data)
crest = RMS.Crest(data)

N = 1024
whan = Window.Window(N)
(x, whan) = whan.hanwind()

#if len(t)< 100000:
##    mpl.RcParams()
#    plt.rcParams['agg.path.chunksize'] = 10000

#
# FFT calculation
[F, DATA] = Transform.FFT(data, fs)
[F, RMSSIG] = Transform.FFT(rmssig, fs)


plt.figure()
plt.subplot(2, 1, 1), plt.plot(t, data)
plt.subplot(2, 1, 1), plt.plot(t, rmssig)
Ejemplo n.º 7
0
class Application:
    def __init__(self):
        self.running = True
        self.game_started = False
        self.game_over = False
        self.score = 0
        self.window = Window(self, 900, 600, 'Arkanoid')
        self.game_objects = {'ball': None, 'platform': None, 'plates': []}

    def run(self):
        """
        Main function of the game
        :return: None
        """
        self.window.init()
        self._init_game_objects()

        while self.running:
            self._handle_events()
            if self.game_started and not self.game_over:
                self._handle_platform_moving()

                self.ball.change_direction_border()

                if self._destroy_collided_plates():
                    self.ball.change_direction_plate()

                if self.platform.colliderect(self.ball.get_rect()):
                    self.ball.change_direction_platform()

                self.ball.move()

                # if self.ball is outside the screen game is over
                self.game_over = self.ball.y > self.window.height

            self.window.display()

    def _create_plates_table(self):
        """
        Creates plates table for destroying. 9 row and 16 columns.
        :return:
        """
        result = []
        y_row = 5
        for row in range(9):
            x_row = 5
            for column in range(16):
                result.append(Plate((x_row, y_row)))
                x_row += 55
            y_row += 25

        return result

    def _handle_events(self):
        """
        Handling events
        :return: None
        """
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    if not self.game_started:
                        self.game_started = True
                    elif self.game_over:
                        self.game_over = False
                        self._init_game_objects()
                    else:
                        self.game_started = False

    def _handle_platform_moving(self):
        """
        Change platform position when pressed arrows keys
        :return:
        """
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT] and self.platform.x - 1 >= 0:
            self.platform.move(-4)
        elif keys[
                pygame.K_RIGHT] and self.platform.x + 101 <= self.window.width:
            self.platform.move(4)

    def _init_game_objects(self):
        """
        Init primary game state
        :return: None
        """
        self.ball = Ball(self, (500, 449))
        self.platform = Platform((450, 590))
        self.plates = self._create_plates_table()
        self.score = 0

        self.game_objects = {
            'ball': self.ball,
            'platform': self.platform,
            'plates': self.plates
        }

    def _destroy_collided_plates(self):
        """
        Destroy collided object and increment score
        If no one object can be destroyed return False
        :return: bool
        """
        for index, object in enumerate(self.plates):
            if object.colliderect(self.ball.get_rect()):
                del self.plates[index]
                self.score += 10
                return True

        return False
Ejemplo n.º 8
0
N = 2**16
fs = 2**12
overlap = 50  # [%]
t = np.arange(0, N / fs, 1 / fs)
x = chirp(t, 20, N / fs - 1 / fs, 2000, phi=90)
x = np.append(x, np.zeros(fs))  # silece for tail of real live sound

y = sd.playrec(x, samplerate=fs, channels=1)
sd.wait()
y = np.reshape(y, len(y))
# averaging multiple signals
# pass  # for later on

# window + multi fft
Nw = fs
hannw = Window.Window(Nw)
(dummy, hann) = hannw.hanwind()

S_1 = np.sum(hann)
S_2 = np.sum(hann**2)
NENBW = Nw * S_2 / (S_1**2)
ENBW = fs * S_2 / (S_1**2)  # = NENBW * fs/N

print(NENBW, ENBW)

overlap = overlap / 100 * Nw
idxl = 0
idxu = Nw
Y = []
while idxu <= len(y):
    (F, Yd) = Transform.FFT(y[idxl:idxu] * hann, fs)