Get the App
SLTechnology News&Howtos  ›  Development  › 

Python uses pygame to realize Code sharing of Tank Battle Games

Shulou Source: shulou.com Published: 2022-06-03 18:27:53 10月03日 Update

This article mainly explains "python uses pygame to realize the code sharing of tank war games". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "python uses pygame to achieve tank war game code sharing"!

Import pygameimport sysimport timefrom pygame.locals import * from random import randintMOVE_SLEEP = 0.01class MyTank: width = 500speed = 10 screen = 0 myshells = [] enemylist = [] enemyshells = [] grade = 0 life = 3 cnt = 0 def startgame (self): pygame.init () self.screen = pygame.display.set_mode ((self.width,self.heights), 0Lab 32) pygame.display.set_caption ("bit tank") self.tank = Tank (self.screen) 275450) for i in range (6): self.enemylist.append (EnmeyTank (self.screen)) while True: key = pygame.key.get_pressed () self.screen.fill ((0mem0) 0) if key [K _ LEFT]: self.tank.move ('L') elif key [K _ RIGHT]: self.tank.move ('R') elif key [K _ UP]: self.tank.move ('U') elif key [K _ DOWN]: self.tank.move ('D') self.get_event () for shell in self.myshells: if shell.move () = True: self.myshells.remove (shell) shell .display () a = shell.hitTank () # bullet collision if a = = True: if self.life > 0: self.myshells.remove (shell) self.grade + = 1 # mytank collision if self.tank.live = = True: if self.tank.hitTank (): self.life-= 1 if self.life

Tags: Tanks bullets collisions codes wars enemies content learning practicality deeper interests scores practicality practicality simplicity of operation methods more friends lives websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia vpn Shulou Technology Shulou Information