def create_organism(self, organism_creator, x, y): organism_position = Position(x, y) if 50 - organism_creator < 2: self.add_organism_to_world(Antelope(self, organism_position)) elif 50 - organism_creator < 4: self.add_organism_to_world( SosnowskyBorscht(self, organism_position)) elif 50 - organism_creator < 6: self.add_organism_to_world(Guarana(self, organism_position)) elif 50 - organism_creator < 8: self.add_organism_to_world(Fox(self, organism_position)) elif 50 - organism_creator < 9: self.add_organism_to_world(Thistle(self, organism_position)) elif 50 - organism_creator < 13: self.add_organism_to_world(Sheep(self, organism_position)) elif 50 - organism_creator < 17: self.add_organism_to_world(Grass(self, organism_position)) elif 50 - organism_creator < 19: self.add_organism_to_world(WolfBerries(self, organism_position)) elif 50 - organism_creator < 22: self.add_organism_to_world(Wolf(self, organism_position)) elif 50 - organism_creator < 24: self.add_organism_to_world(Turtle(self, organism_position)) elif 50 - organism_creator < 25: self.add_organism_to_world(CyberSheep(self, organism_position))
def create_organism_by_name(self, organism_species, x, y, cooldown=-1): organism_position = Position(x, y) if organism_species == "Antelope": self.add_organism_to_world(Antelope(self, organism_position)) if organism_species == "SosnowskyBorscht": self.add_organism_to_world( SosnowskyBorscht(self, organism_position)) if organism_species == "Guarana": self.add_organism_to_world(Guarana(self, organism_position)) if organism_species == "Fox": self.add_organism_to_world(Fox(self, organism_position)) if organism_species == "Thistle": self.add_organism_to_world(Thistle(self, organism_position)) if organism_species == "Sheep": self.add_organism_to_world(Sheep(self, organism_position)) if organism_species == "Grass": self.add_organism_to_world(Grass(self, organism_position)) if organism_species == "WolfBerries": self.add_organism_to_world(WolfBerries(self, organism_position)) if organism_species == "Wolf": self.add_organism_to_world(Wolf(self, organism_position)) if organism_species == "Turtle": self.add_organism_to_world(Turtle(self, organism_position)) if organism_species == "CyberSheep": self.add_organism_to_world(CyberSheep(self, organism_position)) if organism_species == "Human": self.create_human(organism_position, cooldown)
def createNewOrganism(self, code, posX, posY, world): if (code == 0 or code == 'F'): return Fox(posX, posY, world) elif (code == 1 or code == 'W'): return Wolf(posX, posY, world) elif (code == 2 or code == 'H'): return Human(posX, posY, world) elif (code == 3 or code == 'A'): return Antelope(posX, posY, world) elif (code == 4 or code == 'C'): return CyberSheep(posX, posY, world) elif (code == 5 or code == 'S'): return Sheep(posX, posY, world) elif (code == 6 or code == 'T'): return Turtle(posX, posY, world) elif (code == 7 or code == 'b'): return Belladonna(posX, posY, world) elif (code == 8 or code == 's'): return HeracleumSosnowkyi(posX, posY, world) elif (code == 9 or code == 'o'): return Sonchus(posX, posY, world) elif (code == 10 or code == 'u'): return Guarana(posX, posY, world) elif (code == 11 or code == 'g'): return Grass(posX, posY, world) else: return None
def randSpawn(self): index = 0 isHuman = False for i in range(0, self.height): for j in range(0, self.width): chance = randint(0, 99) if chance < 15: uni = randint(0, 10) if uni == 0: self.organisms[index] = Sheep(self, Point(i, j)) elif uni == 1: self.organisms[index] = Wolf(self, Point(i, j)) elif uni == 2: self.organisms[index] = Fox(self, Point(i, j)) elif uni == 3: self.organisms[index] = Turtle(self, Point(i, j)) elif uni == 4: self.organisms[index] = Antelope(self, Point(i, j)) elif uni == 5: self.organisms[index] = Cybersheep(self, Point(i, j)) elif uni == 6: self.organisms[index] = Grass(self, Point(i, j)) elif uni == 7: self.organisms[index] = Dandelion(self, Point(i, j)) elif uni == 8: self.organisms[index] = Belladonna(self, Point(i, j)) elif uni == 9: self.organisms[index] = Hogweed(self, Point(i, j)) index += 1 elif not isHuman: self.organisms[index] = Human(self, Point(i, j)) isHuman = True index += 1
def loadFile(self): self.organisms = None self.allocOrganisms() savefile = open("savefile.wsf", "r") index = 0 ptr = 0 string = savefile.read().split(' ') while True: if string[ptr] == "END": break typee = string[ptr] ptr += 1 power = int(string[ptr]) ptr += 1 age = int(string[ptr]) ptr += 1 x = int(string[ptr]) ptr += 1 y = int(string[ptr]) ptr += 1 position = Point(x, y) if typee == "Grass": self.organisms[index] = Grass(self, position) elif typee == "Dandelion": self.organisms[index] = Dandelion(self, position) elif typee == "Guarana": self.organisms[index] = Guarana(self, position) elif typee == "Belladonna": self.organisms[index] = Belladonna(self, position) elif typee == "Hogweed": self.organisms[index] = Hogweed(self, position) elif typee == "Wolf": self.organisms[index] = Wolf(self, position) elif typee == "Sheep": self.organisms[index] = Sheep(self, position) elif typee == "Fox": self.organisms[index] = Fox(self, position) elif typee == "Turtle": self.organisms[index] = Turtle(self, position) elif typee == "Antelope": self.organisms[index] = Antelope(self, position) elif typee == "Human": self.organisms[index] = Human(self, position) elif typee == "Cybersheep": self.organisms[index] = Cybersheep(self, position) self.organisms[index].power = power self.organisms[index].age = age index += 1 if savefile is not None: savefile.close()
def turf(self): if (self.climate == "temperate"): for i in range(0, 30): for j in range(0, 45): self.grid[i][j] = Grass(j * 16, i * 16) elif (self.climate == "hot"): for i in range(0, 30): for j in range(0, 45): self.grid[i][j] = Arid_grass(j * 16, i * 16) else: for i in range(0, 30): for j in range(0, 45): self.grid[i][j] = Snow_grass(j * 16, i * 16)
def GenerateSafetyLaneWithDeus(deusPattern=Config.safetyLaneDeusPattern): l = Lane(0, 0, 0, Config.laneTypeSafety) counter = 0 for char in deusPattern: if char == "0": Grass(counter * Config.gridSize, l.y, 50, 50) elif char == "1": LilyDeus(counter * Config.gridSize, l.y, 50, 50) counter += 1 if counter < Config.mapSize - 1: print("Sablon za lejn nije dobar") return l
def Create(self): switcher = { 0 : lambda : Antelope(), 1 : lambda : CyberSheep(), 2 : lambda : Fox(), 3 : lambda : Sheep(), 4 : lambda : Turtle(), 5 : lambda : Wolf(), 6 : lambda : Belladonna(), 7 : lambda : Dandelion(), 8 : lambda : Grass(), 9 : lambda : Guarana(), 10: lambda : HeracleumSosnowskyi(), } func = switcher.get(self.value, None) return func()
def CreateString(s): switcher = { "Antelope" : lambda : Antelope(), "CyberSheep" : lambda : CyberSheep(), "Fox" : lambda : Fox(), "Sheep" : lambda : Sheep(), "Turtle" : lambda : Turtle(), "Wolf" : lambda : Wolf(), "Belladonna" : lambda : Belladonna(), "Dandelion" : lambda : Dandelion(), "Grass" : lambda : Grass(), "Guarana" : lambda : Guarana(), "Heracleum" : lambda : HeracleumSosnowskyi(), "Player" : lambda : Human() } func = switcher.get(s, None) return func()
def CreateChar(t): switcher = { 'A' : lambda : Antelope(), 'C' : lambda : CyberSheep(), 'F' : lambda : Fox(), 'S' : lambda : Sheep(), 'T' : lambda : Turtle(), 'W' : lambda : Wolf(), 'B' : lambda : Belladonna(), 'D' : lambda : Dandelion(), 'G' : lambda : Grass(), 'U' : lambda : Guarana(), 'H' : lambda : HeracleumSosnowskyi(), 'P' : lambda : Human() } func = switcher.get(t, None) return func()
def enter(): global muk muk = Muk() game_world.add_object(muk, 1) global back back = Back() game_world.add_object(back, 0) global grass grass = Grass() game_world.add_object(grass, 0) global monster1, arrow, hurdle_up, hurdle_down monster1 = Monster1() game_world.add_object(monster1, 2) #////////////////////////////////////////////////////////////////////////////////////////////////////////////////// o1 = 1 hurdle_up = [Hurdle_Up() for i in range(10)] for i in hurdle_up: i.x += 700 * o1 o1 += 1 game_world.add_object(i, 2) o2 = 1 hurdle_down = [Hurdle_Down() for i in range(10)] for i in hurdle_down: i.x += 700 * o2 o2 += 1 game_world.add_object(i, 2) #////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global box_up o3 = 1 box_up = [Box_Up() for i in range(10)] for i in box_up: if (o3 % 2 == 0): i.x -= 200 i.y += 700 * o3 o3 += 1 game_world.add_object(i, 2) #////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global thron o4 = 1 thron = [Thorn_Up() for i in range(9)] for i in thron: if (o4 % 2 == 0): i.y -= 100 i.x -= 700 * o4 o4 += 1 game_world.add_object(i, 2) #////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global boss boss = Boss() game_world.add_object(boss, 2) global life life = Life() game_world.add_object(life, 4) global over over = Over() global clear clear = Clear() global start start = Start() game_world.add_object(start, 4)
#!/usr/bin/env python import sys, os sys.path.append(os.path.abspath('../Network')) import LedBurnProtocol as network import time sys.path.append(os.path.abspath('../UIElements')) from Grass import Grass grass = Grass() from HorLineGrassAnimation import HorLineGrassAnimation props = {"on_time_percent": 0.4} animation = HorLineGrassAnimation(grass, props) flower = [0, 0, 0] * 600 sheep = [0, 0, 0] * 302 sign = [0, 0, 0] * 150 speed = 25 # in 50 hrz current_time = 0 frame_id = 0 while True: time_precent = float(current_time) / speed animation.apply(time_precent)
from Position import Position from Sheep import Sheep from Grass import Grass if __name__ == '__main__': grass = Grass(position=Position(10, 10)) sheep = Sheep(position=Position(-10, -10)) for i in range(0, 10): print('-- Iteration {0} --'.format(i)) grass.move() print(grass) sheep.move() print(sheep)
def load_object2(self): self.load = Grass() self.structure = self.load.create_grass_list()
def load_object(self): self.load = Structure() self.structure = self.load.create_structure()
class TestRender: '''This is the class that renders maze. Camera angles are handled by Camera.py. ''' WINDOW_WIDTH = 700 WINDOW_HEIGHT = 700 SCALE = .5 MAP_SIZE =100 X_FACTOR = 1 Y_FACTOR = 1 Z_FACTOR = 1 MAP_SIZE = 100 SEA_LEVEL = 4 def __init__(self): self.set_up_graphics() self.load_object() self.set_up_glut() self.camera = Camera(0,60,0) self.camera.rotate(-75,-150,0) self.poly_view = False self.start_loop() def set_up_glut(self): glutIdleFunc(self.display) glutDisplayFunc(self.display) glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF) glutKeyboardFunc(self.keyPressed) glutKeyboardUpFunc(self.keyUp) glutSetCursor(GLUT_CURSOR_NONE) glutPassiveMotionFunc(self.mouseMove) #glGenLists(50) #glNewList(1, GL_COMPILE) #glNewList(1, GL_COMPILE) def start_loop(self): glutMainLoop() def set_up_graphics(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT) glutCreateWindow('Terrains!') glMatrixMode(GL_PROJECTION) gluPerspective(45,1,.1,500) glMatrixMode(GL_MODELVIEW) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable (GL_BLEND) glClearColor(.529,.8078,.980,0) glEnable(GL_NORMALIZE) glEnable (GL_DEPTH_TEST) #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) def load_object(self): self.load = Structure() self.structure = self.load.create_structure() def load_object2(self): self.load = Grass() self.structure = self.load.create_grass_list() def display(self, x=0, y=0): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() #Put camera and light in the correct position self.camera.move() self.camera.renderRotateCamera() self.camera.renderTranslateCamera() glCallList(self.structure) glDisable(GL_TEXTURE_2D) glutSwapBuffers() def mouseMove(self, x, y): '''Called when the mouse is moved.''' factor = 2 tmp_x = (self.camera.mouse_x - x)/factor tmp_y = (self.camera.mouse_y - y)/factor if tmp_x > self.camera.ROTATE: tmp_x = self.camera.ROTATE self.camera.rotate(tmp_y, tmp_x, 0) x = self.WINDOW_WIDTH/2 y = self.WINDOW_HEIGHT/2 glutWarpPointer(x, y) self.camera.mouse_x = x self.camera.mouse_y = y def keyPressed(self, key, x, y): '''Called when a key is pressed.''' if key.lower() in self.camera.keys: self.camera.keys[key.lower()] = True if glutGetModifiers() == GLUT_ACTIVE_SHIFT: self.camera.keys["shift"] = True if key == 'p' and not self.poly_view: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.poly_view = True elif key == 'p' and self.poly_view: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) self.poly_view = False elif key == 't': exit(0) if key.lower() == 'q': self.camera.WALK *= 1.2 self.camera.SPRINT *= 1.2 if key.lower() == 'e': self.camera.WALK *= .8 self.camera.SPRINT *= .8 def keyUp(self, key, x, y): '''Called when a key is released.''' self.camera.keys[key.lower()] = False if not glutGetModifiers() == GLUT_ACTIVE_SHIFT: self.camera.keys["shift"] = False
#!/usr/bin/env python import sys, os sys.path.append(os.path.abspath('../Network')) import LedBurnProtocol as network import time from operator import itemgetter, attrgetter, methodcaller sys.path.append(os.path.abspath('../UIElements')) from Flower import Flower flower = Flower() from SmallSheep import SmallSheep sheep = SmallSheep() from Grass import Grass grass = Grass() from Sign import Sign sign = Sign() from FireScene import FireScene from RoundRobinScene import RoundRobinScene scene = RoundRobinScene(flower, sheep, grass, sign) speed = 25 # in 50 hrz current_time = 0 frame_id = 0 while True: time_precent = float(current_time) / speed
def main(): print("========================\n" " POKEMON V1.1 \n" "========================\n") while True: action = input("WHAT DO YOU WANT TO DO?\n\n" "[1] SHOW POKEMON\n" "[2] WALK\n" "[3] RESET LOCATION\n" "[4] RESTORE HEALTH\n" "[5] BATTLE\n" "[6] QUIT GAME\n").upper() if action == "1": poke.showPokemon() time.sleep(1.5) elif action == "3": poke.setDefaultPosition() print("LOCATION IS RESET") time.sleep(1.5) elif action == "2": type = ["GRASS", "SAND", "WATER", "CAVE", "MOUNTAIN"] color = ["LIGHT", "DARK"] speed = [1, 2, 3, 2, 1] choiceofspeed = random.choice(speed) env = Grass(random.choice(color), random.choice(type), choiceofspeed) for i in env.showGrass(): print(i) direction = input("INPUT DIRECTION (N/S/E/W): ").upper() distance = int(input("INPUT DISTANCE: ")) time.sleep(choiceofspeed) poke.walk(direction, distance) elif action == "4": print("RESTORING HEALTH...") time.sleep(3) poke.setHP(100) print("HEALTH RESTORED!") print(poke.showName(), "is at 100 HP") print("") time.sleep(1) elif action == "5": print("========================\n" " YOUR OPPONENT \n" "========================\n") time.sleep(0.75) opp.showPokemon() time.sleep(1.5) print("") while True: choice = input("PICK MOVES:" "\n" "SCRATCH" "\n" "TACKLE" "\n" "BITE" "\n" "RUN").upper() if choice == "RUN": chance = random.randrange(0, 2) if chance == 1: print("YOU HAVE ESCAPED SUCESSFULLY!") time.sleep(0.5) break if chance == 0: print("YOU FAILED TO ESCAPE!") time.sleep(0.5) enemy_attack = random.choice(list(opp_moves)) enemy_pick = opp_moves.get(enemy_attack) poke.attack(enemy_pick) print("Your Enemy used", enemy_attack) time.sleep(0.5) print("Damage was", enemy_pick) time.sleep(0.5) print("Your HP is: ") print(poke.showHP()) time.sleep(0.5) else: poke_pick = poke_moves.get(choice) enemy_attack = random.choice(list(opp_moves)) enemy_pick = opp_moves.get(enemy_attack) opp.attack(poke_pick) poke.attack(enemy_pick) print("You Used", choice) time.sleep(0.5) print("Damage was", poke_pick) time.sleep(0.5) print("Your Enemy's HP is: ") print(opp.showHP()) time.sleep(1) print("Your Enemy used", enemy_attack) time.sleep(0.5) print("Damage was", enemy_pick) time.sleep(0.5) print("Your HP is: ") print(poke.showHP()) time.sleep(0.5) if (opp.showHP()) < 0: print("CHARIZARD WON!") print("") time.sleep(2) break if (poke.showHP()) < 0: print("CHARIZARD FAINTED!") print("") time.sleep(2) break if action == "6": print("SAVING GAME...") time.sleep(1.5) print("========================\n" " GAMEFREAK \n" "========================\n") time.sleep(1.5) break
def build(key): if key[0] == "G": if len(key) > 1: return Grass(key[1]) else: return Grass(None) if key[0] == "M": if len(key) > 1: return Mountain(key[1]) else: return Mountain(None) if key[0] == "F": if len(key) > 1: return Forest(key[1]) else: return Forest(None) if key[0] == "W": if len(key) > 1: return Wall(key[1]) else: return Wall(None) if key[0] == "~": if len(key) > 1: return Water(key[1]) else: return Water(None) if key[0] == "S": if len(key) > 1: return Sand(key[1]) else: return Sand(None) if key[0] == "E": if len(key) > 1: return MetalWall(key[1]) else: return MetalWall(None) if key[0] == "T": if len(key) > 1: return MetalFloor(key[1]) else: return MetalFloor(None) if key[0] == "P": if len(key) > 1: return Plating(key[1]) else: return Plating(None) if key[0] == ".": if len(key) > 1: return Void(key[1]) else: return Void(None) if key[0] == "O": if len(key) > 1: return WoodFloor(key[1]) else: return WoodFloor(None) if key[0] == "L": if len(key) > 1: return WoodFloorDam(key[1]) else: return WoodFloorDam(None) if key[0] == "B": if len(key) > 1: return Bridge(key[1]) else: return Bridge(None) if key[0] == "-": if len(key) > 1: return BridgeTop(key[1]) else: return BridgeTop(None) if key[0] == "+": if len(key) > 1: return BridgeBot(key[1]) else: return BridgeBot(None)
def addGrass(self): for i in range(0, self.gridWidth): for j in range(0, self.gridHeight): if self.checkIfPositionIsEmpty([i, j]): element = Grass(i, j) self.mapElements.append(element)