找回密码
 中文实名注册
查看: 187|回复: 2

姜仲翌

[复制链接]

3

主题

41

帖子

868

积分

高级会员

Rank: 4

积分
868
发表于 2022-9-4 15:53:39 | 显示全部楼层 |阅读模式
python作业
回复

使用道具 举报

3

主题

41

帖子

868

积分

高级会员

Rank: 4

积分
868
 楼主| 发表于 2022-9-4 15:55:44 | 显示全部楼层

第7单元第2课

[Python] 纯文本查看 复制代码
class Car():
    def __init__(self,color,people):
        self.color = color
        self.people = people
        self.position = [400,300]
        self.change_direction = 'right'

    def forward(self):
        self.change_direction = 'up'
        self.position[0] += 5

    def backward(self):
        self.change_direction = 'down'
        self.position[0] -= 5

    def turn_left(self):
        self.change_direction = 'left'
        self.position[1] = 5

    def turn_right(self):
        self.change_direction = 'left'
        self.position[1] += 5

回复

使用道具 举报

3

主题

41

帖子

868

积分

高级会员

Rank: 4

积分
868
 楼主| 发表于 2022-9-11 15:38:50 | 显示全部楼层
[Python] 纯文本查看 复制代码
import pygame
import sys

pygame.init()
screen = pygame.display.set_mode((800,600))

bg=pygame.image.load('image\星海背景.png')
tg=pygame.image.load('image\炮台_红色珠子.png')
og=pygame.image.load('image\炮台_蓝色珠子.png')
qg=pygame.image.load('image\红色能量球.png')
ball=pygame.image.load('image\蓝色能量球.png')

site = [300,300]
site2 = [500,300]

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                site[1] -= 8
            if event.key == pygame.K_DOWN:
                site[1] += 8
            if event.key == pygame.K_LEFT:
                site[0] -= 8
            if event.key == pygame.K_RIGHT:
                site[0] += 8
                print(site)

        if event.type == pygame.MOUSEBUTTONDOWN:
            print(event.pos)
            site2=list(event.pos)
            print(site2)

    screen.blit(bg,(0,0))
    screen.blit(tg,(0,0))
    screen.blit(og,(0,300))
    screen.blit(qg,site)
    screen.blit(ball,(site2[0]-29,site2[1]-29))
    pygame.display.update()

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-5-9 07:59 , Processed in 0.041715 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表