Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorio intersection functions #9753

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

FoamyGuy
Copy link
Collaborator

Replaces: #9483 that branch accidentally got some unintended changes to files that were unrelated and I could not figure out how to properly revert those changes so I've just made a new branch and PR.

This adds functions to vectorio for testing intersection between the 3 different supported shapes.

Testing was performed on the PyGamer and Pimoroni PicoSystem with this test code and some variations of it to call the different various functions inside the main loop.

import time

import board
import displayio
import vectorio
from game_controls import game_controls

display = board.DISPLAY

main_group = displayio.Group()

palette = displayio.Palette(4)
palette[0] = 0xffffff
palette[1] = 0x125690
palette[2] = 0xbb4444
palette[3] = 0x44bb44

# static_rect = vectorio.Rectangle(pixel_shader=palette, width=40, height=30, x=55, y=45)
# main_group.append(static_rect)

static_polygon = vectorio.Polygon(pixel_shader=palette, points=[
    (-25, -25), (25, -25),
    (45, 25), (-45, 25)
], x=display.width // 2, y=display.height // 2)

moving_rect = vectorio.Rectangle(pixel_shader=palette, width=10, height=10, x=0, y=0)
moving_rect.color_index = 1
main_group.append(moving_rect)

# moving_circle = vectorio.Circle(pixel_shader=palette, radius=7, x=15, y=15)
# moving_circle.color_index = 1
# main_group.append(moving_circle)

display.root_group = main_group
while True:
    cur_state = game_controls.button

    if (cur_state['up']):
        moving_rect.y -= 1
        # moving_circle.y -= 1

    if (cur_state['down']):
        moving_rect.y += 1
        # moving_circle.y += 1

    if (cur_state['right']):
        moving_rect.x += 1
        # moving_circle.x += 1

    if (cur_state['left']):
        moving_rect.x -= 1
        # moving_circle.x -= 1
        
    if vectorio.polygon_rectangle_intersects(
            static_polygon.points, static_polygon.x, static_polygon.y,
            moving_rect.x, moving_rect.y, moving_rect.width, moving_rect.height):

        static_polygon.color_index = 3
    else:
        static_polygon.color_index = 2

    time.sleep(0.01)

@FoamyGuy FoamyGuy mentioned this pull request Oct 23, 2024
@FoamyGuy
Copy link
Collaborator Author

The latest commits update the new code to work under the unix port and add an initial very basic test of the intersection functionality. I've also disabled vectorio on a few more devices which overflowed the build since the previous time I worked on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant