Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripting|libdoomsday: Added the "commonlib" module
libdoomsday has a script module called "commonlib" for common game-related functions. commonlib defines the following methods: - World.Thing.info() - World.Thing.dropItem()
- Loading branch information
Showing
3 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
doomsday/apps/libdoomsday/net.dengine.base.pack/modules/commonlib.ds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Additional functions for games | ||
|
||
import World, Math, Defs | ||
|
||
def World.Thing.info() | ||
return Defs.things.order[self.type()] | ||
end | ||
|
||
def World.Thing.dropItem(type, force=1.0, lift=0.0, height=0.5, prob=1.0) | ||
# Spawns an item at the position of the thing. | ||
# - type: Thing ID of the dropped item (Text). | ||
# - force: XY momentum of the dropped item (random direction). | ||
# - lift: Z momentum of the dropped item. | ||
# - height: spawn position Z offset. | ||
# - prob: chance of dropping (1.0 is 100% certainty). | ||
# Returns the dropped item, or None. | ||
if Math.random() > prob: return None | ||
pos = self.pos() | ||
pos[2] = pos[2] + height * self.height() | ||
item = World.spawnThing(type, pos) | ||
if item | ||
# Throw the item a little bit. | ||
angle = 2 * Pi * Math.random() | ||
mom = [force * Math.cos(angle), force * Math.sin(angle), lift] | ||
item.addMom(mom) | ||
end | ||
return item | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters