4 from scene
import Scene
5 from utils
import Vector
13 self
.id = _entityCounter
17 return "%s(%d)" % (self
.__class__
.__name__
, self
.id)
20 class Physical(Entity
):
21 TYPES
= Entity
.TYPES
+ [Scene
.Types
.DRAWABLE
, Scene
.Types
.PHYSICAL
]
22 def __init__(self
, pos
, walkable
=True):
23 super(Physical
, self
).__init__()
26 self
.walkable
= walkable
28 def addToScene(self
, scene
):
33 def removeFromScene(self
):
34 self
.scene
.remove(self
)
48 TYPES
= Physical
.TYPES
+ [Scene
.Types
.GOODS
]
49 RENDER
= Scene
.Render
.Good
50 def __init__(self
, pos
):
51 super(Good
, self
).__init__(pos
, False)
52 self
.type = Scene
.GoodTypes
.FOOD
57 e
.stats
["life"] += self
.value
58 self
.removeFromScene()
62 TYPES
= Physical
.TYPES
+ [Scene
.Types
.ALIVE
]
63 RENDER
= Scene
.Render
.Bot
64 def __init__(self
, pos
):
65 super(Bot
, self
).__init__(pos
, True)
66 self
.forces
= Vector(0, 0)
67 self
.velocity
= Vector(0, 0)
69 self
.stats
= {"life": 100, "speed": 1}
71 self
.behaviorData
= {}
74 badValues
= [k
for k
, v
in self
.stats
.iteritems() if v
< 0]
76 logging
.debug("%s died by bad genes: %s", self
, badValues
)
78 def addGene(self
, gene
):
79 self
.genes
.append(gene
)
90 self
.name
= self
.__class__
.__name__
92 def modifyStat(self
, entity
, attribute
, value
):
93 stat
= entity
.stats
.setdefault(attribute
, 0)
94 entity
.stats
[attribute
] = stat
+ value
96 def apply(self
, entity
):
100 return "%s" % (self
.name
)
102 class ColorRed(Gene
):
103 def apply(self
, entity
):
104 self
.modifyStat(entity
, "color_red", 25)
106 class ColorGreen(Gene
):
107 def apply(self
, entity
):
108 self
.modifyStat(entity
, "color_green", 25)
110 class ColorBlue(Gene
):
111 def apply(self
, entity
):
112 self
.modifyStat(entity
, "color_blue", 25)
114 class LongLegs(Gene
):
115 def apply(self
, entity
):
116 self
.modifyStat(entity
, "speed", 0.5)
118 class ShortLegs(Gene
):
119 def apply(self
, entity
):
120 self
.modifyStat(entity
, "speed", 0.5)
122 class ClassicBeauty(Gene
):
123 def apply(self
, entity
):
124 self
.modifyStat(entity
, "charisma", 0.5)
126 class ExoticBeauty(Gene
):
127 def apply(self
, entity
):
128 self
.modifyStat(entity
, "charisma", 1)
131 def apply(self
, entity
):
132 self
.modifyStat(entity
, "perception", 2)
136 GENES
= dict(inspect
.getmembers(sys
.modules
[__name__
], lambda member
: inspect
.isclass(member
) and member
.__module__
== __name__
and issubclass(member
, Gene
)))
138 GENE_NAMES
= GENES
.keys()
140 print "Available genes: ", GENE_NAMES