Skip to content

Commit

Permalink
add game26 i.e. angry birds
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesPikachu committed May 15, 2021
1 parent d506d74 commit e5c3bf3
Show file tree
Hide file tree
Showing 22 changed files with 1,184 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Game26/Game26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'''
Function:
愤怒的小鸟小游戏
Author:
Charles
微信公众号:
Charles的皮卡丘
'''
import sys
import cfg
import pygame
from modules import *


'''游戏主程序'''
def main(cfg):
# 初始化
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(cfg.BGMPATH)
pygame.mixer.music.play(-1, 0.0)
screen = pygame.display.set_mode(cfg.SCREENSIZE)
pygame.display.set_caption('Angry Birds —— Charles的皮卡丘')
# 开始游戏
def startgame():
game_levels = GameLevels(cfg, screen)
game_levels.start()
# 退出游戏
def quitgame():
pygame.quit()
sys.exit()
# 开始界面
components = pygame.sprite.Group()
title_label = Label(screen, 700, 100, 400, 200)
title_label.addtext('ANGRY BIRDS', 80, cfg.FONTPATH['arfmoochikncheez'], (236, 240, 241))
components.add(title_label)
start_btn = Button(screen, 500, 400, 300, 100, startgame, (244, 208, 63), (247, 220, 111))
start_btn.addtext('START GAME', 60, cfg.FONTPATH['arfmoochikncheez'], cfg.BACKGROUND_COLOR)
components.add(start_btn)
quit_btn = Button(screen, 1000, 400, 300, 100, quitgame, (241, 148, 138), (245, 183, 177))
quit_btn.addtext('QUIT', 60, cfg.FONTPATH['arfmoochikncheez'], cfg.BACKGROUND_COLOR)
components.add(quit_btn)
mandav_label = Label(screen, cfg.SCREENSIZE[0] - 300, cfg.SCREENSIZE[1] - 80, 300, 100)
mandav_label.addtext('MANDAV', 60, cfg.FONTPATH['arfmoochikncheez'], (41, 41, 41))
components.add(mandav_label)
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitgame()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
quitgame()
elif event.type == pygame.MOUSEBUTTONDOWN:
if start_btn.selected():
start_btn.action()
elif quit_btn.selected():
quit_btn.action()
screen.fill(cfg.BACKGROUND_COLOR)
for component in components: component.draw()
pygame.display.update()
clock.tick(cfg.FPS)


'''run'''
if __name__ == '__main__':
main(cfg)
19 changes: 19 additions & 0 deletions Game26/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Introduction


# Environment
```
OS: Windows10
Python: Python3.5+(have installed necessary dependencies)
```

# Usage
```
Step1:
pip install -r requirements.txt
Step2:
run "python Game26.py"
```

# Game Display
![giphy](demonstration/running.gif)
36 changes: 36 additions & 0 deletions Game26/cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'''配置文件'''
import os


'''图片路径'''
IMAGEPATHS = {
'pig': [
os.path.join(os.getcwd(), 'resources/images/pig_1.png'),
os.path.join(os.getcwd(), 'resources/images/pig_2.png'),
os.path.join(os.getcwd(), 'resources/images/pig_damaged.png'),
],
'bird': [
os.path.join(os.getcwd(), 'resources/images/bird.png'),
],
'wall': [
os.path.join(os.getcwd(), 'resources/images/wall_horizontal.png'),
os.path.join(os.getcwd(), 'resources/images/wall_vertical.png'),
],
'block': [
os.path.join(os.getcwd(), 'resources/images/block.png'),
os.path.join(os.getcwd(), 'resources/images/block_destroyed.png'),
]
}
'''字体路径'''
FONTPATH = {
'Comic_Kings': os.path.join(os.getcwd(), 'resources/fonts/Comic_Kings.ttf'),
'arfmoochikncheez': os.path.join(os.getcwd(), 'resources/fonts/arfmoochikncheez.ttf'),
}
'''背景音乐路径'''
BGMPATH = os.path.join(os.getcwd(), 'resources/audios/bgm.ogg')
'''屏幕大小'''
SCREENSIZE = (1800, 700)
'''fps'''
FPS = 60
'''一些颜色定义'''
BACKGROUND_COLOR = (51, 51, 51)
Binary file added Game26/demonstration/running.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Game26/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''initialize'''
from .sprites import *
from .gamelevels import *
698 changes: 698 additions & 0 deletions Game26/modules/gamelevels.py

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Game26/modules/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'''
Function:
定义工具函数
Author:
Charles
微信公众号:
Charles的皮卡丘
'''
import math


'''定义速度向量'''
class VelocityVector():
def __init__(self, magnitude=0, angle=math.radians(0)):
self.angle = angle
self.magnitude = magnitude


'''向量相加'''
def VectorAddition(vector1, vector2):
x = math.sin(vector1.angle) * vector1.magnitude + math.sin(vector2.angle) * vector2.magnitude
y = math.cos(vector1.angle) * vector1.magnitude + math.cos(vector2.angle) * vector2.magnitude
angle = 0.5 * math.pi - math.atan2(y, x)
magnitude = math.hypot(x, y)
return VelocityVector(magnitude, angle)
Loading

0 comments on commit e5c3bf3

Please sign in to comment.