Skip to content

Commit dea42ce

Browse files
committed
PyShootGame源码
第一次提交,简单的飞机游戏源码。还在完善中。。。
0 parents  commit dea42ce

24 files changed

+646
-0
lines changed

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
131+
# NuGet Packages Directory
132+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133+
#packages/
134+
135+
# Windows Azure Build Output
136+
csx
137+
*.build.csdef
138+
139+
# Windows Store app package directory
140+
AppPackages/
141+
142+
# Others
143+
sql/
144+
*.Cache
145+
ClientBin/
146+
[Ss]tyle[Cc]op.*
147+
~$*
148+
*~
149+
*.dbmdl
150+
*.[Pp]ublish.xml
151+
*.pfx
152+
*.publishsettings
153+
154+
# RIA/Silverlight projects
155+
Generated_Code/
156+
157+
# Backup & report files from converting an old project file to a newer
158+
# Visual Studio version. Backup files are not needed, because we have git ;-)
159+
_UpgradeReport_Files/
160+
Backup*/
161+
UpgradeLog*.XML
162+
UpgradeLog*.htm
163+
164+
# SQL Server files
165+
App_Data/*.mdf
166+
App_Data/*.ldf
167+
168+
#############
169+
## Windows detritus
170+
#############
171+
172+
# Windows image file caches
173+
Thumbs.db
174+
ehthumbs.db
175+
176+
# Folder config file
177+
Desktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Mac crap
183+
.DS_Store
184+
185+
186+
#############
187+
## Python
188+
#############
189+
190+
*.py[co]
191+
192+
# Packages
193+
*.egg
194+
*.egg-info
195+
dist/
196+
build/
197+
eggs/
198+
parts/
199+
var/
200+
sdist/
201+
develop-eggs/
202+
.installed.cfg
203+
204+
# Installer logs
205+
pip-log.txt
206+
207+
# Unit test / coverage reports
208+
.coverage
209+
.tox
210+
211+
#Translations
212+
*.mo
213+
214+
#Mr Developer
215+
.mr.developer.cfg

gameRole.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Sep 11 16:36:03 2013
4+
5+
@author: Leo
6+
"""
7+
8+
import pygame
9+
10+
SCREEN_WIDTH = 480
11+
SCREEN_HEIGHT = 800
12+
13+
class Player(pygame.sprite.Sprite):
14+
def __init__(self, planeImg, clip_rect, init_pos):
15+
pygame.sprite.Sprite.__init__(self)
16+
self.image = []
17+
for i in range(len(clip_rect)):
18+
self.image.append(planeImg.subsurface(clip_rect[i]).convert_alpha())
19+
self.rect = clip_rect[0]
20+
self.rect.topleft = init_pos
21+
self.speed = 1
22+
23+
def moveUp(self):
24+
if self.rect.top <= 0:
25+
self.rect.top = 0
26+
else:
27+
self.rect.top -= self.speed
28+
29+
def moveDown(self):
30+
if self.rect.top > SCREEN_HEIGHT - self.rect.height:
31+
self.rect.top = SCREEN_HEIGHT - self.rect.height
32+
else:
33+
self.rect.top += self.speed
34+
35+
def moveLeft(self):
36+
if self.rect.left < 0:
37+
self.rect.left = 0
38+
else:
39+
self.rect.left -= self.speed
40+
41+
def moveRight(self):
42+
if self.rect.left > SCREEN_WIDTH - self.rect.width:
43+
self.rect.left = SCREEN_WIDTH - self.rect.width
44+
else:
45+
self.rect.left += self.speed

mainGame.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Sep 11 11:05:00 2013
4+
5+
@author: Leo
6+
"""
7+
8+
import pygame
9+
from sys import exit
10+
from pygame.locals import *
11+
from gameRole import *
12+
13+
# 初始化游戏
14+
pygame.init()
15+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
16+
pygame.display.set_caption('飞机大战')
17+
18+
# 载入背景图
19+
background = pygame.image.load('resources/image/background.png').convert()
20+
21+
# 设置玩家相关参数
22+
player_rect = []
23+
player_rect.append(pygame.Rect(0, 99, 102, 126))
24+
player_rect.append(pygame.Rect(165, 360, 102, 126))
25+
player_pos = [200, 600]
26+
filename = 'resources/image/shoot.png'
27+
28+
planeImg = pygame.image.load(filename)
29+
player = Player(planeImg, player_rect, player_pos)
30+
31+
player_img_index = 0
32+
33+
while 1:
34+
screen.fill(0)
35+
screen.blit(background, (0,0))
36+
screen.blit(player.image[player_img_index], player.rect)
37+
if player_img_index == 0:
38+
player_img_index = 1
39+
else:
40+
player_img_index = 0
41+
pygame.display.flip()
42+
for event in pygame.event.get():
43+
if event.type == pygame.QUIT:
44+
pygame.quit()
45+
exit()
46+
47+
48+
key_pressed = pygame.key.get_pressed()
49+
if key_pressed[K_w]:
50+
player.moveUp()
51+
if key_pressed[K_s]:
52+
player.moveDown()
53+
if key_pressed[K_a]:
54+
player.moveLeft()
55+
if key_pressed[K_d]:
56+
player.moveRight()
57+

resources/font/font.fnt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
info face="Deeko Comic Regular" size=40 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=0,0
2+
common lineHeight=26 base=27 scaleW=512 scaleH=512 pages=1 packed=0
3+
page id=0 file="font.png"
4+
chars count=11
5+
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=27 xadvance=12 page=0 chnl=0
6+
char id=52 x=0 y=0 width=30 height=40 xoffset=1 yoffset=-7 xadvance=30 page=0 chnl=0
7+
char id=51 x=30 y=0 width=27 height=38 xoffset=1 yoffset=-5 xadvance=27 page=0 chnl=0
8+
char id=88 x=57 y=0 width=30 height=34 xoffset=1 yoffset=-5 xadvance=30 page=0 chnl=0
9+
char id=56 x=87 y=0 width=33 height=34 xoffset=1 yoffset=-7 xadvance=34 page=0 chnl=0
10+
char id=57 x=120 y=0 width=30 height=33 xoffset=1 yoffset=-4 xadvance=30 page=0 chnl=0
11+
char id=50 x=150 y=0 width=29 height=33 xoffset=1 yoffset=-3 xadvance=30 page=0 chnl=0
12+
char id=48 x=179 y=0 width=27 height=31 xoffset=1 yoffset=-3 xadvance=28 page=0 chnl=0
13+
char id=54 x=206 y=0 width=31 height=31 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=0
14+
char id=53 x=237 y=0 width=35 height=31 xoffset=1 yoffset=0 xadvance=36 page=0 chnl=0
15+
char id=49 x=272 y=0 width=6 height=31 xoffset=1 yoffset=-5 xadvance=7 page=0 chnl=0
16+
char id=55 x=278 y=0 width=33 height=30 xoffset=1 yoffset=-1 xadvance=34 page=0 chnl=0
17+
kernings count=-1

resources/font/font.png

5.07 KB
Loading

resources/image/background.png

32.7 KB
Loading

0 commit comments

Comments
 (0)