コード例 #1
0
ファイル: life.py プロジェクト: BrythonServer/Conway-Life

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)
コード例 #2
0
ファイル: sierpinsky.py プロジェクト: tiggerntatie/sierpinsky
# Sierpinsky demo
from ggame import CircleAsset, Sprite, App, Color, LineStyle

GASKET_SIZE = 64
black = Color(0x000000, 1.0)
thinline = LineStyle(1, black)
asset = CircleAsset(0.25, thinline, black)

# Draw a Sierpinsky Gasket of width and height d,
# with upper left at (x, y).
def draw_sierpinsky(x, y, d):
    if d <= 1:
        Sprite(asset, (x, y))                 # base case
    else:
        # recurse on upper left quadrant
        draw_sierpinsky(x, y, d/2)
        # recurse on upper right quadrant
        draw_sierpinsky(x + d/2, y, d/2)
        # recurse on lower right quadrant
        draw_sierpinsky(x + d/2, y + d/2, d/2)

draw_sierpinsky(0, 0, GASKET_SIZE)

App().run()
コード例 #3
0
ファイル: conway.py プロジェクト: tiggerntatie/Conway-Life
    
    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()
コード例 #4
0
ファイル: project.py プロジェクト: eddie-jeon/empty-app
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)
コード例 #5
0
brn = Color(0x5C3317, 0.9)
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()
コード例 #6
0
ファイル: picture.py プロジェクト: nilskingston/Picture
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()
コード例 #7
0
ファイル: conway2.py プロジェクト: sth23/Conway-Life
            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)
コード例 #8
0
"""
"""
You may use code supplied in the graphics tutorials as a starting point.
Live cells in your program may be represented as rectangles, circles, or any other shape that you would like to use. The example in the video above uses small circles.
The initial state of live cells may be preset or randomized by you, but it must be possible to start the game with a blank screen.
As the Wikipedia article described, your "playing area" may have fixed boundaries, boundaries that wrap around top and bottom, or may be entirely unbounded (in some ways, the easiest approach!).
The user must be able to "turn on" cells by clicking on them with the mouse, or by click-dragging across the window.
If your playing area is unbounded, then the up/down/right/left cursor keys should allow the user to scroll the playing area within the window.
Your live cells should be two different colors: one for its first day of “life”, the second for all subsequent days.
"""
print("click and drag to add a cell. Old cells are blue, new cells are red.")
from ggame import App, Color, LineStyle, Sprite
from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset

o = 0
myapp = App()
go = False
#colors
invis = Color(0xffffff, 1)
red = Color(0xff0000, 1.0)
green = Color(0x00ff00, 1.0)
blue = Color(0x0000ff, 1.0)
black = Color(0x000000, 1.0)

width = myapp.width
height = myapp.height
#list of coords of cells

newcells = []
oldcells = []
コード例 #9
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('dummy')
コード例 #10
0
ファイル: app_test.py プロジェクト: averywallis/Spacewar
 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()
コード例 #11
0
ファイル: sinecosine.py プロジェクト: jaEimele24/Sine-Cosine
See:
https://github.com/HHS-IntroProgramming/Sine-Cosine/blob/master/README.md
for a detailed list of requirements for this assignment.

https://github.com/HHS-IntroProgramming/Standards-and-Syllabus/wiki/Displaying-Graphics
for general information on how to use ggame.

https://github.com/HHS-IntroProgramming/Standards-and-Syllabus/wiki/Programmed-Graphics
for general information on using list comprehensions to generate graphics.

http://brythonserver.github.io/ggame/
for detailed information on ggame.
"""
from ggame import App, Color, LineStyle, Sprite, CircleAsset
from math import sin, cos, radians
app = App()
app.run()
xcoords = [x for x in range(0, 360, 10)]
x = list(range(0, 360, 10))
red = Color(0xff0000, 1.0)
blue = Color(0x0000ff, 1.0)
print('Its Purple If I Say it is!')
purple = Color(0x000000, 1.0)
#Blue Circles
x = list(range(0, 360, 10))
#y = 100+100**sin(radians(x))
myline = LineStyle(1, blue)
Mycircle = CircleAsset(5, myline, blue)
sprites = [Sprite(Mycircle, (x, 100 + 100 * sin(radians(x)))) for x in xcoords]
#Red Circles
Myline2 = LineStyle(1, red)
コード例 #12
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)
コード例 #13
0
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()
コード例 #14
0
from ggame import App, RectangleAsset, ImageAsset, Sprite, LineStyle, Color, Frame, CircleAsset
PrettyColors={'Green':'0x00ff00', 'Red':'0xff000', 'Blue':'0x0000ff'}
class Circle(App):
    def __init__(self, radius):
         super().__init__(radius)
    radius=int(input("Radius?"))
    black=Color(0,1)
    red=Color(0xA62A2A)
    ogline=Linestyle(1, black)
    Circle_Asset=CircleAsset(radius, ogline, red)
    Circle=Sprite(Circle_Asset, (100,100))
        
myapp = App(Circle)
myapp.run()
コード例 #15
0
ファイル: tutorial1.py プロジェクト: megsnyder/Tutorials
from ggame import App, Color, LineStyle, Sprite
from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset

# 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)

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

# Now display a rectangle
Sprite(rectangle)

myapp = App()
コード例 #16
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()
コード例 #17
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)
コード例 #18
0
from ggame import App, RectangleAsset, ImageAsset, SoundAsset
from ggame import LineStyle, Color, Sprite, Sound

myapp = App()

# define colors and line style
green = Color(0x00ff00, 1)
black = Color(0, 1)
noline = LineStyle(0, black)
# a rectangle asset and sprite to use as background
bg_asset = RectangleAsset(myapp.width, myapp.height, noline, green)
bg = Sprite(bg_asset, (0, 0))

# A ball! This is already in the ggame-tutorials repository
ball_asset = ImageAsset("images/orb-150545_640.png")
ball = Sprite(ball_asset, (0, 0))
# Original image is too big. Scale it to 1/10 its original size
ball.scale = 0.1
# custom attributes
ball.direction = 1
ball.go = True


# reverse - change the ball direction
def reverse(b):
    b.direction *= -1


# Set up function for handling screen refresh
def step():
    if ball.go:
コード例 #19
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)
コード例 #20
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)
コード例 #21
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


# 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)
コード例 #22
0
ファイル: picture.py プロジェクト: NedrowNomae/Picture
thickgreen = LineStyle(7, green)
thinwhite = LineStyle(1, white)
thingreen = LineStyle(1, green)
ground = RectangleAsset(500, 20, thinline, brown)
Sprite((ground), (0, 220))
pipe1 = RectangleAsset(30, 50, thingreen, green)
Sprite((pipe1), (350, 180))
pipe2 = EllipseAsset(25, 10, thickgreen, black)
Sprite((pipe2), (337.5, 170))
block = RectangleAsset(15, 15, thinline, brown)
Sprite((block), (200, 100))
Sprite((block), (230, 100))
Sprite((block), (215, 100))
goomba = PolygonAsset([(0, 0), (10, -15), (20, 0), (0, 0)], thinbrown, brown)
Sprite((goomba), (215, 75))
geyes = CircleAsset(1, thinwhite, black)
Sprite((geyes), (222.5, 80))
Sprite((geyes), (226.5, 80))
gleg = RectangleAsset(1, 10, thinline, black)
Sprite((gleg), (222.5, 90))
Sprite((gleg), (227.5, 90))
#its ugly but its supposed to be a goomba, mario and a pipe
# add your code here \/  \/  \/
#no

Sprite(ImageAsset("Small-mariogood5.png"), (100, 200))
app = App(500, 500)
app.run()

# add your code here /\  /\  /\
コード例 #23
0
window = RectangleAsset(25, 50, thinline, black)

knob = CircleAsset(5, thinline, khaki)

Sprite(sky, (0, 0))

Sprite(sun, (50, 50))

Sprite(grass, (0, 500))

Sprite(house, (500, 200))

Sprite(chim, (725, 75))

Sprite(roof, (450, 100))

Sprite(pond, (850, 525))

Sprite(door, (600, 325))

Sprite(window, (620, 350))

Sprite(window, (655, 350))

Sprite(knob, (680, 425))

myapp = App()
myapp.width = 1600
myapp.height = 900
myapp.run()
コード例 #24
0
 def collidingWithSprites(sun, sclass=None):
     if sclass is None:
         slist = App.spritelist
     else:
         slist = App.getSpritesbyClass(sclass)
     return list(filter(self.collidingWith, slist))
コード例 #25
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)
コード例 #26
0
"""
platformer.py
Author: Emma Supattapone
Credit: Abby Feyrer, Mr. Dennison
Assignment:
Write and submit a program that implements the sandbox platformer game:
https://github.com/HHS-IntroProgramming/Platformer
"""

from ggame import App
myapp = App()

SCREEN_WIDTH = 600
SCREEN_HEIGHT = 400
from ggame import App, Color, LineStyle, Sprite, Frame
from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset


red = Color(0xff0000, 1.0)
green = Color(0x00ff00, 1.0)
blue = Color(0x0000ff, 1.0)
black = Color(0x000000, 1.0)
white = Color(0xffffff, 1.0)
orange = Color(0xffa500,1.0)
purple = Color(0xa020f0,1.0)
thinline = LineStyle(1, black)
notthinline = LineStyle(3, green)
mouseposition = (0, 0)
yum=0

コード例 #27
0
from ggame import App, RectangleAsset, ImageAsset, SoundAsset
from ggame import LineStyle, Color, Sprite, Sound

myapp = App()

# define colors and line style
green = Color(0x00ff00, 1)
black = Color(0, 1)
noline = LineStyle(0, black)
# a rectangle asset and sprite to use as background
bg_asset = RectangleAsset(myapp.width, myapp.height, noline, green)
bg = Sprite(bg_asset, (0, 0))

# A ball! This is already in the ggame-tutorials repository
ball_asset = ImageAsset("images/orb-150545_640.png")
ball = Sprite(ball_asset, (0, 0))
# Original image is too big. Scale it to 1/10 its original size
ball.scale = 0.1
# custom attributes
ball.direction = 1
ball.go = True

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


def reverse(b):
    b.direction *= -1
コード例 #28
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()
    
コード例 #29
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()
コード例 #30
0
ファイル: Pong.py プロジェクト: daleyhacker/Final-Project
"""
Patrick Daley
"""

from ggame import App, Color, LineStyle, Sprite, TextAsset
from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset, ImageAsset, Frame
from math import floor
myapp = App(1017,512)

blue = Color(0x2EFEC8, 1.0)
black = Color(0x000000, 1.0)
pink = Color(0xFF00FF, 1.0)
red = Color(0xFF5733, 1.0)
white = Color(0xFFFFFF, 1.0)
red = Color(0xff0000, 1.0)
green = Color(0x00ff00, 1.0)
blue = Color(0x0000ff, 1.0)
black = Color(0x000000, 1.0)
white = Color(0xffffff, 1.0)
grey = Color(0xC0C0C0, 1.0)

thinline = LineStyle(2, black)
blkline = LineStyle(1, black)
noline = LineStyle(0, white)
coolline = LineStyle(1, grey)
blueline = LineStyle(2, blue)
redline = LineStyle(1, red)
greenline = LineStyle(1, green)
gridline = LineStyle(1, grey)
grid=RectangleAsset(30,30,gridline,white)
コード例 #31
0
ファイル: picture.py プロジェクト: glenpassow/Picture
rectangle = RectangleAsset(500, 600, thinline, blue)
circle = CircleAsset(50, thinline, red)
ellipse = EllipseAsset(60, 100, thinline, red)
triangle = PolygonAsset([(50, 50), (100, 200), (0, 80)], thinline, green)
rectangle2 = RectangleAsset(100, 100, thinline, blue)
circle2 = CircleAsset(250, thinline, black)
rectangle3 = RectangleAsset(50, 600, thinline, red)
ellipse2 = EllipseAsset(300, 100, thinline, green)
triangle2 = PolygonAsset([(50, 50), (100, 200), (500, 80)], thinline, red)
triangle3 = PolygonAsset([(89, 500), (300, 200), (0, 80)], thinline, blue)
triangle4 = PolygonAsset([(300, 100), (100, 260), (0, 80)], thinline, green)

#display the shapes
Sprite(rectangle, (600, 50))
Sprite(circle2, (900, 150))
Sprite(circle, (900, 150))
Sprite(ellipse, (400, 400))
Sprite(triangle, (500, 600))
Sprite(rectangle2, (200, 50))
Sprite(rectangle3, (500, 50))
Sprite(ellipse2, (400, 0))
Sprite(triangle2, (300, 400))
Sprite(triangle3, (100, 450))
Sprite(triangle4, (345, 90))

# add your code here /\  /\  /\

myapp = App()
myapp.run()
コード例 #32
0
from ggame import App, RectangleAsset, ImageAsset, Sprite, LineStyle, Color, Frame

SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480

# Background
black = Color(0, 1)
noline = LineStyle(0, black)
bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, black)
bg = Sprite(bg_asset, (0,0))

class SpaceGame(App):
    """
    Tutorial4 space game example.
    """
    def __init__(self, width, height):
        super().__init__(width, height)
myapp = App(SCREEN_WIDTH, SCREEN_HEIGHT)
myapp.run()
コード例 #33
0
ファイル: tutorial3.py プロジェクト: voidJeff/ggame-tutorials
        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)
コード例 #34
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)
コード例 #35
0
ファイル: project.py プロジェクト: eddie-jeon/PROJECT
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()
コード例 #36
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)
コード例 #37
0
ファイル: test.py プロジェクト: tiggerntatie/ggame-tutorials
from ggame import TextAsset, App, Sprite

a = App()
a.run()
コード例 #38
0
def map(file,scale):
    picture=ImageAsset("images/" + file)
    picture_sprite=Sprite(picture, (0,0))
    picture_sprite.scale = scale
    myapp = App()
    myapp.run()