五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

坦克穿衣服 ?| Python編程開發(fā)坦克大戰(zhàn)游戲

2023-05-01 09:46 作者:bili_11451425  | 我要投稿

import pygame

import os


FPS = 60

WIDTH = 1000

HEIGHT = 600

WHITE = (255,255,255)

GREEN = (0,255,0)

BLACK = (0,0,0)


pygame.init()

screen = pygame.display.set_mode((WIDTH,HEIGHT))

pygame.display.set_caption("坦克大戰(zhàn)")

clock = pygame.time.Clock()

running = True


class Player(pygame.sprite.Sprite):

? ? def __init__(self) -> None:

? ? ? ? super().__init__()

? ? ? ? tank_img = pygame.image.load(os.path.join("img/myTank","tank_T1_0.png")).convert()

? ? ? ? self.tank = tank_img

? ? ? ? self.tank.set_colorkey(WHITE)

? ? ? ? self.image = self.tank.subsurface((0,0),(48,48))

? ? ? ? self.rect = self.image.get_rect()

? ? ? ? self.rect.centerx = WIDTH/2

? ? ? ? self.rect.bottom = HEIGHT - 10

? ? ? ? self.speed = 8

? ? ? ? self.direction = "UP"


? ? def update(self):

? ? ? ? key_pressed = pygame.key.get_pressed()

? ? ? ? if key_pressed[pygame.K_RIGHT]:

? ? ? ? ? ? self.rect.x = self.rect.x + self.speed

? ? ? ? ? ? self.image = self.tank.subsurface((0,144),(48,42))

? ? ? ? ? ? self.direction = "RIGHT" ? ? ?

? ? ? ? if key_pressed[pygame.K_LEFT]:

? ? ? ? ? ? self.rect.x -= self.speed

? ? ? ? ? ? self.image = self.tank.subsurface((0,96),(48,48))

? ? ? ? ? ? self.direction = "LEFT" ? ?

? ? ? ? if key_pressed[pygame.K_UP]:

? ? ? ? ? ? self.rect.y -= self.speed

? ? ? ? ? ? self.image = self.tank.subsurface((0,0),(48,48)) ?

? ? ? ? ? ? self.direction = "UP" ? ? ? ?

? ? ? ? if key_pressed[pygame.K_DOWN]:

? ? ? ? ? ? self.rect.y += self.speed

? ? ? ? ? ? self.image = self.tank.subsurface((0,48),(48,48))

? ? ? ? ? ? self.direction = "DOWN" ? ?

? ? ? ? if(self.rect.right > WIDTH):

? ? ? ? ? ? self.rect.right = WIDTH

? ? ? ? if(self.rect.left < 0):

? ? ? ? ? ? ? ? self.rect.left = 0

? ? ? ? if(self.rect.top < 0):

? ? ? ? ? ? self.rect.top = 0

? ? ? ? if(self.rect.bottom > HEIGHT):

? ? ? ? ? ? self.rect.bottom = HEIGHT


? ? def shoot(self):

? ? ? ? bullet = Bullet(self.rect.centerx,self.rect.centery,self.direction)

? ? ? ? all_sprites.add(bullet)


class Bullet(pygame.sprite.Sprite):

? ? def __init__(self,x,y,direction) -> None:

? ? ? ? super().__init__()

? ? ? ? self.bullets = ['./img/bullet/bullet_up.png','./img/bullet/bullet_down.png','./img/bullet/bullet_left.png','./img/bullet/bullet_right.png',]

? ? ? ? self.direction = direction

? ? ? ? if self.direction == "UP":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[0]) ?

? ? ? ? if self.direction == "DOWN":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[1])

? ? ? ? if self.direction == "LEFT":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[2])

? ? ? ? if self.direction == "RIGHT":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[3])

? ? ? ? ? ? self.image = self.bullet

? ? ? ? ? ? self.image.set_colorkey(WHITE)

? ? ? ? ? ? self.rect = self.image.get_rect()

? ? ? ? ? ? self.rect.x = x

? ? ? ? ? ? self.rect.y = y

? ? ? ? ? ? self.speed = 10


? ? def update(self):

? ? ? ? if self.direction == "UP":

? ? ? ? ? ? self.rect.y -= self.speed

? ? ? ? if self.direction == "DOWN":

? ? ? ? ? ? self.rect.y += self.speed

? ? ? ? if self.direction == "LEFT":

? ? ? ? ? ? self.rect.x -= self.speed

? ? ? ? if self.direction == "RIGHT":

? ? ? ? ? ? self.rect.x += self.speed

? ? ? ? if self.rect.bottom > HEIGHT:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.top > 0:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.left < WIDTH:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.right < 0:

? ? ? ? ? ? self.kill()


all_sprites = pygame.sprite.Group()

player = Player()

all_sprites.add(player)


while running:

? ? clock.tick(FPS)

? ? for event in pygame.event.get():

? ? ? ? if event.type == pygame.QUIT:

? ? ? ? ? ? running = False

? ? ? ? elif event.type == pygame.KEYDOWN:

? ? ? ? ? ? if(event.key ?== pygame.K_SPACE):

? ? ? ? ? ? ? ? player.shoot()


? ? screen.fill(BLACK)

? ? all_sprites.update ()

? ? all_sprites.draw(screen)

? ? pygame.display.update()


pygame.quit()

幫忙看看吧

坦克穿衣服 ?| Python編程開發(fā)坦克大戰(zhàn)游戲的評論 (共 條)

分享到微博請遵守國家法律
宁波市| 江达县| 会同县| 延吉市| 昌平区| 贵南县| 新巴尔虎左旗| 西安市| 阿拉善右旗| 延安市| 紫阳县| 凤庆县| 淮滨县| 三门县| 儋州市| 新泰市| 普兰店市| 营山县| 武城县| 榆社县| 镇安县| 梧州市| 德州市| 南充市| 文化| 东方市| 鄂伦春自治旗| 福建省| 孙吴县| 定西市| 宝鸡市| 长岭县| 金秀| 鹿邑县| 都安| 仙桃市| 玛沁县| 阿克| 祁门县| 肃南| 教育|