def test_app(self):
     a3 = App(100, 100)
     # event handling
     a3.listenKeyEvent(KeyEvent.keydown, "space", self.spacehandler)
     a3.listenMouseEvent(MouseEvent.mousewheel, self.wheelhandler)
     key = keyevent('keydown', 32)
     a3._keyEvent(key)
     mouse = mouseevent('wheel', 1, 2, 99)
     a3._mouseEvent(mouse)
     # confirm no events after unlisten
     a3.unlistenKeyEvent(KeyEvent.keydown, "space", self.spacehandler)
     a3.unlistenMouseEvent(MouseEvent.mousewheel, self.wheelhandler)
     a3._keyEvent(key)
     a3._mouseEvent(mouse)
     # assert that each handler was executed only once
     self.assertEqual(self.keyevtx, 1)
     self.assertEqual(self.mouseevtx, 1)
     # run the app
     a3.run()
     # and destroy it
     a3._destroy()
Example #2
0
 def test_app(self):
   a3 = App(100,100)
   # event handling
   a3.listenKeyEvent(KeyEvent.keydown, "space", self.spacehandler)
   a3.listenMouseEvent(MouseEvent.mousewheel, self.wheelhandler)
   key = keyevent('keydown', 32)
   a3._keyEvent(key)
   mouse = mouseevent('wheel', 1, 2, 99)
   a3._mouseEvent(mouse)
   # confirm no events after unlisten
   a3.unlistenKeyEvent(KeyEvent.keydown, "space", self.spacehandler)
   a3.unlistenMouseEvent(MouseEvent.mousewheel, self.wheelhandler)
   a3._keyEvent(key)
   a3._mouseEvent(mouse)
   # assert that each handler was executed only once
   self.assertEqual(self.keyevtx, 1)
   self.assertEqual(self.mouseevtx, 1)
   # run the app
   a3.run()
   # and destroy it
   a3._destroy()
Example #3
0
    if ball.go:
        ball.x += ball.dir
        if ball.x + ball.width > SCREEN_WIDTH or ball.x < 0:
            ball.x -= ball.dir
            reverse(ball)
            
# Handle the space key
def spaceKey(event):
    ball.go = not ball.go
    pop.play()
    pew1.play()

# Handle the "reverse" key
def reverseKey(event):
    reverse(ball)
    pop.play()

# Handle the mouse click
def mouseClick(event):
    ball.x = event.x
    ball.y = event.y
    pew1.play()
    

myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)

myapp.listenKeyEvent('keydown', 'space', spaceKey)
myapp.listenKeyEvent('keydown', 'r', reverseKey)
myapp.listenMouseEvent('click', mouseClick)

myapp.run(step)
Example #4
0
        beach.x += beach.dir
        if beach.x + beach.width > SCREEN_WIDTH or beach.x < 0:
            beach.x -= beach.dir
            reverse(beach)


def spaceKey(event):
    ball.go = not ball.go


# Handle the "reverse" key
def reverseKey(event):
    reverse(ball)


# Handle the mouse click
def mouseClick(event):
    ball.x = event.x
    ball.y = event.y
    pew1.play()
    reverse(ball)


myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
# Set up event handlers for the app
myapp.listenKeyEvent("keydown", "space", spaceKey)
myapp.listenKeyEvent("keydown", "r", reverseKey)
myapp.listenMouseEvent("click", mouseClick)

myapp.run(step)
Example #5
0
# Set up function for handling screen refresh
def step():
    if ball.go:
        ball.x += ball.dir
        if ball.x + ball.width > SCREEN_WIDTH or ball.x < 0:
            ball.x -= ball.dir
            reverse(ball)

# Handle the space key
def spaceKey(event):
    ball.go = not ball.go

# Handle the "reverse" key
def reverseKey(event):
    reverse(ball)

# Handle the mouse click
def mouseClick(event):
    ball.x = event.x
    ball.y = event.y
    pew1.play()

myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
# Set up event handlers for the app
myapp.listenKeyEvent('keydown', 'space', spaceKey)
myapp.listenKeyEvent('keydown', 'r', reverseKey)
myapp.listenMouseEvent('click', mouseClick)

myapp.run(step)
Example #6
0

def Down(event):
    global screenoffset
    screenoffset = (screenoffset[0], screenoffset[1] + 1)
    Move()


def Move():
    global screenoffset
    for p, val in livecells.items():
        pphys = pfroml((p[0] + screenoffset[0], p[1] + screenoffset[1]))
        val[0].position = pphys
        val[1].position = pphys


App.listenMouseEvent('mousedown', MouseDown)
App.listenMouseEvent('mouseup', MouseUp)
App.listenMouseEvent('mousemove', MouseMove)
App.listenKeyEvent('keypress', 'space', Spacebar)
App.listenKeyEvent('keydown', 'left arrow', Left)
App.listenKeyEvent('keydown', 'right arrow', Right)
App.listenKeyEvent('keydown', 'up arrow', Up)
App.listenKeyEvent('keydown', 'down arrow', Down)

print("Press <space> to start and stop.")
print("Use mouse to set initial living cells.")
print("Use cursor keys to move the screen.")

myapp = App()
myapp.run(step)
Example #7
0
def downKey(event):
    spaceship.ygo = True
    spaceship.go = False
    spaceship.thrust = 1
    spaceship.rotation = 3.141592653589793238462643383
    down(spaceship)


def downUp(event):
    spaceship.go = False
    spaceship.ygo = False
    spaceship.thrust = 1
    down(spaceship)


def returnDown(event):
    tab(spaceship)


myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
myapp.listenKeyEvent('keydown', 'a', leftKey)
myapp.listenKeyEvent('keyup', 'a', leftUp)
myapp.listenKeyEvent('keydown', 'd', rightKey)
myapp.listenKeyEvent('keyup', 'd', rightUp)
myapp.listenKeyEvent('keydown', 'w', upKey)
myapp.listenKeyEvent('keyup', 'w', upUp)
myapp.listenKeyEvent('keydown', 's', downKey)
myapp.listenKeyEvent('keyup', 's', downUp)
myapp.listenKeyEvent('keydown', 'tab', returnDown)
myapp.run(step)
Example #8
0
    spaceship.ygo = True
    spaceship.go = False
    spaceship.thrust = 1
    spaceship.rotation = 0
    up(spaceship)


def downKey(event):
    spaceship.ygo = True
    spaceship.go = False
    spaceship.thrust = 1
    spaceship.rotation = 3.141592653589793238462643383
    down(spaceship)


# Handle the mouse click
def mouseClick(event):
    spaceship.x = event.x
    spaceship.y = event.y


myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
myapp.listenKeyEvent('keydown', 'space', spaceKey)
myapp.listenMouseEvent('click', mouseClick)
myapp.listenKeyEvent('keydown', 'a', leftKey)
myapp.listenKeyEvent('keydown', 'd', rightKey)
myapp.listenKeyEvent('keydown', 'w', upKey)
myapp.listenKeyEvent('keydown', 's', downKey)
#myapp.run(ystep)
myapp.run(astr)
Example #9
0
#Player 1
player = RectangleAsset(15, 100, blkline, black)
#PlayerLeft = Sprite(player, (0,101))

class Playerleft(Sprite):
    def __init__(self, x, y):
        self.vy = 0
        super().__init__(player, (x, y))
PlayerLeft = Playerleft(0, 101)
#----------------------------
global wkeyisdown
wkeyisdown = False
def wkey(event):
    global wkeyisdown
    wkeyisdown = True
myapp.listenKeyEvent('keydown', 'w', wkey)

def wkeyup(event):
    global wkeyisdown
    wkeyisdown = False
myapp.listenKeyEvent('keyup', 'w', wkeyup)

#--------------------------
global skeyisdown
skeyisdown = False
def skey(event):
    global skeyisdown
    skeyisdown = True
myapp.listenKeyEvent('keydown', 's', skey)

def skeyup(event):
Example #10
0
#Acts on actions lists to accomplish changes simultaneously
    for cell in birthcell:
        coord[cell] = 1
    for cell in agecell:
        coord[cell] = 2
    for cell in killcell:
        coord[cell] = 0
    display():

#Function called by mouse clicks to change cells manually
def change(info):
    x = int(info.x/10)
    y = int(info.y/10)
    if x >= mapsize or y >= mapsize or x <= 0 or y <= 0:
        return
    elif coord[(x,y)] == 0:
        coord[(x,y)] = 1
        Sprite(newcell,(x*10,y*10))
    else:
        coord[(x,y)] = 0
        Sprite(deadcell,(x*10,y*10))

display():

App.listenKeyEvent("keydown", "space", ticker)
App.listenMouseEvent("mousedown", change)

app = App()
app.run()
    
Example #11
0
            g=g+0.5
            blockoo.y = blockoo.y + 3 * g
"""           
            
            

myapp.run(steppp)            

        
myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)

myapp.run(step)


    
myapp.listenKeyEvent('keydown' , 'w' , w)
myapp.listenMouseEvent('mousemove', move)
myapp.listenKeyEvent('keydown' , 'p' , p)
myapp.listenKeyEvent('keydown' , 's' , s)
myapp.listenKeyEvent('keydown' , 'up arrow' , mup)
myapp.listenKeyEvent('keydown' , 'right arrow' , might)
myapp.listenKeyEvent('keydown' , 'left arrow' , meft)


"""
problems:

must stop player from sinking into the walls when falling
add spring ability to the springs
make the sides+bottom of the walls collide with the player rather than just the tops
Example #12
0
                if bungo.x >= collision[jum].x - 35 and bungo.x <= collision[
                        jum].x + 35:
                    if bungo.y >= collision[
                            jum].y - 35 and bungo.y <= collision[jum].y + 35:
                        bungo.x = posendtickx
                jum += 1
        if bungo.y >= 667:
            bungo.y = posendticky
            jump = 0
        if bungo.y <= 0:
            vertvel = 0
            bungo.y = posendticky
        if bungo.x >= 998 or bungo.x <= 0:
            bungo.x = posendtickx


#app stuff
for j in range(1):
    myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
    myapp.listenMouseEvent('click', mouseClick)
    myapp.listenKeyEvent('keydown', 'w', wallPlaceKey)
    myapp.listenKeyEvent('keydown', 'b', bungoKey)
    myapp.listenKeyEvent('keydown', 'j', jumpyKey)
    myapp.listenKeyEvent('keydown', 'up arrow', jumpgo)
    myapp.listenKeyEvent('keydown', 'left arrow', leftgo)
    myapp.listenKeyEvent('keydown', 'right arrow', rightgo)
    myapp.listenKeyEvent('keyup', 'right arrow', rightstop)
    myapp.listenKeyEvent('keyup', 'left arrow', leftstop)

    myapp.run(step)
Example #13
0
#            print("nextto: " + str(nextto))

            if nextto == 3 and (m, n) not in oldcells:
                #                print("should be" + str((m, n)))
                Cell1((m, n))
                newcells.append((m, n))
            elif (m, n) in oldcells:
                #                print("elif")
                if nextto == 2 or nextto == 3:
                    Cell2((m, n))
                    oldcells.append((m, n))
                else:
                    #                    print("else")
                    #                    Cell0((m, n))
                    topop.append((m, n))
            else:
                #                print("c0 at" + str((m, n)))
                Cell0((m, n))
        for (m, n) in topop:
            oldcells.remove((m, n))
            Cell0((m, n))


#            print("nextto: " + str(nextto))

myapp.run(step)
myapp.listenMouseEvent('mousedown', mousedown)
myapp.listenMouseEvent('mouseup', mouseup)
myapp.listenMouseEvent('mousemove', mousemove)
myapp.listenKeyEvent('keydown', 'space', pauseplay)
Example #14
0
    return l1


def spaceKey(event):
    global lifelist
    lifelist = conway(lifelist)


def click(event):
    mcx = int(event.x)
    mcy = int(event.y)
    acx = int(mcx / pixelsize)
    acy = int(mcy / pixelsize)
    if acx < 0 or acy < 0 or acx > xsize or acy > ysize:
        return
    place = [acx, acy]
    place2 = l2.index(place)
    pixel = lifelist[place2]
    if pixel == "none":
        lifelist[place2] = "life1"
    if pixel == "life1" or pixel == "life2":
        lifelist[place2] = "none"
    printing(lifelist)


printing(lifelist)

myapp = App()
step = myapp.listenKeyEvent('keydown', 'space', spaceKey)
clickity = myapp.listenMouseEvent('click', click)
myapp.run(step)
Example #15
0
            ace = 1
        elif o == AD:
            yourscore += 1
            ace = 1
        else:
            yourscore += 10
        if yourscore > 21.5:
            print("You busted")
            t = 3
            yb = 5
            allowbet = 1
            money = int(money) - int(bet)
            print("You have $" + str(money))
            print("Press space to start another round")
            bet = 0
            m = 2
            n = 2
    #changing you score


#Note: This game is for educational use only

myapp = App()
app = App(500, 500)
app.run(step)
myapp.listenKeyEvent('keydown', 'space', pauseplay)
myapp.listenKeyEvent('keydown', 's', stay)
myapp.listenKeyEvent('keydown', 'enter', begin)
myapp.listenKeyEvent('keydown', 'h', hit)
myapp.listenKeyEvent('keydown', 'b', betting)
myapp.listenKeyEvent('keydown', 'r', rules)