Esempio n. 1
0
import cppyy
cppyy.include("bounce.hpp")
from cppyy.gbl import Arena, Ball, Ghost, Turtle, Point, Rect

import sys; sys.path.append('../examples/')
import g2d

def pt(x, y):
    p = Point()
    p.x, p.y = x, y
    return p
##cppyy.gbl.Point.__getitem__ = lambda self, key: getattr(self, "xy"[key])
##cppyy.gbl.Rect.__getitem__ = lambda self, key: getattr(self, "xywh"[key])

arena = Arena(pt(480, 360))
b1 = Ball(arena, pt(40, 80))
b2 = Ball(arena, pt(80, 40))
g = Ghost(arena, pt(120, 80))
turtle = Turtle(arena, pt(80, 80))
sprites = g2d.load_image("sprites.png")

def tick():
    if g2d.key_pressed("ArrowUp"):
        turtle.go_up(True)
    elif g2d.key_released("ArrowUp"):
        turtle.go_up(False)
    if g2d.key_pressed("ArrowRight"):
        turtle.go_right(True)
    elif g2d.key_released("ArrowRight"):
        turtle.go_right(False)
    if g2d.key_pressed("ArrowDown"):
Esempio n. 2
0
#!/usr/bin/env python3
'''
@author  Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic
@license This software is free - http://www.gnu.org/licenses/gpl.html
'''

import cppyy
cppyy.include("ball.cpp")
from cppyy.gbl import Ball

b = Ball((150, 200))
for i in range(10):
    b.move()
    print(b.position())
Esempio n. 3
0
import cppyy
cppyy.include("ball.hpp")
from cppyy.gbl import Ball

b = Ball(150, 200)
print(b.get_x(), b.get_y())
for i in range(10):
    b.move()
    print(b.get_x(), b.get_y())
Esempio n. 4
0
#!/usr/bin/env python3
'''
@author  Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic
@license This software is free - http://www.gnu.org/licenses/gpl.html
'''

import cppyy
cppyy.include("ball.cpp")
from cppyy.gbl import Ball

b1 = Ball(40, 80)
b2 = Ball(80, 40)

for i in range(25):
    b1.move()
    b2.move()
    print(b1.pos_x(), b1.pos_y())
    print(b2.pos_x(), b2.pos_y())
Esempio n. 5
0
#!/usr/bin/env python3

import cppyy

cppyy.include("actor.cpp")
cppyy.include("bounce.cpp")
from cppyy.gbl import Arena, Ball, Ghost, Turtle

import g2d

arena = Arena(320, 240)
b1 = Ball(arena, 40, 80)
b2 = Ball(arena, 80, 40)
g = Ghost(arena, 120, 80)
turtle = Turtle(arena, 80, 80)
sprites = g2d.load_image("sprites.png")


def update():
    arena.move_all()  # Game logic

    g2d.fill_canvas((255, 255, 255))
    for a in arena.actors():
        g2d.draw_image_clip(sprites, a.position(), a.symbol())


def keydown(code):
    if code == "ArrowUp":
        turtle.go_up()
    elif code == "ArrowDown":
        turtle.go_down()
Esempio n. 6
0
#!/usr/bin/env python3
'''
@author  Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic
@license This software is free - http://www.gnu.org/licenses/gpl.html
'''

import cppyy
cppyy.include("bounce.hpp")
from cppyy.gbl import Arena, Ball, Ghost, Turtle, Point, Rect

import sys; sys.path.append('../examples/')
import g2d_pyg as g2d

arena = Arena((480, 360))
b1 = Ball(arena, (40, 80))
b2 = Ball(arena, (80, 40))
g = Ghost(arena, (120, 80))
turtle = Turtle(arena, (80, 80))
sprites = g2d.load_image("../examples/sprites.png")

def tick():
    if g2d.key_pressed("ArrowUp"):
        turtle.go_up(True)
    elif g2d.key_released("ArrowUp"):
        turtle.go_up(False)
    if g2d.key_pressed("ArrowRight"):
        turtle.go_right(True)
    elif g2d.key_released("ArrowRight"):
        turtle.go_right(False)
    if g2d.key_pressed("ArrowDown"):
        turtle.go_down(True)