我正在用 pygame 制作游戏并练习 OOP。我读过一个 pygame 教程,因为我的游戏有点不同,所以我只采用了我需要的部分,例如移动、pygame.init() 等。当我运行脚本时,没有任何错误只是pygame 欢迎信息。我已经检查过我是否真的添加了代码行来启动程序并且我确实添加了。我还检查了我是否制作了屏幕,我也这样做了。
1 import pygame
2 from pygame.locals import *
3
4 class character:
5 def __init__(self, Name, Picture, Attack1, WaitAttack1, Attack2, WaitAttack2, Heal1, WaitHeal1, SuperAttack1, WaitSuperAttack1):
6 self.Name = Name
7 self.Player = pygame.image.load(Picture)
8 self.Coins = 0
9 self.Backpack = "Empty"
10 self.WorldMap = "Comming soon"
11 self.Health = 250
12 self.Attack1 = Attack1
13 self.WaitAttack1 = WaitAttack1
14 self.Attack2 = Attack2
15 self.WaitAttack2 = WaitAttack2
16 self.Heal1 = Heal1
17 self.WaitHeal1 = WaitHeal1
18 self.SuperAttack1 = SuperAttack1
19 self.WaitSuperAttack1 = WaitSuperAttack1
20 self.Keys = [False, False, False, False]
21 self.playerpos = [100,100]
22
23 def directions(self):
24
25 if self.Keys[0]:
26 self.playerpos[1] -= 5
27 elif self.Keys[2]:
28 self.playerpos[1] += 5
29 if self.Keys[1]:
30 self.playerpos[0] -= 5
31 elif self.Keys[3]:
32 self.playerpos[0] += 5
33
34
35
36 class Slade(character):
37 def __init__(self): 38 character.__init__(self, "Slade", "Slade.png", 40, 20, 50, 25, 10, 5, 30, 25)
PS:我是 OOP 的新手。所以请尽量忽略我的代码很糟糕的事实。
海绵宝宝撒
幕布斯6054654
相关分类