Example #1
0
def destination(place, file):
    thequestion=input("Welcome to {0}! You may: 1. Look around, 2. Attempt to Trade, 3. Stop to Rest, 4. See your health, 5. Review your items, 6. Go to the Store, 7. Continue on the hike".format(place))
    if thequestion is "1":
        picture=ImageAsset("images/" + file)
        picture_sprite=Sprite(picture, (0,0))
        myapp = App()
        myapp.run()
 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
    def test_enfoldingcollision(self):
        def step():
            s1.x += 1
            s2.x -= 1
            c = s1.collidingWith(s2)
            self.assertTrue(c, msg="big sprite colliding with embedded sprite")
            c = s2.collidingWith(s1)
            self.assertTrue(c,
                            msg="small sprite colliding with enfolding sprite")

        s1 = Sprite(self.rocket, (10, 10))
        s2 = Sprite(self.image, (15, 15))

        a = App()
        a.run(step)

        for i in range(10):
            a._animate(1)

        s1.destroy()
        s2.destroy()
Example #4
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 #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
    
    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 #7
0
# Three primary colors with no transparency (alpha = 1.0)
red = Color(0xff0000, 1.0)
green = Color(0x00ff00, 1.0)
blue = Color(0x0000ff, 1.0)
black = Color(0x000000, 1.0)
yellow = Color(0x999900, 1.0)

# Define a line style that is a thin (1 pixel) wide black line
thinline = LineStyle(1, black)
# A graphics asset that represents a rectangle

#Main square of the house
house = RectangleAsset(300, 300, thinline, blue)

#Roof
roof = PolygonAsset([(0, 100), (200, 0), (400, 100), (0, 100)], thinline, red)

#sun
sun = EllipseAsset(70, 70, thinline, yellow)

#ellipse = EllipseAsset (50, 20, thinline, blue)
#hexagon = PolygonAsset ([(0, 0), (200, 0), (250, 250), (0, 0)], thinline, red)

#Sprites
Sprite(house, (250, 250))
Sprite(roof, (200, 150))
Sprite(sun)

myapp = App()
myapp.run()
Example #8
0
        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 #9
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 #10
0
    mouseposition = (event.x, event.y)


def collidingWithSprites(blocko, block):
    if blocko is block:
        return False
    elif blocko._collisionStyle == block._collisionStyle == type(blocko)._circCollision:
        dist2 = (blocko.x - block.x)**2 + (blocko.y - block.y)**2
        return dist2 < (45)**2
    else:
        return (blocko.xmin > block.xmax
            or blocko.xmax < block.xmin
            or blocko.ymin > block.ymax
            or blocko.ymax < block.ymin)

myapp.run()    

#class KeyEvent(_Event):
global star, yum
star = 0
def mup(event):
    star = 2
    tt=16
def might(event):
    star = 3
def meft(event):
    star = 4
    

global t
global tt
Example #11
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()
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()
Example #13
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)
Example #14
0
car1 = RectangleAsset(120, 70, bl_line, Orange)
car2 = RectangleAsset(125, 60, bl_line, Lgreen)
wheel = CircleAsset(12, bl_line, black)
road = RectangleAsset(1200, 280, thinline, dkgr)
window = CircleAsset(10, thinline, clearsh)
stripe = RectangleAsset(990, 10, thinline, wit)
truck = RectangleAsset(210, 80, bl_line, purp)
trkfrt = PolygonAsset([(10, 0), (80, 0), (80, 90), (0, 91), (10, 0)], thinline,
                      brn)
bgwheels = CircleAsset(16, bl_line, medgr)
bgwinw = RectangleAsset(50, 55, thinline, clearsh)

Sprite(road, (15, 1))
Sprite(stripe, (117, 108))
my4app = App()
my4app.run()

import picture
picture.my2app.run()

Sprite(car1, (680, 40))
Sprite(car2, (820, 40))
Sprite(wheel, (700, 115))
Sprite(wheel, (780, 115))
Sprite(wheel, (840, 100))
Sprite(wheel, (920, 100))
Sprite(window, (700, 60))
Sprite(window, (740, 60))
Sprite(window, (780, 60))
Sprite(window, (840, 65))
Sprite(window, (882, 65))
Example #15
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 #16
0
        if number == len(colorlist)-1:
            stylecount = 0 

#EXTRA FUN:
#asset = CircleAsset(.5, thinline, black)
#lavender = Color(0xCF94F3, 1.0)
#print("new: ", xpen, ypen)
#print("old: ", oldxpen, oldypen)
#Sprite(asset, (xpen,ypen))
#print(App.width)
#print(App.height)
#go through once, then delete and add 2 shorter lines, again and again 
#55,23
#100, 60
#100,70
#44,12
#98,12
#89,49
#150, 47.6
#151,75
#198,40 rainbow, 0.075 

#PRESENTATION:
#150,68 rainbow, thin, 0.075
#180,46 special, thin, 0.075
#198,40 rainbow, thick, 0.2
#150, 34 (backup example)

myapp = App()
myapp.run(step)
Example #17
0
            elif neighbors[i][j] > 3:
                grid[i][j] = 0
            elif grid[i][j] != 0:
                grid[i][j] += 1
            elif neighbors[i][j] == 3:
                grid[i][j] += 1

    # Displays live cells
    displayCells()


# Get dimensions from user
# Width of grid
gridcolumns = int(input("How wide would you like the simulation to be? "))
# Height of grid
gridrows = int(input("How tall would you like the simulation to be? "))
# Start w/ random initial conditions or user determined?

# Grid[row][column]
grid = []
# Create random grid
for i in range(0, gridrows):
    grid.append([0] * gridcolumns)
    for j in range(0, gridcolumns):
        grid[i][j] = random.randint(0, 1)
        if grid[i][j] == 1:
            grid[i][j] = random.randint(1, 7)

myapp = App()
myapp.run(tick)
Example #18
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 #19
0
pale = Color(0xFFFACD, 0.4)

bl_line = LineStyle(3, black)
thinline = LineStyle(1, black)

brkhr = RectangleAsset(130, 32, bl_line, brn)
head = EllipseAsset(120, 100, bl_line, pale)
nose = PolygonAsset([(50, 60), (75, 40), (100, 60), (50, 60)], thinline, turqo)
eye = CircleAsset(20, thinline, Lgreen)
pupil = CircleAsset(8, thinline, purp)
mouth = PolygonAsset([(0, 0), (100, 0), (80, 20), (20, 20), (0, 0)], bl_line,
                     Orange)
hat = RectangleAsset(80, 20, thinline, turqo)
neck = EllipseAsset(60, 75, bl_line, pale)
arm = PolygonAsset([(30, 50), (125, 50), (145, 80), (30, 80)], thinline, brn)

Sprite(head, (150, 140))
Sprite(brkhr, (90, 10))
Sprite(nose, (75, 70))
Sprite(eye, (190, 80))
Sprite(eye, (110, 80))
Sprite(pupil, (190, 80))
Sprite(pupil, (110, 80))
Sprite(mouth, (100, 170))
Sprite(hat, (115, 15))
Sprite(neck, (150, 300))
Sprite(arm, (160, 180))

my2app = App()
my2app.run()
Example #20
0
from ggame import TextAsset, App, Sprite

a = App()
a.run()
Example #21
0
def map(file,scale):
    picture=ImageAsset("images/" + file)
    picture_sprite=Sprite(picture, (0,0))
    picture_sprite.scale = scale
    myapp = App()
    myapp.run()