URL:https://algorithm.joho.info/programming/python/google-colab-gpu/
Pythonで出来るゲームPygameでブロック崩しゲームを自作した方がいます
この公開プログラムを、ほぼコピペしてプログラムを作成し、実行した結果が下の動画です
失敗すると残念な音が出ますが、ブログでは確認できないかもしれません
プログラムを全部載せると、文字数がオーバーになるので、頭の部分だけにしました
import pygame
from pygame.locals import *
import math
import sys
import pygame.mixer
SCREEN = Rect(0, 0, 400, 400)
from pygame.locals import *
import math
import sys
import pygame.mixer
SCREEN = Rect(0, 0, 400, 400)
# パドルのクラス sprite:妖精、炭酸が勢いよくはじける様子 rect:長方形 clamp:留め金、固定する
# paddle:カヌーをこぐ道具
class Paddle(pygame.sprite.Sprite):
def __init__(self, filename):
pygame.sprite.Sprite.__init__(self, self.containers)
self.image = pygame.image.load(filename).convert()
self.rect = self.image.get_rect()
self.rect.bottom = SCREEN.bottom - 20 # パドルのy座標
def update(self):
self.rect.centerx = pygame.mouse.get_pos()[0] # マウスのx座標をパドルのx座標に
self.rect.clamp_ip(SCREEN) # ゲーム画面内のみで移動
# paddle:カヌーをこぐ道具
class Paddle(pygame.sprite.Sprite):
def __init__(self, filename):
pygame.sprite.Sprite.__init__(self, self.containers)
self.image = pygame.image.load(filename).convert()
self.rect = self.image.get_rect()
self.rect.bottom = SCREEN.bottom - 20 # パドルのy座標
def update(self):
self.rect.centerx = pygame.mouse.get_pos()[0] # マウスのx座標をパドルのx座標に
self.rect.clamp_ip(SCREEN) # ゲーム画面内のみで移動