Add tower defense game in the Darcap Fun Zone

Submitted by:   Jason Zheng
master
Jason Zheng 2022-01-08 01:21:41 -06:00 committed by Kevin Zheng
parent af0a4b094c
commit 0edce80939
8 changed files with 15578 additions and 7 deletions

View File

@ -8,7 +8,7 @@ enter_x 31
enter_y 16
msg
Created: 2008-07-31 Raphaël Quinet
Modified: 2021-08-01 Andreas Kirschbaum
Modified: 2022-01-09 jason
endmsg
outdoor 1
end
@ -5699,12 +5699,10 @@ x 43
y 4
end
arch perm_magic_portal
name Game Pending
slaying fz_lobby
x 43
y 4
end
arch dust_effect
name Tower Defense
slaying fz_tower_defense
hp 35
sp 21
x 43
y 4
end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,151 @@
import Crossfire
bulletwall = [
'lbulletwall_1',
'lbulletwall_2',
'lbulletwall_3',
'lbulletwall_4',
'lbulletwall_5',
'lbulletwall_6',
'lbulletwall_7',
'lbulletwall_8',
]
lightningwall = [
'lightningwall_1',
'lightningwall_2',
'lightningwall_3',
'lightningwall_4',
'lightningwall_5',
'lightningwall_6',
'lightningwall_7',
'lightningwall_8',
]
firewall = [
'firewall_1',
'firewall_2',
'firewall_3',
'firewall_4',
'firewall_5',
'firewall_6',
'firewall_7',
'firewall_8',
]
def create_tower(player, current_map, tile, builder):
"""
If a builder is dropped on a tower placement tile, a tower is built
player: the player object
current_map: the map object the player is in
tile: all objects on a tile (a list of Crossfire objects)
builder: the tower builder (a Crossfire object)
"""
for ob in tile:
if ob.Name == 'tower placement':
# key/value: builder name/(arch name, spell level)
builders = {
'build large bullet tower': ('lbulletwall_1', 1),
'build lightning tower': ('lightningwall_1', 1),
'build fire tower': ('firewall_1', 40)
}
for name in builders:
if name in builder.Name:
wall = Crossfire.CreateObjectByName(builders[name][0])
wall.Level = builders[name][1]
wall.Teleport(current_map, player.X, player.Y)
player.Teleport(current_map, player.X, player.Y+1)
builder.Quantity -= 1
break
def destroy_tower(tile, towerlist):
"""
If an object in tile exists in towerlist, the object is removed
tile: all objects on a tile (a list of Crossfire objects)
towerlist: bulletwall, firewall, or lightningwall
"""
for ob in tile:
if ob.ArchName in towerlist:
ob.Remove()
def replace_tower(current_map, tile, towerlist, level=0):
"""
If an object in tile exists in towerlist, the object is replaced with the
next direction in towerlist
current_map: the map object the player is in
tile: all objects on a tile (a list of Crossfire objects)
towerlist: bulletwall, firewall, or lightningwall
level: the spell level of the tower
"""
for ob in tile:
if ob.ArchName in towerlist:
position = towerlist.index(ob.ArchName)
x, y = ob.X, ob.Y
if position == len(towerlist)-1:
new_position = 0
else:
new_position = position+1
ob.Remove()
wall = Crossfire.CreateObjectByName(towerlist[new_position])
wall.Teleport(current_map, x, y)
# Add original rebalanced spell level for tower
if level:
wall.Level = level
def player_objects(player, current_map) -> list:
"""
Returns all objects in the direction the player faces
player: the player object
current_map: the map object the player is in
"""
# key/value: crossfire direction number/corresponding (x, y) coordinate
directions = {
Crossfire.Direction.NORTH: (player.X, player.Y-1),
Crossfire.Direction.SOUTH: (player.X, player.Y+1),
Crossfire.Direction.EAST: (player.X+1, player.Y),
Crossfire.Direction.WEST: (player.X-1, player.Y),
Crossfire.Direction.NORTHWEST: (player.X-1, player.Y-1),
Crossfire.Direction.NORTHEAST: (player.X+1, player.Y-1),
Crossfire.Direction.SOUTHWEST: (player.X-1, player.Y+1),
Crossfire.Direction.SOUTHEAST: (player.X+1, player.Y+1)
}
x, y = directions[player.Facing]
tile_ob = []
ob = current_map.ObjectAt(x, y)
while ob:
tile_ob.append(ob)
ob = ob.Above
return tile_ob
def player_tile_objects(player, current_map) -> list:
"""
Returns all objects in the tile the player is standing on
player: the player object
current_map: the map object the player is in
"""
tile_ob = []
ob = current_map.ObjectAt(player.X, player.Y)
while ob:
tile_ob.append(ob)
ob = ob.Above
return tile_ob

View File

@ -0,0 +1,19 @@
import Crossfire
player = Crossfire.WhoIsActivator()
pedestal = Crossfire.WhoAmI()
# key/value: direction player is facing/direction player should be moved
directions = {
Crossfire.Direction.NORTH: Crossfire.Direction.SOUTH,
Crossfire.Direction.SOUTH: Crossfire.Direction.NORTH,
Crossfire.Direction.EAST: Crossfire.Direction.WEST,
Crossfire.Direction.WEST: Crossfire.Direction.EAST,
Crossfire.Direction.NORTHWEST: Crossfire.Direction.SOUTHEAST,
Crossfire.Direction.NORTHEAST: Crossfire.Direction.SOUTHWEST,
Crossfire.Direction.SOUTHWEST: Crossfire.Direction.NORTHEAST,
Crossfire.Direction.SOUTHEAST: Crossfire.Direction.NORTHWEST
}
if player and player.Facing:
player.Move(directions[player.Facing])

View File

@ -0,0 +1,13 @@
import Crossfire
import CFTowerDefense as td
player = Crossfire.WhoIsActivator()
builder = Crossfire.WhoAmI()
current_map = Crossfire.WhoIsActivator().Map
tile = td.player_tile_objects(player, current_map)
Crossfire.SetReturnValue(1)
if tile and current_map.Path == '/darcap/darcap/circus/fz_tower_defense':
td.create_tower(player, current_map, tile, builder)

View File

@ -0,0 +1,21 @@
import Crossfire
private_dict = Crossfire.GetPrivateDictionary()
value = Crossfire.ScriptParameters()
current_map = Crossfire.WhoAmI().Map
if value == 'reset':
private_dict['death'] = 0
else:
private_dict['death'] += 1
# End of wave 1
if private_dict['death'] == 120:
current_map.TriggerConnected(999, 1)
# End of wave 2
elif private_dict['death'] == 240:
current_map.TriggerConnected(1000, 1)
private_dict['death'] = 0
# Crossfire.Log(Crossfire.LogError, f"{private_dict['death']}")

View File

@ -0,0 +1,14 @@
import Crossfire
import CFTowerDefense as td
player = Crossfire.WhoIsActivator()
wrench = Crossfire.WhoAmI()
current_map = Crossfire.WhoIsActivator().Map
tile = td.player_objects(player, current_map)
Crossfire.SetReturnValue(1)
if tile and current_map.Path == '/darcap/darcap/circus/fz_tower_defense':
walls = td.bulletwall+td.firewall+td.lightningwall
td.destroy_tower(tile, walls)

View File

@ -0,0 +1,15 @@
import Crossfire
import CFTowerDefense as td
player = Crossfire.WhoIsActivator()
wrench = Crossfire.WhoAmI()
current_map = Crossfire.WhoIsActivator().Map
tile = td.player_objects(player, current_map)
Crossfire.SetReturnValue(1)
if tile and current_map.Path == '/darcap/darcap/circus/fz_tower_defense':
td.replace_tower(current_map, tile, td.bulletwall)
td.replace_tower(current_map, tile, td.firewall, 40)
td.replace_tower(current_map, tile, td.lightningwall)