Example #1
0
roof2 = PolygonAsset ([(400, 300), (400, 175), (680, 300)],  thinline, green)
Sprite(roof2)

windowellipse = EllipseAsset (75, 30, thinline, aqua)
Sprite(windowellipse, (250, 250))

windowline = PolygonAsset ([(175, 251), (175, 250), (325, 251), (325, 250)], thinline, black)
Sprite(windowline)

windowline2 = PolygonAsset ([(200, 225), (201, 225), (200, 275), (201, 275)], thinline, black)
Sprite(windowline2)

windowline3 = PolygonAsset ([(249, 200), (250, 200), (249, 300), (250, 300)], thinline, black)
Sprite(windowline3)

windowline4 = PolygonAsset ([(299, 200), (300, 200), (299, 300), (300, 300)], thinline, black)
Sprite(windowline4)







# add your code here /\  /\  /\



myapp = App()
myapp.run()
Example #2
0
from ggame import TextAsset, App, Sprite

a = App()
a.run()
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
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()
Example #5
0
"""
Trivial example of a minimal ggame App with Sprite.
"""
from ggame import App, ImageAsset, Sprite

# Create a displayed object at 100,100 using an image asset
Sprite(ImageAsset("bunny.png"), (100, 100))
# Create the app, with a default stage
APP = App()
# Run the app
APP.run()
Example #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)
Example #7
0
    
    def countneighbors(self, addr):
        count = 0
        for naddr in self.neighboraddresses(addr):
            count += self.population(naddr)
        return count

    def birthnew(self, nextgen, addr):
        if addr not in self.livingcells:
            if self.countneighbors(addr) == 3:
                nextgen[addr] = 0

    def step(self):
        nextgen = {}
        for addr in self.livingcells:
            n = self.countneighbors(addr)
            if n in (2, 3):
                nextgen[addr] = self.livingcells[addr]+1
            for naddr in self.neighboraddresses(addr):
                self.birthnew(nextgen, naddr)
        for s in self.getSpritesbyClass(Cell):
            s.visible = False
            s.destroy()
        self.livingcells = nextgen
        for c in self.livingcells:
            isnew = self.livingcells[c] == 0
            Cell(isnew, (c[0]*CELLDIAMETER, c[1]*CELLDIAMETER))

App = ConwayGame()
App.run()
Example #8
0
youwin = TextAsset("Congrats, you win!!")
youlose = TextAsset("Sorry, but you lose :(")
for s in secondslist:
    s.visible = False
for s in blocklist:
    s.visible = False
blocklist[0].visible = True

wintext = Sprite(youwin, (0, 0))
wintext.visible = False
losetext = Sprite(youlose, (0, 365))
losetext.visible = False
blockcount = 0

#Mouse clicks
def mouseClick(event):
    global blockcount
    if gameend == False:
        if blockcount >= len(blocklist):
            return
        if event.x >= blocklist[blockcount].x and event.y >= blocklist[blockcount].y and event.x <= blocklist[blockcount].x + 50 and event.y <= blocklist[blockcount].y + 50:
            if event.x >= rect11.x and event.y >= rect11.y and event.x <= rect11.x + 50 and event.y <= rect11.y + 50:
                wintext.visible = True
            #blocklist[blockcount].visible = False
            blockcount = blockcount + 1
            blocklist[blockcount].visible = True
        
myapp = App()
myapp.listenMouseEvent('click', mouseClick)
myapp.run(step)
Example #9
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

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

# Handle the mouse click
def mouseClick(event):
    ball.x = event.x
    ball.y = event.y
    
myapp.listenKeyEvent('keydown', 'space', spaceKey)
myapp.listenKeyEvent('keydown', 'r', reverseKey)
myapp.listenMouseEvent('click', mouseClick)

pew1_asset = SoundAsset("sounds/pew1.mp3")
pew1 = Sound(pew1_asset)
pop_asset = SoundAsset("sounds/reappear.mp3")
pop = Sound(pop_asset)

myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
myapp.run(step)
Example #10
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()
from ggame import App, ImageAsset, Sprite

# Create a displayed object using an image asset
Sprite(ImageAsset("ggame/bunny.png"), (100,100))
# Create the app, with a 500x500 pixel stage
app = App(500,500)  
# Run the app
app.run()