Exemplo n.º 1
0
"""
follow.py
=========
Move the cursor, and the red block follows.

Copyright (C) 2017 Matthew Joyce ([email protected])

This program is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pygame_go as pygo

window = pygo.window(600, 400)
block = pygo.image(10, 10, color="red")

while window.active():
    window.fill("white")
    window.draw_image(block, pygo.mouse_position(), align=pygo.center)
    window.update()
Exemplo n.º 2
0
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pygame_go as pygo

block_size = 20

window = pygo.window(1000, 600, frame_rate=10)

cells = set()
paused = False


def point_to_block(x, y):
    block_x = (x - window.width // 2) // block_size
    block_y = (y - window.height // 2) // block_size
    return block_x, block_y


def block_to_point(block_x, block_y):
    x = block_x * block_size + window.width // 2
    y = block_y * block_size + window.height // 2
    return x, y
Exemplo n.º 3
0
"""
basic.py
========
Show a blank, black window to the user. The only interaction is quitting.
This is the bare minimum for a pygame-go program

Copyright (C) 2017 Matthew Joyce ([email protected])

This program is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pygame_go

window = pygame_go.window(600, 400)
window.loop_forever()
Exemplo n.º 4
0
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pygame_go as pygo

window = pygo.window(600, 400, frame_rate=60)

mode = 0

cursor_block = pygo.image(20, 20, color="red")

cursor_circle = pygo.image(20, 20)
cursor_circle.draw_circle(position=cursor_circle.center,
                          radius=cursor_circle.width // 2,
                          color="red")

collide_circle = pygo.image(100, 100)
collide_circle.draw_circle(position=collide_circle.center,
                           radius=collide_circle.width // 2,
                           color="green")
Exemplo n.º 5
0
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pygame_go as pygo

BALL_RADIUS = 50

window = pygo.window(800, 600, frame_rate=60)

ball_x, ball_y = window.center
ball_dx = ball_dy = 5
bounces = 0

while window.active():
    bounced = False
    if ball_x in (BALL_RADIUS, window.width - BALL_RADIUS):
        ball_dx = -ball_dx
        bounced = True
    if ball_y in (BALL_RADIUS, window.height - BALL_RADIUS):
        ball_dy = -ball_dy
        bounced = True

    bounces += bounced