Ejemplo n.º 1
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()
Ejemplo n.º 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()
Ejemplo n.º 3
0
 def __init__(self, position):
     super().__init__(Bunny.asset, position)
     # register mouse events
     App.listenMouseEvent(MouseEvent.mousedown, self.mousedown)
     App.listenMouseEvent(MouseEvent.mouseup, self.mouseup)
     App.listenMouseEvent(MouseEvent.mousemove, self.mousemove)
     self.dragging = False
     self.deltax = self.deltay = 0
Ejemplo n.º 4
0
from ggame import App, RectangleAsset, ImageAsset, SoundAsset
from ggame import LineStyle, Color, Sprite, Sound

rectangle dimensions:1728 862

# A ball! This is already in the ggame-tutorials repository
ball_asset = ImageAsset("images/orb-150545_640.png")
ball = Sprite(ball_asset, (0, 0))
ball.fxcenter = 0.7
ball.fycenter = 0.6
# Original image is too big. Scale it to 1/10 its original size
ball.scale = 0.05
    
#Handle the mouse movement
def mouseMove(event):
    ball.x = event.x
    ball.y = event.y

myapp = App()
myapp.listenMouseEvent('mousemove', mouseMove)
myapp.run()
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
                        Sprite (circle, ((20*x+950), yval))
            goforh = 0
            while goforh <= len(xlistpts)-1:
                Sprite(circlebig, (20*float(xlistpts[goforh])+950, -20*float(ylistpts[goforh])+500))
                goforh += 1
            goforlist = 1
            while goforlist <= len(xlistpts)-1:
                pointz = TextAsset("("+str(xlistpts[goforlist-1])+","+str(ylistpts[goforlist-1])+"), ("+str(xlistpts[goforlist])+","+str(ylistpts[goforlist])+")", style = '8pt Arial')
                goforlist+=2
                Sprite (pointz, (10, pointpos*15))
                pointpos+=1
    if linetype in ['a', 'b', 'c', 'd', 'e', 's', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'q', 'r', 't', 'u', 'v', 'w', 'x', 'y', 'z']:
        Sprite (esetreg, (200, 200))
def mousePosition(event):
    global text
    global coords
    if coords != None:
        coords.destroy()
    xcurse.y = event.y-7
    ycurse.x = event.x-9
    text = TextAsset("(" + str(round((event.x-959)/20)) + "," + str(round((-(event.y-507))/20)) + ")", style = '10pt Arial')
    coords = Sprite(text, (event.x-7, event.y-22))
def mouseclick(event):
    Sprite (smiley, (100, 100))
    

myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
myapp.run()
myapp.listenMouseEvent('mousemove', mousePosition)
myapp.listenMouseEvent('mouseclick', mouseclick)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 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()
    
Ejemplo n.º 11
0
            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

is it different if it is a list?
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)