def play_game(clock, mf, mouth, bugs, event_handler):

    sound_eat = pygame.mixer.Sound('eat.wav')

    for _ in range(DEMO_LOOPS):

        for event in pygame.event.get():
            if event_handler:
                ret = event_handler(event)
                if ret:
                    return ret

        # Object for this frame
        nf = Frame(mf)

        # Draw the bugs as dots
        for bug in bugs:
            nf.set_pixel(bug.x, bug.y, GR.COLOR_BUG_AS_DOT)

        # Magnify the maze and bugs
        nf = MAG.draw_magnifier(nf, mouth.x - 8, mouth.y - 8, 17)

        # Draw any bugs appearing on the magnifier (not just dots)
        MAG.draw_bugs_on_magnifier(nf, mouth.x - 8, mouth.y - 8, 17, bugs)

        # Draw the mouth and check for bug collision
        hit_bug = MAG.draw_mouth_on_magnifier(nf, mouth)
        hit_bug = False

        # Render the frame
        hardware.render_frame(nf)

        if hit_bug:
            return "Mode: Splash"

        clock.tick(10)

        if mf.get_pixel(mouth.x, mouth.y) == GR.COLOR_DOT:
            sound_eat.play()

        # Leave a crumb (also erases the dot)
        if mouth.animation == 0:
            mf.set_pixel(mouth.x, mouth.y, GR.COLOR_CRUMB)

        # Erase crumbs taken by bugs
        for bug in bugs:
            if mf.get_pixel(bug.x, bug.y) == GR.COLOR_CRUMB:
                mf.set_pixel(bug.x, bug.y, 0)
            bug.move(mf)

        # Move the mouth
        mouth.move(mf, None, None)

    return "Mode: Splash"
示例#2
0
def wipe_in(fin):
    #print('wipe in')
    nf = Frame(hardware.last_rendered_frame)

    for x in range(1, 64, 2):
        for y in range(96):
            nf.set_pixel(x, y, fin.get_pixel(x, y))
            nf.set_pixel(x - 1, y, fin.get_pixel(x - 1, y))
            nf.set_pixel(127 - x, y, fin.get_pixel(127 - x, y))
            nf.set_pixel(127 - x + 1, y, fin.get_pixel(127 - x + 1, y))
            if x != 63:
                nf.set_pixel(x + 1, y, GR.COLOR_LENS_BORDER)
                nf.set_pixel(127 - x - 1, y, GR.COLOR_LENS_BORDER)
        hardware.render_frame(nf)
def handle(clock):
    #print('Mode: Lose')

    last_maze_frame = hardware.last_rendered_frame

    SONG_END = pygame.USEREVENT + 1
    pygame.mixer.music.set_endevent(SONG_END)
    pygame.mixer.music.load('gotcha.wav')
    pygame.mixer.music.play()

    bugimage = GR.BIG_BUG
    animation = 0

    playing = True
    while playing:
        for event in pygame.event.get():
            #print(event)
            if event.type == 25:
                playing = False

        #print(bugimage['dancing'])

        last_maze_frame.draw_image(3, 32, bugimage['dancing'][animation])
        last_maze_frame.draw_image(108, 32, bugimage['dancing'][animation])

        hardware.render_frame(last_maze_frame)

        animation += 1
        animation &= 1

        clock.tick(4)

    for _ in range(8):
        last_maze_frame.draw_image(3, 32, bugimage['dancing'][animation])
        last_maze_frame.draw_image(108, 32, bugimage['dancing'][animation])
        hardware.render_frame(last_maze_frame)
        animation += 1
        animation &= 1
        clock.tick(4)

    clock.tick(1)
    return "Mode: Splash"
示例#4
0
def wipe_out(fin):
    nf = Frame(hardware.last_rendered_frame)

    #src = fin._pixels
    #dst = nf._pixels
    for x in range(1, 64, 2):
        #a = 63-x
        #b = 64+x
        for y in range(96):
            #dst[y*128+a] = src[y*128+a]
            #dst[y*128+b] = src[y*128+b]
            nf.set_pixel(63 - x, y, fin.get_pixel(63 - x, y))
            nf.set_pixel(63 - x + 1, y, fin.get_pixel(63 - x + 1, y))
            nf.set_pixel(64 + x, y, fin.get_pixel(64 + x, y))
            nf.set_pixel(64 + x - 1, y, fin.get_pixel(64 + x - 1, y))
            if x != 63:
                #dst[y*128+a-1] = GR.COLOR_LENS_BORDER
                #dst[y*128+b+1] = GR.COLOR_LENS_BORDER
                nf.set_pixel(63 - x - 1, y, GR.COLOR_LENS_BORDER)
                nf.set_pixel(64 + x + 1, y, GR.COLOR_LENS_BORDER)
        hardware.render_frame(nf)
示例#5
0
def handle(clock):
    #print('Mode: Win')

    mf = hardware.last_rendered_frame

    sound_step = pygame.mixer.Sound('step.wav')

    colors = [
        GR.COLORS_SPLASH_TEXT, GR.COLORS_SPLASH_TEXT + 1,
        GR.COLORS_SPLASH_TEXT + 2, GR.COLORS_SPLASH_TEXT + 3
    ]

    sc = 0
    og = GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL]
    for i in range(8):
        GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL] = GR.COLOR_PALETTE[colors[sc]]
        sc += 1
        if sc >= len(colors):
            sc = 0
        hardware.render_frame(mf)
        clock.tick(4)
    GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL] = og

    pic = Frame()

    text.draw_text(pic, 0x1E, 0x1B, "We'll Getcha",
                   [GR.COLORS_SPLASH_TEXT + 1])
    text.draw_text(pic, 0x27, 0x28, "Next Time", [GR.COLORS_SPLASH_TEXT + 2])

    acc = Frame()

    seg = 0
    y = 0
    animation = 0

    while True:

        for _ in pygame.event.get():
            pass

        if seg == 0:

            if y > 0:
                for x in range(128):
                    acc.set_pixel(x, y - 2, pic.get_pixel(x, y - 2))
                    acc.set_pixel(x, y - 1, pic.get_pixel(x, y - 1))
            nf = Frame(acc)

            sound_step.play(0)
            for i in range(32):
                nf.draw_image(0 + i * 8, y, GR.LITTLE_BUG[2][animation])
            animation += 1
            animation &= 1
            y = y + 2
            if y > 96:
                seg = 1
                text.draw_text(pic, 0x5D, 0x28, "!",
                               [GR.COLORS_SPLASH_TEXT + 3])
                y = 0
                hardware.render_frame(acc)
                clock.tick(1)

            hardware.render_frame(nf)

            clock.tick(10)

        elif seg == 1:

            if y > 0:
                for x in range(128):
                    acc.set_pixel(x, y - 4, pic.get_pixel(x, y - 4))
                    acc.set_pixel(x, y - 3, pic.get_pixel(x, y - 3))
                    acc.set_pixel(x, y - 2, pic.get_pixel(x, y - 2))
                    acc.set_pixel(x, y - 1, pic.get_pixel(x, y - 1))
            nf = Frame(acc)

            sound_step.play(0)
            nf.draw_image(92, y, GR.LITTLE_BUG[2][animation])
            animation += 1
            animation &= 1
            y = y + 4
            if y > 96:
                seg = 3

            hardware.render_frame(nf)

            clock.tick(15)

        else:
            clock.tick(1)
            return "Mode: Game"
def handle(clock, event_handler):
    #print('Mode: Demo')

    # Make the bugs (not too close to center)
    bugs = []
    for _ in range(16):
        while True:
            cx = random.randint(0, 19)
            cy = random.randint(0, 15)
            if (cx >= 6 and cx < 14) and (cy >= 6 and cy < 14):
                continue
            break
        bugs.append(Bug(cx * 4 + 25, cy * 4 + 17, random.randint(0, 3)))

    pic = Frame()

    # Draw the bugs
    mega = Maze(20, 16, 192)
    mode_game.draw_maze(mega._maze, pic)

    # Draw the big bugs
    bugimage = GR.BIG_BUG
    pic.draw_image(3, 32, bugimage['standing'])
    pic.draw_image(108, 32, bugimage['standing'])

    # The mouth
    mouth = Mouth(25 + 10 * 4, 17 + 8 * 4, random.randint(0, 3))

    # Don't start on a dot
    pic.set_pixel(mouth.x, mouth.y, 0)

    hs = str(mode_game.HIGH_SCORE).rjust(4, '0')
    text.draw_text(pic, 19, 4, 'High Score ' + hs, GR.COLOR_SCORE)
    text.draw_text(pic, 26, 84, 'Play Giga-Bug', GR.COLOR_SCORE)

    transitions.wipe_in(pic)
    """
    base_frame = Frame()
    
    base_frame.draw_image(10,15, GR.CHARS['A']) # The letter 'A'
    base_frame.draw_text(5,5,    GR.CHARS,'Demonstration')
    base_frame.draw_image(20,25, GR.BIG_BUG['standing']) # Bug standing
    base_frame.draw_image(50,25, GR.BIG_BUG['dancing'][0]) # Bug dancing ...
    base_frame.draw_image(70,25, GR.BIG_BUG['dancing'][1]) # ... two animations   
    
    direction = 1 # 0=UP, 1=RIGHT, 2=DOWN, 3=LEFT
    animation = 0 # 0 or 1 ... two animations
    
    while True:
        frame = Frame(base_frame)        
             
        frame.draw_image(10,60, GR.MOUTH[direction][animation])
            
        hardware.render_frame(frame)
        
        animation = (animation + 1) % 2
    
        time.sleep(0.25)  
    """

    clock.tick(0.75)
    nf = MAG.draw_magnifier(pic, mouth.x - 8, mouth.y - 8, 17)
    MAG.draw_mouth_on_magnifier(nf, mouth)
    hardware.render_frame(nf)
    clock.tick(0.75)

    # Play this setup
    return play_game(clock, pic, mouth, bugs, event_handler)
示例#7
0
def handle(clock, event_handler):

    #print('Mode: Splash')
    hardware.set_colors(GR.COLOR_PALETTE)

    pic = Frame()

    color_start1 = 0
    color_start2 = 1
    color_start3 = 2

    colors = [
        GR.COLORS_SPLASH_TEXT, GR.COLORS_SPLASH_TEXT + 1,
        GR.COLORS_SPLASH_TEXT + 2, GR.COLORS_SPLASH_TEXT + 3
    ]

    text.draw_text(pic, 22, 14, 'Bob Bishop', GR.COLOR_CRUMB)
    text.draw_text(pic, 22, 34, 'Steve Bjork', GR.COLOR_CRUMB)
    text.draw_text(pic, 22, 44, 'Datasoft 1982', GR.COLOR_CRUMB)
    text.draw_text(pic, 22, 74, 'Chris Cantrell', colors[1])

    text.draw_text(pic, 10, 4, 'DUNG BEETLES', colors, color_start1)
    text.draw_text(pic, 10, 24, 'Mega-Bug', colors, color_start2)
    text.draw_text(pic, 10, 64, 'Giga-Bug', colors, color_start3)

    transitions.wipe_out(pic)

    SONG_END = pygame.USEREVENT + 1
    pygame.mixer.music.set_endevent(SONG_END)
    pygame.mixer.music.load('splash.wav')
    pygame.mixer.music.play()

    while True:

        for event in pygame.event.get():
            if event.type == 25:
                return "Mode: Demo"
            if event_handler:
                ret = event_handler(event)
                if ret:
                    pygame.mixer.music.stop()
                    return ret

        nf = Frame(pic)

        text.draw_text(nf, 10, 4, 'DUNG BEETLES', colors, color_start1)
        text.draw_text(nf, 10, 24, 'Mega-Bug', colors, color_start2)
        text.draw_text(nf, 10, 64, 'Giga-Bug', colors, color_start3)

        color_start1 += 1
        if color_start1 >= 4:
            color_start1 = 0
        color_start2 += 1
        if color_start2 >= 4:
            color_start2 = 0
        color_start3 += 1
        if color_start3 >= 4:
            color_start3 = 0

        hardware.render_frame(nf)

        clock.tick(10)
示例#8
0
xxx,yyy ... xxx,yyy    xxx,yyy ... xxx,yyy

255,031 ... xxx,yyy    192,031 ... xxx,yyy
|                 |    |                 |
xxx,yyy ..< 192,000    191,000 ..< 128,000

000,000 >.. 063,000    064,000 >.. 128,000
|                 |    |                 |
000,031 ... 063,031    064,031 ... 128,031

"""


def draw_shape(fr, x, y):
    for i in range(8):
        fr.set_pixel(x + i, y, 4)
        fr.set_pixel(x, y + i, 4)
        fr.set_pixel(x + 1, y + 1, 1)
        fr.set_pixel(x + 2, y + 2, 2)
        fr.set_pixel(x + 3, y + 3, 3)


fr = Frame()

draw_shape(fr, 0, 0)

hardware.render_frame(fr)

print('sleeping')
time.sleep(10)