Exemple #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()
Exemple #2
0
        elif event.is_key():
            if event.key == " ":
                paused = not paused
            elif event.key in ("+", "="):
                block_size += 1
            elif event.key == "-":
                block_size = max(10, block_size - 1)
            elif event.key == "c":
                cells.clear()
        if event.is_mouse_motion() and event.is_pressed(pygo.left_button):
            cells.add(point_to_block(*event.start))
            cells.add(point_to_block(*event.end))

    blocks_x, blocks_y = window.width // block_size, window.width // block_size

    alive = pygo.image(block_size, block_size, color="white")
    alive.draw_hollow_rect(position=alive.topleft,
                           size=alive.size,
                           color="gray10")

    dead = pygo.image(block_size, block_size, color="black")
    dead.draw_hollow_rect(position=dead.topleft,
                          size=dead.size,
                          color="gray10")

    for x in range(-blocks_x // 2 - 1, blocks_x // 2 + 2):
        for y in range(-blocks_y // 2 - 1, blocks_y // 2 + 2):
            if (x, y) in cells:
                window.draw_image(alive, block_to_point(x, y))
            else:
                window.draw_image(dead, block_to_point(x, y))
Exemple #3
0
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")

collide_block = pygo.image(100, 100, color="green")

while window.active():
    for event in window.events():
Exemple #4
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

window = pygame_go.window(600, 400)

bullet = pygame_go.image(10, 10)
bullet.draw_circle(position=bullet.center, radius=5, color="red")
bullets = []

while window.active():
    window.fill("white")
    window.draw_text(text="Press space to shoot...",
                     position=window.topleft,
                     color="black")

    new_bullets = []
    for x, y in bullets:
        if y > -10:
            new_bullets.append((x, y - 10))
    bullets = new_bullets
Exemple #5
0
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
import random

window = pygame_go.window(600, 400)

background_color = pygame_go.color.colors["white"]
block_x = block_y = 50

block = pygame_go.image(10, 10)
block.fill(pygame_go.color.colors["red"])
block2 = pygame_go.image(10, 10)
block2.fill(255, 0, 255)
block3 = pygame_go.image(10, 100)
block3.fill("blue")
block4 = pygame_go.image(10, 100)
block4.fill("tomato")

while window.active():
    for event in window.events():
        print(repr(event))
        if event.is_mouse_press():
            if event.button is pygame_go.left_button:
                print("Mouse click at", event.position, "using left button")
            elif event.button is pygame_go.right_button:
Exemple #6
0
"""

import pygame_go as pygo
import random

SNAKE_SIZE = 20

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

snake_dx, snake_dy = 0, SNAKE_SIZE
cx, cy = window.center
snake_parts = [(cx, cy - SNAKE_SIZE * i) for i in range(3)]
food_location = (random.randrange(window.width // SNAKE_SIZE) * SNAKE_SIZE,
                 random.randrange(window.height // SNAKE_SIZE) * SNAKE_SIZE)

head_image = pygo.image(SNAKE_SIZE, SNAKE_SIZE, color="white")
head_image.draw_circle(position=head_image.center, radius=2, color="black")
head_image.draw_hollow_rect(position=head_image.topleft,
                            size=head_image.size,
                            color="black")

tail_image_even = pygo.image(SNAKE_SIZE, SNAKE_SIZE, color="yellow")
tail_image_odd = pygo.image(SNAKE_SIZE, SNAKE_SIZE, color="green")
food_image = pygo.image(SNAKE_SIZE, SNAKE_SIZE, color="red")

while window.active():
    window.fill("white")

    for event in window.events():
        if event.is_key() and event.key in [
                "<Left>", "<Right>", "<Up>", "<Down>"