Ejemplo n.º 1
0
def drawBall():
    # Ball
    no_stroke()
    fill(ball['color'][0], ball['color'][1], ball['color'][2])
    circle((ball['pos'][0], ball['pos'][1]), ball['radius'])

    # Border colitions
    if asm.ADD(int(ball['pos'][1]),
               int(ball['radius'] / 2)) > height or asm.SUB(
                   int(ball['pos'][1]), int(ball['radius'] / 2)) < 0:
        ball['vel'][1] = asm.MUL(ball['vel'][1], -1)

    # Right paddle colitions
    if asm.ADD(int(ball['pos'][0]), int(
            ball['radius'] / 2)) >= rightPaddle.pos['x']:
        if asm.ADD(int(ball['pos'][1]), int(
                ball['radius'] / 2)) >= rightPaddle.pos['y'] and asm.SUB(
                    int(ball['pos'][1]), int(ball['radius'] / 2)) <= asm.ADD(
                        int(rightPaddle.pos['y']), rightPaddle.heigth):
            ball['vel'][0] = asm.MUL(ball['vel'][0], -1)

    # Left paddle colitions
    if asm.ADD(int(ball['pos'][0]), int(ball['radius'] / 2)) <= asm.ADD(
            int(leftPaddel.pos['x']), asm.MUL(leftPaddel.width, 2)):
        if asm.ADD(int(ball['pos'][1]), int(
                ball['radius'] / 2)) >= leftPaddel.pos['y'] and asm.SUB(
                    int(ball['pos'][1]), int(ball['radius'] / 2)) <= asm.ADD(
                        int(leftPaddel.pos['y']), leftPaddel.heigth):
            ball['vel'][0] = asm.MUL(ball['vel'][0], -1)

    # Update ball position
    ball['pos'][1] = asm.ADD(int(ball['pos'][1]), ball['vel'][1])
    ball['pos'][0] = asm.ADD(int(ball['pos'][0]), ball['vel'][0])
Ejemplo n.º 2
0
def draw():
    global leftPaddel, rightPaddle

    background(0)

    # Paddles
    no_stroke()
    fill(255)
    rect(( leftPaddel.pos['x'], leftPaddel.pos['y'] ), leftPaddel.width, leftPaddel.heigth)
    rect(( rightPaddle.pos['x'], rightPaddle.pos['y'] ), rightPaddle.width, rightPaddle.heigth)

    # Check move
    if leftPaddel.moving != 0:
        leftPaddel.pos['y'] = asm.ADD(leftPaddel.pos['y'], leftPaddel.vel * leftPaddel.moving)
    if rightPaddle.moving != 0:
        rightPaddle.pos['y'] = asm.ADD(rightPaddle.pos['y'], rightPaddle.vel * rightPaddle.moving)
Ejemplo n.º 3
0
def drawPaddles():
    # Paddles
    no_stroke()
    fill(255)
    rect((leftPaddel.pos['x'], leftPaddel.pos['y']), leftPaddel.width,
         leftPaddel.heigth)
    rect((rightPaddle.pos['x'], rightPaddle.pos['y']), rightPaddle.width,
         rightPaddle.heigth)

    # Check move
    if leftPaddel.moving != 0:
        if leftPaddel.moving == 1:
            if asm.ADD(leftPaddel.pos['y'], leftPaddel.heigth) < height:
                leftPaddel.pos['y'] = asm.ADD(
                    leftPaddel.pos['y'],
                    asm.MUL(leftPaddel.vel, leftPaddel.moving))
        else:
            if leftPaddel.pos['y'] > 0:
                leftPaddel.pos['y'] = asm.ADD(
                    leftPaddel.pos['y'],
                    asm.MUL(leftPaddel.vel, leftPaddel.moving))
    if rightPaddle.moving != 0:
        if rightPaddle.moving == 1:
            if asm.ADD(rightPaddle.pos['y'], rightPaddle.heigth) < height:
                rightPaddle.pos['y'] = asm.ADD(
                    rightPaddle.pos['y'],
                    asm.MUL(rightPaddle.vel, rightPaddle.moving))
        else:
            if rightPaddle.pos['y'] > 0:
                rightPaddle.pos['y'] = asm.ADD(
                    rightPaddle.pos['y'],
                    asm.MUL(rightPaddle.vel, rightPaddle.moving))
Ejemplo n.º 4
0
def setup():
    global leftPaddel, rightPaddle

    title('PongASM')
    size(1280, 720)

    # Paddle creation
    leftPaddel = Paddel(
        height = 150,
        pos = {'x': 50, 'y' : 50}, 
        vel = 10
    )
    rightPaddle = Paddel(
        height = 150,
        pos = {'x': asm.ADD(width, -50), 'y' : 50}, 
        vel = 10
    )

    # Correctly position the paddles
    rightPaddle.pos['x'] = asm.ADD(rightPaddle.pos['x'], -rightPaddle.width)
    leftPaddel.pos['y'] = asm.ADD(int(height / 2), -int(leftPaddel.heigth / 2))
    rightPaddle.pos['y'] = asm.ADD(int(height / 2), -int(rightPaddle.heigth / 2))
Ejemplo n.º 5
0
import time

num = 0
t0 = time.time()

import hectorASM as asm

for n in range(10000000):
    num = asm.ADD(num, 1)

t1 = time.time()

total = t1-t0
print('Prueba con hectorASM:')
print('Num: {}'.format(num))
print('Total time: {}'.format(total))

num = 0
t0 = time.time()

import hectorASM as asm

for n in range(10000000):
    num += 1

t1 = time.time()

total = t1-t0
print('\nPrueba normal:')
print('Num: {}'.format(num))
print('Total time: {}'.format(total))
Ejemplo n.º 6
0
def draw():
    global leftPaddel, rightPaddle

    background(0)

    # Ball
    no_stroke()
    fill(ball['color'][0], ball['color'][1], ball['color'][2])
    circle((ball['pos'][0], ball['pos'][1]), ball['radius'])
    
    # Border colitions
    if asm.ADD(int(ball['pos'][1]), int(ball['radius'] / 2)) > height or asm.SUB(int(ball['pos'][1]), int(ball['radius'] / 2)) < 0:
        ball['vel'][1] = asm.MUL(ball['vel'][1], -1)

    # Right paddle colitions
    if asm.ADD(int(ball['pos'][0]), int(ball['radius'] / 2)) >= rightPaddle.pos['x']:
        if asm.ADD(int(ball['pos'][1]), int(ball['radius'] / 2)) >= rightPaddle.pos['y'] and asm.SUB(int(ball['pos'][1]), int(ball['radius'] / 2)) <= asm.ADD(int(rightPaddle.pos['y']), rightPaddle.heigth):
            ball['vel'][0] = asm.MUL(ball['vel'][0], -1)  

    # Left paddle colitions
    if asm.ADD(int(ball['pos'][0]), int(ball['radius'] / 2)) <= asm.ADD(int(leftPaddel.pos['x']), asm.MUL(leftPaddel.width, 2)):
        if asm.ADD(int(ball['pos'][1]), int(ball['radius'] / 2)) >= leftPaddel.pos['y'] and asm.SUB(int(ball['pos'][1]), int(ball['radius'] / 2)) <= asm.ADD(int(leftPaddel.pos['y']), leftPaddel.heigth):
            ball['vel'][0] = asm.MUL(ball['vel'][0], -1)  

    # Update ball position
    ball['pos'][1] = asm.ADD(int(ball['pos'][1]), ball['vel'][1])
    ball['pos'][0] = asm.ADD(int(ball['pos'][0]), ball['vel'][0])

    # Paddles
    no_stroke()
    fill(255)
    rect(( leftPaddel.pos['x'], leftPaddel.pos['y'] ), leftPaddel.width, leftPaddel.heigth)
    rect(( rightPaddle.pos['x'], rightPaddle.pos['y'] ), rightPaddle.width, rightPaddle.heigth)

    # Check move
    if leftPaddel.moving != 0:
        if leftPaddel.moving == 1:
            if asm.ADD(asm.ADD(leftPaddel.pos['y'], leftPaddel.heigth), borde) < height:
                leftPaddel.pos['y'] = asm.ADD(leftPaddel.pos['y'], asm.MUL(leftPaddel.vel, leftPaddel.moving))
        else:
            if asm.ADD(leftPaddel.pos['y'], borde) > 0:
                leftPaddel.pos['y'] = asm.ADD(leftPaddel.pos['y'], asm.MUL(leftPaddel.vel, leftPaddel.moving))
    if rightPaddle.moving != 0:
        if rightPaddle.moving == 1:
            if asm.ADD(asm.ADD(rightPaddle.pos['y'], rightPaddle.heigth), borde) < height:
                rightPaddle.pos['y'] = asm.ADD(rightPaddle.pos['y'], asm.MUL(rightPaddle.vel, rightPaddle.moving))
        else:
            if asm.ADD(rightPaddle.pos['y'], borde) > 0:
                rightPaddle.pos['y'] = asm.ADD(rightPaddle.pos['y'], asm.MUL(rightPaddle.vel, rightPaddle.moving))