0 Members and 1 Guest are viewing this topic.
#import neeeded modulesimport pygameimport mathimport sysimport randomimport binhexfrom pygame.locals import *gravity=0#check to make sure pygame is workingif not pygame.font: print 'Warning, fonts disabled'if not pygame.mixer: print 'Warning, sound disabled'#functions to create our resourcesdef load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', fullname raise SystemExit, message image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0,0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect()def load_sound(name): class NoneSound: def play(self): pass if not pygame.mixer or not pygame.mixer.get_init(): return NoneSound() fullname = os.path.join('data', name) try: sound = pygame.mixer.Sound(fullname) except pygame.error, message: print 'Cannot load sound:', fullname raise SystemExit, message return sound#functions to get the stats for ingame objectsdef getEnemyStats(ID): return {}def getObstacleStats(ID): return {}def getPlayerStats(ID): return {}def getWeaponStats(ID): return {}#function to get all the level datadef getLevel(ID): return {}#function to get the constants for the gamedef getConstants(levelpack): return {}#class for enemiesclass Enemy(pygame.sprite.Sprite): def __init__(self, name, ID): stats=getEnemyStats(ID)#get this enemies stats #define needed variables self.name=name self.ID=ID self.danger=0 self.jump=0 self.gravity=0 self.xvel=0 self.yvel=0 self.area.bottom=599 self.area.right=599 def update(self): if not self.danger or self.jump:#check to see if there is a special situation if stats[speed]:#see if this is a moving enemy and at what speed it would move newpos=self.rect.move((speed,self.gravity)) else: newpos=self.rect.move((0, self.gravity)) elif self.danger:#see if the enemy is in danger self.evade() return 0 elif self.jump:#see if the enemy is jumping newpos=((self.xvel,self.yvel-self.gravity)) self.rect=newpos#move the enemy to its new position #implement the force of gravity def gravity(self): #need a collision detector here if self.rect.bottom>=self.area.bottom: self.downforce=0 self.jump=0 self.change=0 self.rect.bottom=599 else: self.downforce+=1/constants[gravity] #evade danger def evade(): return 0def engine(): return 1def playGame(run): #start set_up while run: clock.tick(constant[speed]) #run game engine engine() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() return elif event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() return if event.type == MOUSEBUTTONDOWN: sets=pygame.mouse.get_pressed() if sets[0]==1: pass elif event.type == KEYDOWN and event.key == K_LEFT: player.left() elif event.type == KEYDOWN and event.key == K_RIGHT: player.right() else: player.still() allsprites.update() #Draw Everything screen.blit(background, (0, 0)) allsprites.draw(screen) pygame.display.flip()def collidedetect(defense,offense): if offense.rect.left<defense.rect.right: if offense.rect.left>defense.rect.left: if offense.rect.top<defense.rect.bottom: if offense.rect.top>defense.rect.top: return 1 elif offense.rect.bottom<defense.rect.bottom: if offense.rect.bottom>defense.rect.top: return 1 elif offense.rect.right>defense.rect.left: if offense.rect.right<defense.rect.right: if offense.rect.top<defense.rect.bottom: if offense.rect.top>defense.rect.top: return 3 elif offense.rect.bottom<defense.rect.botom: if offense.rect.bottom>defense.rect.top: return 3 elif offense.rect.top<defense.rect.bottom: if offense.rect.top>defense.rect.top: if offense.rect.left>defense.rect.left: if offense.rect.left<defense.rect.right: return 2 elif offense.rect.right<defense.rect.right: if offense.rect.right>defense.rect.left: return 2 elif offense.rect.bottom<defense.rect.bottom: if offense.rect.bottom>defense.rect.top: if offense.rect.left>defense.rect.left: if offense.rect.left<defense.rect.right: return 0 elif offense.rect.right<defense.rect.right: if offense.rect.right>defense.rect.left: return 0 else: return 5def main(): run=1 playGame() return 1if __name__ == '__main__': try: levelpack=sys.argv[1]#get the levelpacks name except IndexError: print "need a valid levelpack file or folder" exit(1) constants=getConstants(levelpack)#find out the needed constants main()
/str /Killer /2011-06-27 /enemy /ruler501 /FFBC /end#header with name of enemy date creators name, ID code(random 2 byte integer in hexadecimal)0#class numberKiller#img folder95#health(% of 100)3#jump speed in px/s50#transparency 0-2554#walking speed running speed is just 2x this1#boolean can crouch5#AI level 1 would be perfect evasion if possible
import osimport randomimport datetimename=raw_input("What is your name?")curdate=str(datetime.date.today())def base10toN(num,n): """Change a to a base-n number. Up to base-36 is supported without special notation.""" num_rep={10:'A', 11:'B', 12:'C', 13:'D', 14:'E', 15:'F', 16:'G', 17:'h', 18:'i', 19:'j', 20:'k', 21:'l', 22:'m', 23:'n', 24:'o', 25:'p', 26:'q', 27:'r', 28:'s', 29:'t', 30:'u', 31:'v', 32:'w', 33:'x', 34:'y', 35:'z'} new_num_string='' current=num while current!=0: remainder=current%n if 36>remainder>9: remainder_string=num_rep[remainder] elif remainder>=36: remainder_string='('+str(remainder)+')' else: remainder_string=str(remainder) new_num_string=remainder_string+new_num_string current=current/n return new_num_stringtype=int(raw_input("""what type of file are you making1)weapon2)obstacle3)player4)enemy5)level6)levelpack\n"""))if type==1: wname=raw_input("What is this weapons name? It is a max of 10 characters long\n") if len(name)>10: print "please try doing this again correctly" exit(1) ID=str(base10toN(random.randint(0,65535),16)) header='/str /'+wname+' /'+curdate+' /weapon /'+name+' /'+ID+' /end' wclass=raw_input("What is the class number for this weeapon?0-255\n") folder=raw_input("What is the image folder for this weapon?\n") strength=raw_input("How much damage does this weapon do?\n") type=raw_input("Is this a projectile or beem weapon?p or b\n") if type=='p': projectile=raw_input("What is the folder for the projectiles image?\n") speed=raw_input("how fast does this projectile move?\n") transparency=raw_input("How transparent is the projectile? 0-255\n") ammo='p '+projectile+' '+speed+' '+transparency elif type=="b": width=raw_input("How wide is this beam?\n") speed=raw_input("How fast does the beam move? put 0 for instantaneous movement\n") color=raw_input("What is the hex value of the color of this beam?\n") transparency=raw_input("How transparent is the beam? 0-255\n") ammo='b '+color+' '+width+' '+speed+' '+transparency else: print "Please do this correctly next time" exit(1) aimab=raw_input("How amaible is this weapon? 1-360\n") transparency=raw_input("How transparent is the weapon? 0-255\n") clip=raw_input("How many shots do you have between reloads?\n") time=raw_input("how many frames are there between shots?\n") reload=raw_input("How long does it take to reload(in frames)?\n") usablen=int(raw_input("How many classes is this usable by?\n")) usable='' for i in xrange(0,usablen): usable=usable+' '+raw_input("What is a class this weapon is usable by?\n") file=open('w'+wname, 'w') file.write(header) file.write('\n') file.write(wclass) file.write('\n') file.write(folder) file.write('\n') file.write(strength) file.write('\n') file.write(ammo) file.write('\n') file.write(aimab) file.write('\n') file.write(transparency) file.write('\n') file.write(clip) file.write('\n') file.write(time) file.write('\n') file.write(reload) file.write('\n') file.write(usable) file.close()elif type==2: oname=raw_input("What is this obstacles name? It is a max of 10 characters long\n") if len(name)>10: print "please try doing this again correctly" exit(1) ID=str(base10toN(random.randint(0,65535),16)) header='/str /'+oname+' /'+curdate+' /enemy /'+name+' /'+ID+' /end' imgType=int(raw_input("""Is this obstacle a solid fill or a img file:1)solid fill2)img file\n""")) if imgType==1: hex=raw_input("what is the hex value of the fill color?\n") img="hex "+hex elif imgType==2: folder=raw_input("What is the name of the folder with the image(s)?\n") img="img "+folder else: print "Try putting in a valid number 1 or 2 next time" exit(1) transparency=raw_input("How transparent is this obstacle? 0-255\n") damage=raw_input("How much damage does this obstacle do? 0 if it doesn't do damage\n") slow=raw_input("By what percentage does this slow a player/enemy? 100 if you can't pass through it\n") destroyable=int(raw_input("Can this obstacle be destroyed? 0 or 1\n")) if destroyable==1: health=raw_input("Out of 100% how much damgae can this obstacle take?\n") destruction="1 "+health elif destroyable==0: destruction="0" else: print "Please try to put in a value number 1 or 0 next time" exit(1) gravity=raw_input("Is this obstacle affected by gravity?0 or 1\n") file=open('o'+oname, 'w') file.write(header) file.write('\n') file.write(img) file.write('\n') file.write(transparency) file.write('\n') file.write(damage) file.write('\n') file.write(slow) file.write('\n') file.write(destruction) file.write('\n') file.write(gravity) file.close()elif type==3: pname=raw_input("What is the name for this player? It is a max of 10 characters long\n") if len(pname)>10: print "please try doing this again correctly" exit(1) ID=str(base10toN(random.randint(0,65535),16)) while len(ID)<4: hold='0'+ID ID=hold header='/str /'+pname+' /'+curdate+' /player /'+name+' /'+ID+' /end' pclass=raw_input("What is the class number of this player? from 0-255\n") folder=raw_input("What folder has the images for this player?\n") health=raw_input("How much health does this player have? Out of 100\n") jump=raw_input("How quickly does this player jump?\n") transparency=raw_input("How transparent is this player? 0-255\n") speed=raw_input("How fast is this player?\n") walljump=raw_input("HCan this player walljump? 0 or 1\n") crouch=raw_input("Can this player crouch? 0 or 1\n") file=open('p'+pname, 'w') file.write(header) file.write('\n') file.write(pclass) file.write('\n') file.write(folder) file.write('\n') file.write(health) file.write('\n') file.write(jump) file.write('\n') file.write(transparency) file.write('\n') file.write(speed) file.write('\n') file.write(walljump) file.write('\n') file.write(crouch) file.close()elif type==4: ename=raw_input("What is the name for this enemy? It is a max of 10 characters long\n") if len(ename)>10: print "please try doing this again correctly" exit(1) ID=str(base10toN(random.randint(0,65535),16)) while len(ID)<4: hold='0'+ID ID=hold header='/str /'+ename+' /'+curdate+' /enemy /'+name+' /'+ID+' /end' eclass=raw_input("What is the class number of this enemy? from 0-255\n") folder=raw_input("What is the name of the folder with the images?\n") health=raw_input("How much health does this enemy have out of 100?\n") jump=raw_input("How fast does this enemy jump(px/s) put zero if he can't jump?\n") transparency=raw_input("How transparent is this enemy? 0-255\n") speed=raw_input("How fast does this enemy move(px/f)?\n") crouch=raw_input("Can this unit crouch? 0/1\n") AIlvl=raw_input("how good is this enemies AI? 1=perfect\n") file=open('e'+ename, 'w') file.write(header) file.write('\n') file.write(eclass) file.write('\n') file.write(folder) file.write('\n') file.write(health) file.write('\n') file.write(jump) file.write('\n') file.write(transparency) file.write('\n') file.write(speed) file.write('\n') file.write(crouch) file.write('\n') file.write(AIlvl) file.close()elif type==5: lname=raw_input("What is the name for this enemy? It is a max of 10 characters long\n") if len(lname)>10: print "please try doing this again correctly" exit(1) ID=str(base10toN(random.randint(0,65535),16)) while len(ID)<4: hold='0'+ID ID=hold header='/str /'+lname+' /'+curdate+' /level /'+name+' /'+ID+' /end' startx=raw_input("What is the x value of the starting positions top left?\n") starty=raw_input("What is the y value for the starting positions(higher=lower) top left?\n") start=x+','+y endx=raw_input("What is the x value of the ending positions top left?\n") endy=raw_input("What is the y value of the ending positions(higher=lower) top left?\n") endimage=raw_input("what is the name of the image for the ending position?\n") endtransparency=raw_input("What is the transparency for the ending? 0-255\n") endtime=raw_input("How long do you have to stay on the ending position to win?\n") end= endx+','+endy+' '+endimage+' '+endtransparency+' '+endtime enemyamount=int(raw_input("How many enemies will you need to make?\n")) enemies='' for i in xrange(0,enemyamount): ename=raw_input('What is this enemies name?\n') ex=raw_input("What is the x value of the top left of where this enemy appears?\n") ey=raw_input("What is the y value(higher=lower) of the top left of where this enemy appears?\n") eweapon=raw_input("What is the name of its default weapon?\n") ewclips=raw_input("How many clips does it start with?\n") entrance=int(raw_input("""Does this enemy come in 1)on time 2)randomly 3)by player position\n""")) if entrance==1: etiming=raw_input("HOw many frames into the game should this enemy appear?\n") entry='t '+etiming elif entrance==2: repeat=raw_input("Does this unit appear more than once? 1 or 0\n") entry='r '+repeat elif entrance==3: px=raw_input("When the player gets to what x value does this enemy appear?\n") py=raw_input("When the player gets to what y value does this enemy appear?\n") entry='p '+px+','+py else: print "Please do this correctly next time" exit(1) enemies+=ename+' '+ex+','+ey+' '+eweapon+' '+ewclips+' '+entry+' /' obstacleamount=int(raw_input("How many enemies will you need to make?\n")) obstacle='' for i in xrange(0,obstacleamount): oname=raw_input('What is this obstacles name?\n') ox=raw_input("What is the x value of the top left of where this obstacle appears?\n") oy=raw_input("What is the y value(higher=lower) of the top left of where this obstacle appears?\n") ogravity=raw_input("Is this obstacle affected by gravity?0 or 1\n") randomness=raw_input("Does this obstacle randomly appear throughout the level?\n") obstacle+=oname+' '+ox+','oy+' '+gravity+' '+randomness gravity=raw_input("What is the force of gravity in px's(lower=higher force)?\n") pweapon=raw_input("What is the default weapons name?\n") pwclips=raw_input("How many clips does the default weapon come with?\n") weapon=pweapon+' '+pwclips elif type==6: passelse: print "Try again with a valid number 1-6" exit(1)