I kind of disagree with bluesocarrot. (go Australia!)
Writing 300 line scripts for every unit is silly, id say 4 scripts for all the units, ground units water units air units and buildings.
and you just run an instance of the script.
I’m not too crash hot with python methods and classes, but heres a basic idea.
All the unit info is stored in this set and can be retrieved using data = Data.new, data.buildings(0) to retrieve the barracks.
The array for buildings is [ID, object name, object type (like 1 unit production or 2 attacking building), hp, units that can be built from it, attack range, attack.
The array for units is [ID, object name, hp, type 0 = ground 1 = water 2 = air, hp, attack range, attack.
So here, a barracks can build infantry and rocketers.
class Data:
def __inti__:
buildings_data = [[0, "barracks", 1, 200, [0, 1], 0, 0],[1, "watch tower", 2, 120, 0, 8, 12]]
units_data = [[0, "infantry", 0, 50, 5, 8],[1, "rocketer", 50, 5, 15]]
buildings = []
units = []
retrieve_data(type, id=0):
if (type == 0):
return buildings_data(id)
elif (type == 1):
return units_data(id)
elif (type == 2):
return buildings
elif (type == 3):
return units
def append(type, data):
if (type == 0):
buildings.append(data)
else:
units.append(data)
This is the class for buildings
class Building:
def __init__(id, object, owner, unit_status, hp):
Game_Logic.data.append(id, object, unit_staus, hp)
current_status = 0
def id:
return id
def object:
return object
def owner:
return owner
def unit_status:
return unit_status
def hp:
return hp
def current_status:
return current_staus
def idle?:
if (current_status == 0):
return True
else:
return False
def building?:
def attacking?:
if (current_status == 1):
return True
else:
return False
def attacking?:
if (current_status == 2):
return True
else:
return False
and for the actual building
id = len(Game_Logic.data.retrieve_data(0))
properties = Building.new(id ,"baracks", 2, 1, [200,200])
This way our 100 units with 300 line scripts each gets reduced 100 units with 10 line scripts and 6 300 line scripts.
Well, now that I got that out of the way, it looks good anicator. Are you planning on making a game out of the this?