Skip to content

Commit

Permalink
Unified comment
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesPikachu committed Dec 10, 2019
1 parent e7d224b commit 6bedffa
Show file tree
Hide file tree
Showing 27 changed files with 163 additions and 179 deletions.
1 change: 0 additions & 1 deletion Game1/Game1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
'''
Function:
Bunnies and Badgers
Expand Down
35 changes: 18 additions & 17 deletions Game10/Game10.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
HEIGHT = 560


# 定义按钮
'''定义按钮'''
def BUTTON(screen, position, text):
bwidth = 310
bheight = 65
Expand All @@ -31,7 +31,7 @@ def BUTTON(screen, position, text):
return screen.blit(text_render, (left+50, top+10))


# 开始界面
'''开始界面'''
def start_interface(screen):
clock = pygame.time.Clock()
while True:
Expand All @@ -50,7 +50,7 @@ def start_interface(screen):
pygame.display.update()


# 子弹
'''子弹'''
class Bullet(pygame.sprite.Sprite):
def __init__(self, idx, position):
pygame.sprite.Sprite.__init__(self)
Expand All @@ -65,16 +65,16 @@ def __init__(self, idx, position):
self.speed = 8
# 玩家编号
self.playerIdx = idx
# 移动子弹
'''移动子弹'''
def move(self):
self.position = self.position[0], self.position[1] - self.speed
self.rect.left, self.rect.top = self.position
# 画子弹
'''画子弹'''
def draw(self, screen):
screen.blit(self.image, self.rect)


# 小行星
'''小行星'''
class Asteroid(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
Expand All @@ -89,11 +89,11 @@ def __init__(self):
self.angle = 0
self.angular_velocity = random.randrange(1, 5)
self.rotate_ticks = 3
# 移动小行星
'''移动小行星'''
def move(self):
self.position = self.position[0], self.position[1] + self.speed
self.rect.left, self.rect.top = self.position
# 转动小行星
'''转动小行星'''
def rotate(self):
self.rotate_ticks -= 1
if self.rotate_ticks == 0:
Expand All @@ -105,12 +105,12 @@ def rotate(self):
rot_image = rot_image.subsurface(rot_rect).copy()
self.image = rot_image
self.rotate_ticks = 3
# 画小行星
'''画小行星'''
def draw(self, screen):
screen.blit(self.image, self.rect)


# 飞船
'''飞船'''
class Ship(pygame.sprite.Sprite):
def __init__(self, idx):
pygame.sprite.Sprite.__init__(self)
Expand All @@ -129,12 +129,12 @@ def __init__(self, idx):
self.cooling_time = 0
# 爆炸用
self.explode_step = 0
# 飞船爆炸
'''飞船爆炸'''
def explode(self, screen):
img = self.explode_img.subsurface((48*(self.explode_step-1), 0), (48, 48))
screen.blit(img, (self.position['x'], self.position['y']))
self.explode_step += 1
# 移动飞船
'''移动飞船'''
def move(self, direction):
if direction == 'left':
self.position['x'] = max(-self.speed['x']+self.position['x'], -10)
Expand All @@ -145,15 +145,15 @@ def move(self, direction):
elif direction == 'down':
self.position['y'] = min(self.speed['y']+self.position['y'], 520)
self.rect.left, self.rect.top = self.position['x'], self.position['y']
# 画飞船
'''画飞船'''
def draw(self, screen):
screen.blit(self.image, self.rect)
# 射击
'''射击'''
def shot(self):
return Bullet(self.playerIdx, (self.rect.center[0] - 5, self.position['y'] - 5))


# 游戏界面
'''游戏界面'''
def GameDemo(num_player, screen):
pygame.mixer.music.load(("./resources/sounds/Cool Space Music.mp3"))
pygame.mixer.music.set_volume(0.4)
Expand Down Expand Up @@ -284,7 +284,7 @@ def GameDemo(num_player, screen):
clock.tick(60)


# 结束界面
'''结束界面'''
def end_interface(screen):
clock = pygame.time.Clock()
while True:
Expand All @@ -304,7 +304,7 @@ def end_interface(screen):
pygame.display.update()


# 主函数
'''主函数'''
def main():
pygame.init()
pygame.font.init()
Expand All @@ -322,5 +322,6 @@ def main():
end_interface(screen)


'''run'''
if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Game11/Game11.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def keyPressEvent(self, event):
self.updateWindow()


'''run'''
if __name__ == '__main__':
app = QApplication([])
tetris = TetrisGame()
Expand Down
34 changes: 10 additions & 24 deletions Game12/Game12.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@
from itertools import chain


'''
Function:
退出游戏
'''
'''退出游戏'''
def quitGame():
pygame.quit()
sys.exit(0)


'''
Function:
游戏地图
'''
'''游戏地图'''
class gameMap():
def __init__(self, num_cols, num_rows):
self.walls = []
Expand Down Expand Up @@ -78,10 +72,7 @@ def getBox(self, col, row):
return None


'''
Function:
游戏界面
'''
'''游戏界面'''
class gameInterface():
def __init__(self, screen):
self.screen = screen
Expand Down Expand Up @@ -139,10 +130,7 @@ def scroll(self):
self.scroll_y += 2


'''
Function:
某一关卡的游戏主循环
'''
'''某一关卡的游戏主循环'''
def runGame(screen, game_level):
clock = pygame.time.Clock()
game_interface = gameInterface(screen)
Expand Down Expand Up @@ -215,7 +203,7 @@ def runGame(screen, game_level):
clock.tick(100)


# 定义按钮
'''定义按钮'''
def BUTTON(screen, position, text):
bwidth = 310
bheight = 65
Expand All @@ -231,7 +219,7 @@ def BUTTON(screen, position, text):
return screen.blit(text_render, (left+50, top+10))


# 开始界面
'''开始界面'''
def startInterface(screen):
screen.fill(Config.get('bg_color'))
clock = pygame.time.Clock()
Expand All @@ -251,7 +239,7 @@ def startInterface(screen):
pygame.display.update()


# 关卡切换界面
'''关卡切换界面'''
def switchInterface(screen):
screen.fill(Config.get('bg_color'))
clock = pygame.time.Clock()
Expand All @@ -271,7 +259,7 @@ def switchInterface(screen):
pygame.display.update()


# 结束界面
'''结束界面'''
def endInterface(screen):
screen.fill(Config.get('bg_color'))
clock = pygame.time.Clock()
Expand All @@ -289,10 +277,7 @@ def endInterface(screen):
pygame.display.update()


'''
Function:
主函数
'''
'''主函数'''
def main():
pygame.init()
pygame.mixer.init()
Expand All @@ -311,5 +296,6 @@ def main():
endInterface(screen)


'''run'''
if __name__ == '__main__':
main()
6 changes: 2 additions & 4 deletions Game13/Game13.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
FPS = 60


'''
Function:
开始游戏
'''
'''开始游戏'''
def startGame(screen):
clock = pygame.time.Clock()
# 加载字体
Expand Down Expand Up @@ -236,5 +233,6 @@ def main():
endInterface(screen, BLACK, is_win)


'''run'''
if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Game14/Game14.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@ def main(screen):
showText(screen, font_big, is_clearance)


'''test'''
if __name__ == '__main__':
main(initialize())
8 changes: 4 additions & 4 deletions Game2/Game2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
'''
Function:
仿八分音符的声控小游戏
Expand Down Expand Up @@ -50,15 +49,15 @@ def __init__(self):
input=True,
frames_per_buffer=self.numSamples)
self.schedule(self.update)
# 碰撞检测
'''碰撞检测'''
def collide(self):
diffx = self.pikachu.x - self.floor.x
for b in self.floor.get_children():
if b.x <= diffx + self.pikachu.width * 0.8 and diffx + self.pikachu.width * 0.2 <= b.x + b.width:
if self.pikachu.y < b.height:
self.pikachu.land(b.height)
break
# 定义游戏规则
'''定义游戏规则'''
def update(self, dt):
# 获取每帧的音量
audio_data = self.stream.read(self.numSamples)
Expand All @@ -69,11 +68,12 @@ def update(self, dt):
if k > 8000:
self.pikachu.jump((k - 8000) / 1000.0)
self.collide()
# 重置
'''重置'''
def reset(self):
self.floor.x = 0


'''run'''
if __name__ == '__main__':
cocos.director.director.init(caption="Pikachu~~~")
cocos.director.director.run(cocos.scene.Scene(VCGame()))
1 change: 0 additions & 1 deletion Game2/classes/block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
'''
Function:
定义block类,用于随机生成地面块
Expand Down
9 changes: 4 additions & 5 deletions Game2/classes/pikachu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
'''
Function:
定义皮卡丘类(Define Pikachu Class)
Expand All @@ -23,25 +22,25 @@ def __init__(self):
# 皮卡丘的位置
self.position = 80, 280
self.schedule(self.update)
# 声控跳跃
'''声控跳跃'''
def jump(self, h):
if self.able_jump:
self.y += 1
self.speed -= max(min(h, 10), 7)
self.able_jump = False
# 着陆后静止
'''着陆后静止'''
def land(self, y):
if self.y > y - 25:
self.able_jump = True
self.speed = 0
self.y = y
# 更新(重力下降)
'''更新(重力下降)'''
def update(self, dt):
self.speed += 10 * dt
self.y -= self.speed
if self.y < -85:
self.reset()
# 重置
'''重置'''
def reset(self):
self.parent.reset()
self.able_jump = False
Expand Down
Loading

0 comments on commit 6bedffa

Please sign in to comment.