找回密码
 中文实名注册
查看: 191|回复: 3

【python作业】李松沐 第一小学 六年级

[复制链接]

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
发表于 2022-8-13 15:17:39 | 显示全部楼层 |阅读模式
我的作业。。。。
回复

使用道具 举报

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
 楼主| 发表于 2022-8-13 15:18:14 | 显示全部楼层

第七单元第一课 炮弹栈

本帖最后由 李松沐 于 2022-8-13 15:24 编辑

[Python] 纯文本查看 复制代码
# 你需要在这里修改 [鼠标点击事件] 的代码
        # 鼠标点击事件
        if event.type == pygame.MOUSEBUTTONDOWN:
            # 获取鼠标坐标
            mouse_position=pygame.mouse.get_pos()
            if storage_rect.collidepoint(mouse_position) and len(ball_list)<4:
                ball_list.append(ball)
                ball=spaceship.new_ball

            # 【在这里编写代码,完成弹出反应仓的代码】
            

            else:
                # 把炮台中的能量球发射出去
                spaceship.fire_ball(ball, mouse_position)
                # 产生一颗新的能量球放到炮台里
                ball = spaceship.new_ball()
回复

使用道具 举报

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
 楼主| 发表于 2022-9-4 15:30:29 | 显示全部楼层

第八课 滑雪大冒险-1

[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):
        pass
    def turn_left(self):
        pass
    def turn_right(self):
        self.change_direction='left'
        self.position[1]+=5
car_one=Car('red',1)
car_two=Car('blue',3)
car_two.turn_left()
回复

使用道具 举报

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
 楼主| 发表于 2022-9-11 15:30:49 | 显示全部楼层

pygame

[Python] 纯文本查看 复制代码
import pygame
import sys
pygame.init()
screen=pygame.display.set_mode((800,600))              
bg=pygame.image.load('image\星海背景.png')
ball1 = pygame.image.load('image\红色能量球.png')
ball2 = pygame.image.load('image\绿色能量球.png')
site1=[0,0]
site2=[0,0]
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:
                site1[1]-=8
            if event.key == pygame.K_DOWN:
                site1[1] += 8
            if event.key==pygame.K_LEFT:
                site1[0]-=8
            if event.key == pygame.K_RIGHT:
                site1[0] += 8
        if event.type==pygame.MOUSEBUTTONDOWN:
            print(event.pos)
            site2=list=(event.pos)
            print(site2)
    screen.blit(bg, (0, 0))
    screen.blit(ball1, site1)
    screen.blit(ball2, (site2[0]-29,site2[1]-29))
    pygame.display.update()
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 09:35 , Processed in 0.042882 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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