How to use load_images method in Airtest

Best Python code snippet using Airtest

threades.py

Source:threades.py Github

copy

Full Screen

1#! /usr/bin/env python2#3# Author : Mohit Taneja (mohitgenii@gmail.com)4# Date : 9/06/2008 5#6# This program is free software; you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation; either version 2 of the License, or9# (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program; if not, write to the Free Software18# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19#20#from model import *21import model22import Exceptions 23import threading 24import random 25from time import sleep,time,ctime26#import texts_spa27#import texts_eng28# import statements for animation classes29import pygame30import os31from pygame.locals import *32pygame.init()33pygame.mixer.init()34#from load_images import *35import game_events36import load_images37import pickle38import glob39from texts_spa import setup_text, upgrade_fac_text, buysell_exceptions, setup_fac_exceptions, upgrade_fac_exceptions, fac_running_exceptions, setup_format_text, upgrade_format_text40from texts_eng import setup_text, upgrade_fac_text, buysell_exceptions, setup_fac_exceptions, upgrade_fac_exceptions, fac_running_exceptions, setup_format_text, upgrade_format_text41#import proceduralFlow42original_screen_size = [1200.0,900.0]43import gui44#from gui import *45import defaultStyle46pygame.display.init()47try:48 display_info = pygame.display.Info()49 new_screen_size = [display_info.current_w,display_info.current_h]50 51except:52 53 new_screen_size = [800,600]54 55#new_screen_size = [800,600]56global screen 57if model.FLAG_XO:58 global screen59 new_screen_size[1] -= 80.0/900.0*new_screen_size[1]60 screen = pygame.display.set_mode(new_screen_size,SRCALPHA,32)61else:62 63 screen = pygame.display.set_mode(new_screen_size,FULLSCREEN|SRCALPHA,32)64 #screen = pygame.display.set_mode(new_screen_size,SRCALPHA,32)65defaultStyle.init(gui)66desktop = gui.Desktop()67###### FLAGS ####68GAME_EXIT_FLAG = False69# Facility placement flag70buildFacilityPlacementFlag = ""71# Level start Facility build flag 72levelStartFacilityBuildFlag = 073levelStartUpdateFlag = True74#Screen Initialization Flags75total_update_flag = True76panel_update_flag = True77map_update_flag = True78top_update_flag = True79facilities_update_flag = True 80game_save_flag = False81PLACING_LIST_TEMP = []82current_level = 083SOUND_PATH = os.path.join('sounds','effects')84SOUND_VOLUME = [1,1] #max Vol is [1,1] i.e [left,right]85def initialize_facilities(autobuild_flag = True):86 87 model.ppl.change_total_population(1000)88 global levelStartFacilityBuildFlag89 global levelStartUpdateFlag90 levelStartUpdateFlag = False91 global PLACING_LIST_TEMP92 PLACING_DATA_LIST = PLACING_LIST_TEMP93 new_list = []94 HOUSE_NO = model.INIT_HOUSE95 HOSP_NO = model.INIT_HOSPITAL96 SCHOOL_NO = model.INIT_SCHOOL97 FARM_NO = model.INIT_FARM98 FOUNTAIN_NO = model.INIT_FOUNTAIN99 WORKS_NO = model.INIT_WORKSHOP100 101 102 for i in range(len(PLACING_DATA_LIST)):103 if PLACING_DATA_LIST[i][0] == 'HOUSE' and HOUSE_NO>0:104 build_facility(model.House,PLACING_DATA_LIST = PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)105 HOUSE_NO = HOUSE_NO -1106 levelStartFacilityBuildFlag +=1107 new_list.append(PLACING_DATA_LIST[i])108 109 if PLACING_DATA_LIST[i][0] == 'HOSPITAL' and HOSP_NO>0:110 build_facility(model.Hospital,PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)111 HOSP_NO = HOSP_NO -1112 levelStartFacilityBuildFlag +=1113 new_list.append(PLACING_DATA_LIST[i])114 115 if PLACING_DATA_LIST[i][0] == 'SCHOOL' and SCHOOL_NO>0:116 build_facility(model.School,PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)117 SCHOOL_NO = SCHOOL_NO -1118 levelStartFacilityBuildFlag +=1119 new_list.append(PLACING_DATA_LIST[i])120 121 if PLACING_DATA_LIST[i][0] == 'FARM' and FARM_NO>0:122 build_facility(model.Farm,PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)123 FARM_NO = FARM_NO -1124 levelStartFacilityBuildFlag +=1125 new_list.append(PLACING_DATA_LIST[i])126 127 if PLACING_DATA_LIST[i][0] == 'FOUNTAIN' and FOUNTAIN_NO>0:128 build_facility(model.Fountain,PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)129 FOUNTAIN_NO = FOUNTAIN_NO -1130 levelStartFacilityBuildFlag +=1131 new_list.append(PLACING_DATA_LIST[i])132 133 if PLACING_DATA_LIST[i][0] == 'WORKSHOP' and WORKS_NO>0:134 build_facility(model.Workshop,PLACING_DATA_LIST[i], autobuild_flag = autobuild_flag)135 WORKS_NO = WORKS_NO -1136 levelStartFacilityBuildFlag +=1137 new_list.append(PLACING_DATA_LIST[i])138 139 #reload_placing_data_list()140 model.ppl.change_total_population(-1000)141 142 PLACING_LIST_TEMP = new_list143 transform_obj.focus_at((1000,2000))144 transform_obj.set_ratio(0.5)145 calculate_indicators_starting()146# A Switch for pausing the update thread147update_thread_pause = True148''' Utility Functions '''149def stop_facility(facility_obj,name_res = ''):150 ''' Thread to stop a facility it resumes the facility when the village151 has enough model.resources to run the facility152 '''153 text = fac_running_exceptions['insufficient_res']%{'facility':model.FACILITY_NAMES[facility_obj.get_name()],'resource':str(name_res).lower()}154 message.push_message(text,'high')155 event = game_events.Event(type = game_events.STOPFACILITYEVENT, facility_name = facility_obj.get_name())156 game_events.EventQueue.add(event)157 res_cost = facility_obj.get_consumption()158 facility_obj.stop_facility()159 a=1160 while True:161 a=0162 for i in range(len(model.resources)):163 name = model.resources[i].get_name()164 if res_cost.has_key(name):165 if model.resources[i].get_vquantity() < res_cost[name]:166 a=1167 if a==0:168 break169 if GAME_EXIT_FLAG:170 return171 sleep(1)172 if GAME_EXIT_FLAG:173 return174 sleep(1)175 if GAME_EXIT_FLAG:176 return177 178 facility_obj.resume_facility()179 text = fac_running_exceptions['resume']%{'facility':model.FACILITY_NAMES[facility_obj.get_name()]}180 message.push_message(text,'low')181 event = game_events.Event(type = game_events.RESUMEFACILITYEVENT, facility_name = facility_obj.get_name())182 game_events.EventQueue.add(event)183 184def get_setup_text(facility_obj):185 186 ty = model.text_file.setup_format_text[0]187 188 _name_dic = {'WATER':model.text_file.list_gen_res[0]189 ,'BUILDING MATERIAL':model.text_file.list_gen_res[1]190 ,'TOOLS':model.text_file.list_gen_res[2]191 ,'MEDICINE':model.text_file.list_gen_res[3]192 ,'BOOKS':model.text_file.list_gen_res[4]193 ,'HOUSE':model.text_file.facilities_list[0]194 ,'HOSPITAL':model.text_file.facilities_list[1]195 ,'WORKSHOP':model.text_file.facilities_list[2]196 ,'SCHOOL':model.text_file.facilities_list[3]197 ,'FOUNTAIN':model.text_file.facilities_list[4]198 ,'FARM':model.text_file.facilities_list[5]199 }200 201 202 facility=_name_dic[str(facility_obj.get_name())]203 number = str(int(facility_obj.get_original_number()))204 costbuild = facility_obj.get_cost_build() or model.text_file.resources_text[1]205 costrun = facility_obj.get_cons_dict() or model.text_file.resources_text[1]206 manbuild = str(int(model.FACILITY_MANP_DICT_BUILD[facility_obj.get_name()]['EMPLOYED PEOPLE IN CONSTRUCTION']))207 try:208 manrun = model.FACILITY_MANP_DICT_RUN[facility_obj.get_name()]['EMPLOYED PEOPLE IN %(facility)s'%{'facility':facility}]209 except:210 manrun = '0'211 rem_build_mat = int(model.resources[1].get_vquantity()) - int(costbuild['BUILDING MATERIAL'])212 rem_tools = int(model.resources[2].get_vquantity()) - int(costbuild['TOOLS'])213 rem_water = int(model.resources[0].get_vquantity()) - int(costbuild['WATER'])214 215 if rem_build_mat < 0:216 resafter = model.text_file.setup_fac_exceptions['low_resource']%{'resource':'bricks'}217 elif rem_tools < 0:218 resafter = model.text_file.setup_fac_exceptions['low_resource']%{'resource':'tools'}219 elif rem_water < 0:220 resafter = model.text_file.setup_fac_exceptions['low_resource']%{'resource':'water'}221 else:222 resafter = model.text_file.list_gen_res[1]+':'+ str(rem_build_mat)+ model.text_file.list_gen_res[2]+':'+str(rem_tools)+model.text_file.list_gen_res[0]+':'+str(rem_water)223 224 strcostbuild = ''225 strcostrun = ''226 227 228 if type(costbuild) != str:229 for cost in costbuild.iteritems():230 strcostbuild+=' '+str(cost[1]).lower()+' '+str(_name_dic[cost[0]])231 else:232 strcostbuild=costbuild233 if type(costrun) != str:234 for cost in costrun.iteritems():235 strcostrun+=' '+str(cost[1]).lower()+' '+str(_name_dic[cost[0]])236 else:237 strcostrun=costrun238 239 return ty%{'facility':facility,'number':number,'costbuild':strcostbuild,'costrun':strcostrun,'manbuild':manbuild,'manrun':manrun,'resafter':resafter}240def get_upgrade_text(facility_obj):241 242 ty = model.text_file.upgrade_format_text[0]243 244 _name_dic = {'WATER':model.text_file.list_gen_res[0]245 ,'BUILDING MATERIAL':model.text_file.list_gen_res[1]246 ,'TOOLS':model.text_file.list_gen_res[2]247 ,'MEDICINE':model.text_file.list_gen_res[3]248 ,'BOOKS':model.text_file.list_gen_res[4]249 ,'HOUSE':model.text_file.facilities_list[0]250 ,'HOSPITAL':model.text_file.facilities_list[1]251 ,'WORKSHOP':model.text_file.facilities_list[2]252 ,'SCHOOL':model.text_file.facilities_list[3]253 ,'FOUNTAIN':model.text_file.facilities_list[4]254 ,'FARM':model.text_file.facilities_list[5]255 }256 try:257 assert (facility_obj.get_level()<3)258 text = model.text_file.upgrade_text[facility_obj.get_name()][facility_obj.get_level()]259 facility=_name_dic[facility_obj.get_name()]260 number = str(int(facility_obj.get_original_number()))261 cost_upgrade = facility_obj.get_cost_inc_level()262 rem_build_mat = int(model.resources[1].get_vquantity()) - int(cost_upgrade['BUILDING MATERIAL'])263 rem_tools = int(model.resources[2].get_vquantity()) - int(cost_upgrade['TOOLS'])264 if rem_build_mat < 0:265 resafter = model.text_file.setup_fac_exceptions['low_resource']%{'resource':'bricks'}266 if rem_tools < 0 :267 resafter = model.text_file.setup_fac_exceptions['low_resource']%{'resource':'tools'}268 else:269 resafter = model.text_file.list_gen_res[1]+':'+ str(rem_build_mat)+ model.text_file.list_gen_res[2]+':'+str(rem_tools)270 strcostupgrade=''271 272 for cost in cost_upgrade.iteritems():273 strcostupgrade+=' '+str(cost[1])+' '+_name_dic[str(cost[0])]274 except:275 resafter=model.text_file.upgrade_fac_exceptions['max_level']276 return resafter277 278 return ty%{'text':text,'number':number,'facility':facility,'costupgrade':strcostupgrade,'resafter':resafter}279def set_build_facility_placement_flag(facility_obj = None):280 global buildFacilityPlacementFlag281 if facility_obj:282 buildFacilityPlacementFlag = facility_obj.get_name()283 else :284 buildFacilityPlacementFlag = ""285 286def build_placed_facility(facility_name, autobuild_flag, PLACING_DATA_LIST):287 '''Builds the placed facility according to placed position288 Args:289 facility_obj: The to be built facility object290 place_facility_thread: Thread for placing facility291 '''292 global PLACING_LIST_TEMP293 PLACING_LIST_TEMP.append(PLACING_DATA_LIST)294 295 facility_name = PLACING_DATA_LIST[0]296 rect_obj = PLACING_DATA_LIST[1]297 298 place_pos_x = rect_obj[0]299 place_pos_y = rect_obj[1]300 301 if autobuild_flag == False:302 audio.play_sound('build') 303 304 if facility_name == 'HOUSE':305 images_obj.initialize_facility('HOUSE')306 sprite = House_sprite((place_pos_x,place_pos_y))307 model.house_sprite_list.append(sprite)308 309 if facility_name == 'HOSPITAL':310 images_obj.initialize_facility('HOSPITAL')311 sprite = Hospital_sprite((place_pos_x,place_pos_y))312 model.hospital_sprite_list.append(sprite)313 314 if facility_name == 'WORKSHOP':315 images_obj.initialize_facility('WORKSHOP')316 sprite = Workshop_sprite((place_pos_x,place_pos_y))317 model.workshop_sprite_list.append(sprite)318 319 if facility_name == 'SCHOOL':320 images_obj.initialize_facility('SCHOOL')321 sprite = School_sprite((place_pos_x,place_pos_y))322 model.school_sprite_list.append(sprite)323 324 if facility_name == 'FARM':325 images_obj.initialize_facility('FARM')326 sprite = Farm_sprite((place_pos_x,place_pos_y))327 model.farm_sprite_list.append(sprite)328 329 if facility_name == 'FOUNTAIN':330 images_obj.initialize_facility('FOUNTAIN')331 sprite = Fountain_sprite((place_pos_x,place_pos_y))332 model.fountain_sprite_list.append(sprite)333 add_sprite_all(sprite)334 add_sprite_facilities(sprite)335 336 # Generating villagers for each facility337 speeds = [[2,0],[-2,0],[0,2],[0,-2]]338 facility_obj = model.facilities_list[0]339 for i in range(len(model.facilities_list)):340 if model.facilities_list[i].get_name() == facility_name:341 facility_obj = model.facilities_list[i]342 for i in range(int(random.random()*5)):343 #print attribute344 dir = int(random.random()*4)345 villager = Villager((place_pos_x-500,place_pos_y-500,place_pos_x+500,place_pos_y+500))346 villager.set_speed(speeds[dir])347 villager.add(villagers,all)348 349 check_collide_villager(sprite) # Function to check if a sprite collides with the position of a villager350 351 352def place_facility_collide_check(rect_obj):353 FACILITY_RECT_LIST = []354 355 (rect_obj[0],rect_obj[1]) = transform_obj.inverse_transform_cordinate((rect_obj[0],rect_obj[1]))356 market_rect = pygame.Rect(int(2800*(1200.0/new_screen_size[0])),int(2500*(900.0/new_screen_size[1])),int(516*(1200.0/new_screen_size[0])),int(600*(900.0/new_screen_size[1]))) 357 358 for key in model.facilities_list_sprites.values():359 for i in range(len(key)):360 FACILITY_RECT_LIST.append(transform_obj.inverse_transform_rect(key[i].rect))361 362 result = rect_obj.collidelist(FACILITY_RECT_LIST)363 if rect_obj.colliderect(market_rect):364 result = 1365 366 if result == -1:367 return False368 else:369 return True370 371 372def build_facility(facility_obj, PLACING_DATA_LIST = [], list_food = model.DEF_FARM_PROD, autobuild_flag = False):373 ''' Thread to build a new building of any facility374 Args:375 facility_obj:Facility object to be built376 list_food:377 '''378 379 if facility_obj.get_number() == 0:380 381 if facility_obj.get_original_number() > 0:382 text = model.text_file.setup_fac_exceptions['stopped']383 message.push_message(text,'high')384 return text385 try:386 387 if facility_obj.check_manp_res(model.ppl)<0:388 raise Exceptions.Low_Manpower_Resources_Exception389 390 model.resources=facility_obj.build_start(model.resources,model.ppl)391 392 if facility_obj.get_name() == 'FARM':393 qrice = int(list_food[0])*model.MAX_FOOD_PROD_PER_FARM/100394 qwheat = int(list_food[1])*model.MAX_FOOD_PROD_PER_FARM/100395 qbeans = int(list_food[2])*model.MAX_FOOD_PROD_PER_FARM/100396 prod = facility_obj.get_prod_dict()397 prod['RICE'] = (prod['RICE']*facility_obj.get_number() + qrice)/(facility_obj.get_number() + 1)398 prod['WHEAT'] = (prod['WHEAT']*facility_obj.get_number() + qwheat)/(facility_obj.get_number() + 1)399 prod['BEANS'] = (prod['BEANS']*facility_obj.get_number() + qbeans)/(facility_obj.get_number() + 1)400 facility_obj.set_production(prod)401 402 model.ppl = facility_obj.update_manp_res(model.ppl)403 404 405 except Exceptions.Resources_Underflow_Exception,args:406 res = str(args).lower()407 text = model.text_file.setup_fac_exceptions['low_resource']%{'resource':res}408 return text409 except Exceptions.Low_Manpower_Resources_Exception:410 text = model.text_file.setup_fac_exceptions['low_manpower']411 return text412 except Exceptions.Maximum_Number_Reached:413 text = model.text_file.setup_fac_exceptions['max_limit']414 return text415 if autobuild_flag == False:416 set_build_facility_placement_flag(facility_obj)417 else:418 build_placed_facility("",True,PLACING_DATA_LIST)419 420 return model.text_file.setup_text[4]421def check_collide_villager(sprite):422 ''' Checks if an installation collides with a position of a villager, If yes, then it deletes 423 the villager sprite and create similar villager sprites at safe positions424 '''425 426 while True:427 428 sprites_list = pygame.sprite.spritecollide(sprite,villagers,False)429 if sprites_list:430 for sprites in sprites_list:431 new_sprite = Villager(sprites.get_attributes())432 sprites.remove(all,villagers)433 sprites.kill()434 435 new_sprite.add(villagers,all) 436 else:437 break438 439def build_end_facility(facility_obj):440 global levelStartFacilityBuildFlag441 model.ppl = facility_obj.build_end(model.ppl)442 event = game_events.Event(type = game_events.BUILDFACILITYEVENT, facility_name = facility_obj.get_name())443 game_events.EventQueue.add(event)444 if levelStartFacilityBuildFlag > 0:445 levelStartFacilityBuildFlag -= 1446 if levelStartFacilityBuildFlag == 0:447 model.resources = model.ppl.update_turn(model.resources,model.facilities_list)448 calculate_indicators_starting()449 450def upgrade_facility(facility_obj):451 ''' Upgrades a facility452 COMMENT : change the view of facility if you want to do so453 '''454 if facility_obj.get_number() == 0:455 456 if facility_obj.get_original_number() > 0:457 text = model.text_file.upgrade_fac_exceptions['stopped']458 message.push_message(text,'high')459 return text460 text = model.text_file.upgrade_fac_exceptions['none_setup']461 return text462 463 #global model.resources464 try:465 model.resources = facility_obj.update_level(model.resources,model.ppl)466 except Exceptions.Resources_Underflow_Exception,args:467 res = str(args).lower()468 text = model.text_file.upgrade_fac_exceptions['low_resource']%{'resource':res}469 return text470 except Exceptions.Maximum_Level_Reached:471 text = model.text_file.upgrade_fac_exceptions['max_level']472 return text473 474 if facility_obj.get_name() == 'HOUSE':475 images_obj.House_flag = False476 images_obj.initialize_facility(facility_obj.get_name())477 if facility_obj.get_name() == 'HOSPITAL':478 images_obj.Hospital_flag = False479 images_obj.initialize_facility(facility_obj.get_name())480 if facility_obj.get_name() == 'WORKSHOP':481 images_obj.Workshop_flag = False482 images_obj.initialize_facility(facility_obj.get_name())483 if facility_obj.get_name() == 'SCHOOL':484 images_obj.School_flag = False485 images_obj.initialize_facility(facility_obj.get_name())486 for i in range(len(model.facilities_list_sprites[facility_obj.get_name()])):487 model.facilities_list_sprites[facility_obj.get_name()][i].upgrade_level()488 489 event = game_events.Event(type = game_events.UPGRADEFACILITYEVENT, facility_name = facility_obj.get_name())490 game_events.EventQueue.add(event)491 492 text = model.text_file.upgrade_fac_text[4]493 return text494def pause_update_thread():495 global update_thread_pause496 update_thread_pause = False497def resume_update_thread():498 global update_thread_pause499 update_thread_pause = True500def calculate_indicators_starting():501 502 # updation of indicators503 504 # housing505 ratio_people_sheltered = model.ppl.get_no_of_ppl_sheltered()/model.ppl.get_total_population()506 model.Housing.turn({'SHELTERED PEOPLE' : ratio_people_sheltered})507 # nutrition508 ppl_fed_ratio = model.ppl.get_no_of_ppl_fed()/model.ppl.get_total_population()509 temp = model.FOOD_DIST_DICT_INIT510 protiens = 0.0511 vitamins = 0.0512 fats = 0.0513 for resource in model.food_resources:514 name = resource.get_name()515 if temp.has_key(name):516 quantity = int(resource.get_vquantity())517 protiens += temp[name]['PROTIENS'] * quantity518 vitamins += temp[name]['VITAMINS'] * quantity519 fats += temp[name]['FATS'] * quantity520 521 522 food = protiens + vitamins + fats523 if food:524 protiens /= food*0.6525 if protiens>1:526 protiens = 1527 vitamins /= food*0.4528 if vitamins>1:529 vitamins = 1530 fats /= food*0.6531 if fats>1:532 fats = 1533 model.Nutrition.turn({'PEOPLE FED' : ppl_fed_ratio , 'PROTIENS' : protiens , 'FATS' : fats , 'VITAMINS' : vitamins})534 # health535 healthy_ppl_ratio = model.ppl.get_no_of_ppl_healthy()/model.ppl.get_total_population()536 nutrition = model.Nutrition.get_value()537 nutrition /= model.MAX_INDICATOR538 water = model.Water.get_vquantity()/1000.0539 if water>1:540 water =1541 model.Health.turn({'HEALTHY PEOPLE' : healthy_ppl_ratio , 'NUTRITION' : nutrition , 'WATER' : water})542 # education543 educated_ppl = model.ppl.get_no_of_ppl_educated()/model.ppl.get_total_population()544 level = model.School.get_level()/model.MAX_LEVELS_FACILITY545 model.Education.turn({'EDUCATED PEOPLE' : educated_ppl , 'LEVEL OF EDUCATION' : level })546 # training547 level = model.Workshop.get_level()/model.MAX_LEVELS_FACILITY548 ppl_workshop = model.ppl.get_no_of_ppl_emp_in_workshop()/model.ppl.get_total_population()549 ppl_farm = model.ppl.get_no_of_ppl_emp_in_farm()/model.ppl.get_total_population() 550 ppl_hospital = model.ppl.get_no_of_ppl_emp_in_hospital()/model.ppl.get_total_population()551 ppl_construction = model.ppl.get_no_of_ppl_emp_in_cons()/model.ppl.get_total_population()552 ppl_emp = model.ppl.get_total_no_of_ppl_emp()/model.ppl.get_total_population()553 model.Training.turn({ 'LEVEL OF WORKSHOPS' : level , 'EMPLOYED PEOPLE IN WORKSHOP' : ppl_emp , 'EMPLOYED PEOPLE IN FARM' : ppl_emp , 'EMPLOYED PEOPLE IN HOSPITAL' : ppl_emp , 'EMPLOYED PEOPLE IN CONSTRUCTION' : ppl_emp })554update_turn_time = 0 555def update_turn(delay = 0):556 ''' Updates the model.resources, facilities, manpower model.resources and indicators557 at each turn558 '''559 global food_resources560 global Housing561 global Nutrition562 global Health563 global Water564 global School565 global update_turn_time566 567 update_turn_time += delay568 #print "Delay :" + str(delay)569 #print "turn time :" + str(update_turn_time)570 if update_turn_time>10000:571 572 if update_thread_pause == True:573 # updation of all facilities574 global levelStartUpdateFlag575 levelStartUpdateFlag = True576 577 for i in range(len(model.facilities_list)):578 try:579 model.resources = model.facilities_list[i].turn(model.resources)580 except Exceptions.Resources_Underflow_Exception,args:581 582 t = threading.Thread(target = stop_facility , args = [model.facilities_list[i],str(args)])583 t.start()584 except Exceptions.Resources_Overflow_Exception:585 pass 586 587 # Increase of population588 popul = model.ppl.get_total_population()589 model.POPULATION_FACTOR+=0.05590 model.ppl.change_total_population((popul * model.POPULATION_CHANGE/model.POPULATION_FACTOR))591 model.ppl.update_total_no_of_ppl_employed()592 593 # updation of manpower model.resources594 595 model.resources = model.ppl.update_turn(model.resources,model.facilities_list)596 # updation of prices of model.resources and the check on model.resources if their market value decreases a certain value then it should increase it597 598 for i in range(len(model.resources)):599 model.resources[i].update_price()600 if model.resources[i].get_mquantity < 500:601 model.resources[i].change_mquantity(8000)602 603 # housing604 ratio_people_sheltered = model.ppl.get_no_of_ppl_sheltered()/model.ppl.get_total_population()605 model.Housing.turn({'SHELTERED PEOPLE' : ratio_people_sheltered})606 607 # nutrition608 ppl_fed_ratio = model.ppl.get_no_of_ppl_fed()/model.ppl.get_total_population()609 #print "ppl_fed_ratio",ppl_fed_ratio610 temp = model.FOOD_DIST_DICT_INIT611 protiens = 0.0612 vitamins = 0.0613 fats = 0.0614 for resource in model.food_resources:615 name = resource.get_name()616 if temp.has_key(name):617 quantity = int(resource.get_vquantity())618 #print "name, quantity of food resource",name,quantity619 protiens += temp[name]['PROTIENS'] * quantity620 vitamins += temp[name]['VITAMINS'] * quantity621 fats += temp[name]['FATS'] * quantity622 623 #print "value of protiens,vitamins,fats",protiens,vitamins,fats624 food = protiens + vitamins + fats625 if food:626 protiens /= food*0.6627 if protiens>1:628 protiens = 1629 vitamins /= food*0.4630 if vitamins>1:631 vitamins = 1632 fats /= food*0.6633 if fats>1:634 fats = 1635 #print "protiens,vitamins,fats",protiens,vitamins,fats636 637 model.Nutrition.turn({'PEOPLE FED' : ppl_fed_ratio , 'PROTIENS' : protiens , 'FATS' : fats , 'VITAMINS' : vitamins})638 639 # health640 healthy_ppl_ratio = model.ppl.get_no_of_ppl_healthy()/model.ppl.get_total_population()641 #print "healthy_ppl_ratio",healthy_ppl_ratio642 nutrition = model.Nutrition.get_value()643 nutrition /= model.MAX_INDICATOR644 #print "nutrition",nutrition645 water = model.Water.get_vquantity()/1000.0646 if water>1:647 water =1648 #print "water",water649 650 model.Health.turn({'HEALTHY PEOPLE' : healthy_ppl_ratio , 'NUTRITION' : nutrition , 'WATER' : water})651 652 # education653 educated_ppl = model.ppl.get_no_of_ppl_educated()/model.ppl.get_total_population()654 level = model.School.get_level()/model.MAX_LEVELS_FACILITY655 model.Education.turn({'EDUCATED PEOPLE' : educated_ppl , 'LEVEL OF EDUCATION' : level })656 657 # training658 level = model.Workshop.get_level()/model.MAX_LEVELS_FACILITY659 ppl_workshop = model.ppl.get_no_of_ppl_emp_in_workshop()/model.ppl.get_total_population()660 ppl_farm = model.ppl.get_no_of_ppl_emp_in_farm()/model.ppl.get_total_population() 661 ppl_hospital = model.ppl.get_no_of_ppl_emp_in_hospital()/model.ppl.get_total_population()662 ppl_construction = model.ppl.get_no_of_ppl_emp_in_cons()/model.ppl.get_total_population()663 ppl_emp = model.ppl.get_total_no_of_ppl_emp()/model.ppl.get_total_population()664 model.Training.turn({ 'LEVEL OF WORKSHOPS' : level , 'EMPLOYED PEOPLE IN WORKSHOP' : ppl_emp , 'EMPLOYED PEOPLE IN FARM' : ppl_emp , 'EMPLOYED PEOPLE IN HOSPITAL' : ppl_emp , 'EMPLOYED PEOPLE IN CONSTRUCTION' : ppl_emp })665 update_turn_time =0666# Functions for making the code resolution independent667def resize_pos(original_pos,original_size = original_screen_size,new_size = new_screen_size):668 ratio_x = (original_pos[0]+0.0)/(original_size[0]+0.0) 669 ratio_y = original_pos[1]/(original_size[1] +0.0)670 new_pos = (int(new_size[0]*ratio_x),int(new_size[1]*ratio_y))671 return new_pos672def resize_pt(point,original_size = original_screen_size,new_size = new_screen_size):673 ratio_x = new_size[0]/(original_size[0]+0.0) 674 ratio_y = new_size[1]/(original_size[1] +0.0)675 ratio = (ratio_x + ratio_y)/2676 point *= ratio677 return int(point)678def resize_pt_x(point,original_size = original_screen_size,new_size = new_screen_size):679 ratio_x = new_size[0]/(original_size[0]+0.0) 680 point *= ratio_x681 return int(point)682def resize_pt_y(point,original_size = original_screen_size,new_size = new_screen_size):683 ratio_y = new_size[1]/(original_size[1] +0.0)684 point *= ratio_y685 return int(point)686 687def resize_rect(original_rect,original_size = original_screen_size,new_size = new_screen_size):688 ratio_x = new_size[0]/(original_size[0]+0.0) 689 ratio_y = new_size[1]/(original_size[1] +0.0)690 new_rect = (int(original_rect[0]*ratio_x),int(original_rect[1]*ratio_y),int(original_rect[2]*ratio_x),int(original_rect[3]*ratio_y))691 return new_rect692# Functions to perform various game operations693def buy_res(res,res_quantity):694 ''' This method allows a user to buy model.resources695 '''696 #global model.resources697 #global model.money698 699 700 try:701 quantity=int(res_quantity)702 model.money = res.buy(quantity , model.money)703 except Exceptions.Money_Underflow_Exception:704 text = model.text_file.buysell_exceptions['low_money']705 return text706 except Exceptions.Resources_Underflow_Exception,args:707 text = model.text_file.buysell_exceptions['low_mkt_qty']708 return text709 except Exceptions.Resources_Overflow_Exception:710 text = model.text_file.buysell_exceptions['overflow']711 return text712 713 text = model.text_file.buysell_exceptions['no_exception']714 715 event = game_events.Event(type = game_events.BUYRESOURCESEVENT, res_name = res.get_name(), res_quantity = res_quantity)716 game_events.EventQueue.add(event)717 718 return text719 720def sell_res(res,res_quantity):721 ''' This method allows a user to sell model.resources722 '''723 try:724 quantity=int(res_quantity)725 model.money = res.sell(quantity , model.money) 726 except Exceptions.Resources_Underflow_Exception,args:727 text = model.text_file.buysell_exceptions['low_qty']728 return text729 except Exceptions.Resources_Overflow_Exception:730 text = model.text_file.buysell_exceptions['no_exception']731 return text732 text = model.text_file.buysell_exceptions['no_exception']733 734 event = game_events.Event(type = game_events.SELLRESOURCESEVENT, res_name = res.get_name(), res_quantity = res_quantity)735 game_events.EventQueue.add(event)736 737 return text738 739 740# Functions for calamities741def demolish_facility(facility_name):742 ''' Function to demolish a facility743 '''744 745 if (facility_name == 'House') and (model.House.get_number()>0):746 747 model.ppl = model.House.demolish(model.ppl)748 sprite = model.house_sprite_list.pop(0)749 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.House.get_name())750 game_events.EventQueue.add(event)751 sprite.kill()752 753 if (facility_name == 'Hospital') and (model.Hospital.get_number()>0):754 model.ppl = model.Hospital.demolish(model.ppl)755 sprite = model.hospital_sprite_list.pop(0)756 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.Hospital.get_name())757 game_events.EventQueue.add(event)758 sprite.kill()759 760 if (facility_name == 'Workshop') and (model.Workshop.get_number()>0):761 model.ppl = model.Workshop.demolish(model.ppl)762 sprite = model.workshop_sprite_list.pop(0)763 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.Workshop.get_name())764 game_events.EventQueue.add(event)765 sprite.kill()766 767 if (facility_name == 'School') and (model.School.get_number()>0):768 model.ppl = model.School.demolish(model.ppl)769 sprite = model.school_sprite_list.pop(0)770 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.School.get_name())771 game_events.EventQueue.add(event)772 sprite.kill()773 774 if (facility_name == 'Farm') and (model.Farm.get_number()>0):775 model.ppl = model.Farm.demolish(model.ppl)776 sprite = model.farm_sprite_list.pop(0)777 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.Farm.get_name())778 game_events.EventQueue.add(event)779 sprite.kill()780 781 if (facility_name == 'Fountain') and (model.Fountain.get_number()>0):782 model.ppl = model.Fountain.demolish(model.ppl)783 sprite = model.fountain_sprite_list.pop(0)784 event = game_events.Event(type = game_events.DEMOLISHFACILITYEVENT, facility_name = model.Fountain.get_name())785 game_events.EventQueue.add(event)786 sprite.kill()787 788def flood():789 '''This method needs to be called when there is an flood in the village790 It will increase the quantity of water with the village and stop the operation of791 all facilities for some time792 '''793 global Hospital 794 global House795 global School796 global Workshop797 #global model.ppl798 global Water799 global Farm800 801 802 try :803 model.Water.change_vquantity(1000)804 except :805 pass806 807 model.Hospital.stop_facility()808 model.House.stop_facility() # we can comment it out even....809 model.School.stop_facility()810 model.Workshop.stop_facility()811 model.Farm.stop_facility()812 813 sleep(90) # that means for five turns814 815 model.Hospital.resume_facility()816 model.House.resume_facility()817 model.School.resume_facility()818 model.Workshop.resume_facility()819 model.Farm.resume_facility()820 821 822def famine():823 '''This method needs to be called when there is an famine in the village824 It will stop the production of farms for some time, five turns825 '''826 827 global Farm828 829 model.Farm.stop_facility()830 sleep(90)831 model.Farm.resume_facility()832 833if model.FLAG_XO or model.FLAG_SOAS:834 import olpcgames.util835 import subprocess836 list_file = open('storyboard_list.pkl')837 for i in range(pickle.load(list_file)):838 item = pickle.load(list_file)839 subprocess.call(['mkdir', os.path.join(olpcgames.util.get_activity_root(),'storyboards',str(item))])840 save_game_file = os.path.join(olpcgames.util.get_activity_root(),'storyboards',str(model.storyboard_file),'save_game.pkl')841else:842 save_game_file = os.path.join('storyboards',str(model.storyboard_file),'save_game.pkl')843def save_game():844 '''Used to save current level'''845 global PLACING_LIST_TEMP846 global current_level847 global game_save_flag848 global storyboard_file849 game_save_flag = True850 851 data_file = os.path.join('storyboards',str(model.storyboard_file),'save_game.pkl')852 output = open(data_file,'wb')853 pickle.dump(current_level,output)854 pickle.dump(model.game_controller.get_global_time(),output)855 pickle.dump(PLACING_LIST_TEMP,output)856 output.close()857 858def delete_saved_game(data_file = save_game_file):859 '''Used to delete saved game data'''860 global game_saved_flag861 game_save_flag = False862 output = open(data_file,'wb')863 output.close()864 865def resume_game():866 '''Used to resume a saved game'''867 global PLACING_LIST_TEMP868 global level_save_time869 global game_save_flag870 global current_level871 872 data_file = os.path.join('storyboards',str(model.storyboard_file),'save_game.pkl')873 output = open(data_file,'rb')874 level = pickle.load(output)875 current_level = level876 level_save_time = pickle.load(output)877 model.game_controller.resume_game_time_update(level_save_time)878 #print model.global_time879 while True:880 try:881 PLACING_LIST_TEMP = pickle.load(output)882 #print PLACING_LIST_TEMP883 except EOFError:884 break885 output.close()886 game_save_flag = False887 888def check_saved_game_level():889 '''Used to check the status of game, saved or unsaved'''890 891 global game_save_flag892 storyboard_list_file = open('storyboard_list.pkl')893 for i in range(pickle.load(storyboard_list_file)):894 storyboard_name = pickle.load(storyboard_list_file)895 if os.path.exists(os.path.join('storyboards',str(storyboard_name[1]),'save_game.pkl')):896 game_save_flag = True 897 break898 899def load_initial_facilities():900 global PLACING_LIST_TEMP901 PLACING_LIST_TEMP = []902 fac_load_file = open(os.path.join('storyboards',str(model.storyboard_file),'init_fac.pkl'),'rb')903 while True:904 try:905 PLACING_LIST_TEMP.append(pickle.load(fac_load_file))906 except EOFError:907 break908 fac_load_file.close()909 910 911# The messages Classes 912class Messages:913 ''' Class which handles the messaging system914 '''915 def __init__(self):916 self.queue = []917 self.queue_color = []918 919 920 def push_message(self,text,priority):921 ''' Used to push a message in the message queue922 '''923 if priority == 'low':924 color = (0,250,0) # Green925 if priority == 'medium':926 color = (0,0,250) # Blue927 if priority == 'high':928 color = (250,0,0) # Red929 930 self.queue_color.append(color)931 self.queue.append(text)932 933 def pop_message(self):934 ''' Used to pop a message from the message queue935 '''936 937 text = None938 color = None939 if self.queue:940 text = self.queue.pop(0)941 color = self.queue_color.pop(0)942 return (text,color)943 944 945message = Messages() # the Mesages class object 946# NOW there are classes of animation and sprites here947class Workshop_sprite(pygame.sprite.Sprite):948 949 def __init__(self,(x,y)):950 pygame.sprite.Sprite.__init__(self)951 self.frame = 0952 self.ratio = transform_obj.ratio953 self.level = model.Workshop.get_level()954 self.built_flag = 0955 self.image = load_images.Workshop_tiles_list[self.level][self.frame]956 self.rect = self.image.get_rect()957 self.position = (x,y)958 self.position_rect = self.rect.move(self.position)959 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))960 self.tile_time = 0961 self.update_flag = True962 def update(self):963 if self.tile_time < 2000:964 self.tile_time += model.iteration_time965 else:966 self.tile_time = 0967 968 if (self.frame >= 2 and self.level ==0) :969 if (self.frame == 2 and self.built_flag == 0) :970 build_end_facility(model.Workshop)971 self.built_flag = 1972 elif (self.frame >= 2 and self.level ==1) :973 if (self.frame == 2 and self.built_flag == 0) :974 build_end_facility(model.Workshop)975 self.built_flag = 1976 elif (self.frame >= 2 and self.level ==2) :977 if (self.frame == 2 and self.built_flag == 0) :978 build_end_facility(model.Workshop)979 self.built_flag = 1980 elif (self.frame >= 2 and self.level ==3) :981 if (self.frame == 2 and self.built_flag == 0) :982 build_end_facility(model.Workshop)983 self.built_flag = 1984 else:985 self.frame += 1986 self.update_flag = True987 if not self.ratio == transform_obj.ratio:988 self.update_flag = True989 self.ratio = transform_obj.ratio990 self.rect = self.image.get_rect()991 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))992 993 994 def set_frame(self):995 if transform_obj.check_update_condition() or self.update_flag:996 self.image = load_images.Workshop_tiles_list[self.level][self.frame]997 self.update_flag = False998 self.rect = self.image.get_rect()999 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1000 1001 def get_position(self):1002 ''' Returns the position rect of the sprite1003 '''1004 return self.position_rect1005 1006 def upgrade_level(self):1007 1008 transform_obj.focus_at(self.position)1009 self.level +=11010 self.counter = 41011 self.frame = 01012 self.update_flag = True1013 1014class House_sprite(pygame.sprite.Sprite):1015 1016 def __init__(self,(x,y)):1017 pygame.sprite.Sprite.__init__(self)1018 # Saving tiles of all the upgrades in tiles_list1019 self.frame = 01020 self.level = model.House.get_level()1021 self.built_flag = 01022 self.ratio = transform_obj.ratio1023 self.image = load_images.House_tiles_list[self.level][self.frame]1024 self.rect = self.image.get_rect()1025 self.position = (x,y)1026 self.position_rect = self.rect.move(self.position)1027 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1028 self.tile_time = 01029 self.update_flag = True1030 def update(self):1031 if self.tile_time < 2000:1032 self.tile_time += model.iteration_time1033 else:1034 self.tile_time = 01035 1036 if (self.frame >= 3 and self.level ==0) :1037 if (self.frame == 3 and self.built_flag == 0) :1038 build_end_facility(model.House)1039 self.built_flag = 11040 elif (self.frame >= 2 and self.level ==1) :1041 if (self.frame == 2 and self.built_flag == 0) :1042 build_end_facility(model.House)1043 self.built_flag = 11044 elif (self.frame >= 2 and self.level ==2) :1045 if (self.frame == 2 and self.built_flag == 0) :1046 build_end_facility(model.House)1047 self.built_flag = 11048 elif (self.frame >= 2 and self.level ==3) :1049 if (self.frame == 2 and self.built_flag == 0) :1050 build_end_facility(model.House)1051 self.built_flag = 11052 else:1053 self.frame += 11054 self.update_flag = True1055 if not self.ratio == transform_obj.ratio:1056 self.update_flag = True1057 self.ratio = transform_obj.ratio1058 1059 self.rect = self.image.get_rect()1060 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1061 1062 1063 def set_frame(self):1064 if transform_obj.check_update_condition() or self.update_flag:1065 self.image = load_images. House_tiles_list[self.level][self.frame]1066 self.update_flag = False1067 self.rect = self.image.get_rect()1068 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1069 1070 def get_position(self):1071 ''' Returns the position rect of the sprite1072 '''1073 return self.position_rect1074 1075 def upgrade_level(self):1076 transform_obj.focus_at(self.position)1077 self.level +=11078 self.counter = 41079 self.frame = 01080 self.update_flag = True1081 1082class Hospital_sprite(pygame.sprite.Sprite):1083 1084 def __init__(self,(x,y)):1085 pygame.sprite.Sprite.__init__(self)1086 # Saving tiles of all the upgrades in tiles_list1087 self.frame = 01088 self.ratio = transform_obj.ratio1089 self.level = model.Hospital.get_level()1090 self.built_flag = 01091 self.image = load_images.Hospital_tiles_list[self.level][self.frame]1092 self.rect = self.image.get_rect()1093 self.position = (x,y)1094 self.position_rect = self.rect.move(self.position)1095 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1096 self.tile_time = 01097 self.update_flag = True1098 def update(self):1099 1100 if self.tile_time < 2000:1101 self.tile_time += model.iteration_time1102 else:1103 self.tile_time = 01104 1105 if (self.frame >= 3 and self.level ==0) :1106 if (self.frame == 3 and self.built_flag == 0) :1107 build_end_facility(model.Hospital)1108 self.built_flag = 11109 elif (self.frame >= 2 and self.level ==1) :1110 if (self.frame == 2 and self.built_flag == 0) :1111 build_end_facility(model.Hospital)1112 self.built_flag = 11113 elif (self.frame >= 2 and self.level ==2) :1114 if (self.frame == 2 and self.built_flag == 0) :1115 build_end_facility(model.Hospital)1116 self.built_flag = 11117 elif (self.frame >= 2 and self.level ==3) :1118 if (self.frame == 2 and self.built_flag == 0) :1119 build_end_facility(model.Hospital)1120 self.built_flag = 11121 else:1122 self.frame += 11123 self.update_flag = True1124 if not self.ratio == transform_obj.ratio:1125 self.update_flag = True1126 self.ratio = transform_obj.ratio1127 1128 self.rect = self.image.get_rect()1129 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1130 1131 1132 def set_frame(self):1133 if transform_obj.check_update_condition() or self.update_flag:1134 self.image = load_images.Hospital_tiles_list[self.level][self.frame]1135 self.update_flag = False1136 self.rect = self.image.get_rect()1137 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1138 1139 def get_position(self):1140 ''' Returns the position rect of the sprite1141 '''1142 return self.position_rect1143 1144 def upgrade_level(self):1145 transform_obj.focus_at(self.position)1146 self.level +=11147 self.counter = 41148 self.frame = 01149 self.update_flag = True1150 1151 1152class School_sprite(pygame.sprite.Sprite):1153 1154 def __init__(self,(x,y)):1155 pygame.sprite.Sprite.__init__(self)1156 # Saving tiles of all the upgrades in tiles_list1157 1158 1159 self.frame = 01160 self.level = model.School.get_level()1161 self.built_flag =01162 self.ratio = transform_obj.ratio1163 self.image = load_images.School_tiles_list[self.level][self.frame]1164 self.rect = self.image.get_rect()1165 self.position = (x,y)1166 self.position_rect = self.rect.move(self.position)1167 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1168 self.tile_time =01169 self.update_flag = True1170 1171 def update(self):1172 1173 if self.tile_time < 2000:1174 self.tile_time += model.iteration_time1175 else:1176 self.tile_time = 01177 1178 if (self.frame >= 3 and self.level ==0) :1179 if (self.frame == 3 and self.built_flag == 0) :1180 build_end_facility(model.School)1181 self.built_flag = 11182 elif (self.frame >= 2 and self.level ==1) :1183 if (self.frame == 2 and self.built_flag == 0) :1184 build_end_facility(model.School)1185 self.built_flag = 11186 elif (self.frame >= 2 and self.level ==2) :1187 if (self.frame == 2 and self.built_flag == 0) :1188 build_end_facility(model.School)1189 self.built_flag = 11190 elif (self.frame >= 2 and self.level ==3) :1191 if (self.frame == 2 and self.built_flag == 0) :1192 build_end_facility(model.School)1193 self.built_flag = 11194 else:1195 self.frame += 11196 self.update_flag = True1197 if not self.ratio == transform_obj.ratio:1198 self.update_flag = True1199 self.ratio = transform_obj.ratio1200 1201 self.rect = self.image.get_rect()1202 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1203 1204 1205 def set_frame(self):1206 if transform_obj.check_update_condition() or self.update_flag:1207 self.image = load_images.School_tiles_list[self.level][self.frame]1208 self.update_flag = False1209 self.rect = self.image.get_rect()1210 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1211 1212 def get_position(self):1213 ''' Returns the position rect of the sprite1214 '''1215 return self.position_rect1216 1217 def upgrade_level(self):1218 transform_obj.focus_at(self.position)1219 self.level +=11220 self.counter = 41221 self.frame = 01222 self.update_flag = True1223 1224class Farm_sprite(pygame.sprite.Sprite):1225 1226 def __init__(self,(x,y)):1227 pygame.sprite.Sprite.__init__(self)1228 self.frame = 01229 self.built_flag = 01230 self.ratio = transform_obj.ratio1231 self.image = load_images.Farm_tiles[0][self.frame]1232 self.rect = self.image.get_rect()1233 self.position = (x,y)1234 self.position_rect = self.rect.move(self.position)1235 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1236 self.tile_time = 01237 self.update_flag = True1238 1239 def update(self):1240 1241 1242 if self.tile_time < 2000:1243 self.tile_time += model.iteration_time1244 else:1245 self.tile_time = 01246 1247 if (self.frame >= 2) :1248 if (self.frame == 2 and self.built_flag == 0) :1249 build_end_facility(model.Farm)1250 self.built_flag = 11251 else:1252 self.frame += 11253 self.update_flag = True1254 1255 if not self.ratio == transform_obj.ratio:1256 self.update_flag = True1257 self.ratio = transform_obj.ratio1258 1259 self.rect = self.image.get_rect()1260 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1261 1262 1263 def set_frame(self):1264 if transform_obj.check_update_condition() or self.update_flag:1265 self.image = load_images.Farm_tiles[0][self.frame]1266 self.update_flag = False1267 1268 self.rect = self.image.get_rect()1269 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1270 1271 def get_position(self):1272 ''' Returns the position rect of the sprite1273 '''1274 return self.position_rect1275 1276 def upgrade_level(self):1277 transform_obj.focus_at(self.position)1278 self.update_flag = True1279 1280 1281class Fountain_sprite(pygame.sprite.Sprite):1282 1283 def __init__(self,(x,y)):1284 pygame.sprite.Sprite.__init__(self)1285 # Saving tiles of all the upgrades in tiles_list1286 self.frame = 01287 self.built_flag = 01288 self.ratio = transform_obj.ratio1289 self.image = load_images.Fountain_tiles[0][self.frame]1290 self.rect = self.image.get_rect()1291 self.position = (x,y)1292 self.position_rect = self.rect.move(self.position)1293 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1294 self.tile_time = 01295 self.update_flag = True1296 1297 def update(self):1298 1299 1300 if self.tile_time < 2000:1301 self.tile_time += model.iteration_time1302 else:1303 self.tile_time = 01304 1305 if (self.frame >= 3) :1306 if (self.frame == 3 and self.built_flag == 0) :1307 build_end_facility(model.Fountain)1308 self.built_flag = 11309 else:1310 self.frame += 11311 self.update_flag = True1312 if not self.ratio == transform_obj.ratio:1313 self.update_flag = True1314 self.ratio = transform_obj.ratio1315 1316 self.rect = self.image.get_rect()1317 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1318 1319 def set_frame(self):1320 if transform_obj.check_update_condition() or self.update_flag:1321 self.image = load_images.Fountain_tiles[0][self.frame]1322 self.update_flag = False1323 self.rect = self.image.get_rect()1324 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1325 1326 def get_position(self):1327 ''' Returns the position rect of the sprite1328 '''1329 return self.position_rect1330 1331 def upgrade_level(self):1332 transform_obj.focus_at(self.position)1333 self.update_flag = True1334 1335# The work for drawing the background1336#global back_image_level11337if not model.FLAG_XO:1338 global image_to_scale1339 image_to_scale = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]1340 global image_pos1341 image_pos = []1342 for num_ver in range(10):1343 for num_hor in range(12):1344 rect = Rect(num_hor*250 + 10, num_ver*250 + 10, 230, 230)1345 image_pos.append(rect)1346#Class to initialise the background1347class Environment2:1348 1349 def __init__(self):1350 self.sheet = pygame.image.load(os.path.join('data','tileset2.png')).convert()1351 #self.sheet = pygame.transform.scale(self.sheet,(3010,2260))1352 1353 self.dis_image = {}1354 for image_no in image_to_scale:1355 self.surf = pygame.Surface((230,230)).convert()1356 self.rect = image_pos[image_no]1357 self.surf.blit(self.sheet,(0,0),self.rect)1358 self.surf = pygame.transform.scale(self.surf,resize_pos((230,230)))1359 self.dis_image[image_no] = self.surf1360 1361 self.dis_image_trans = {}1362 for self.dis_image_key in self.dis_image.keys():1363 self.dis_image_trans[self.dis_image_key] = transform_obj.transform_surface(self.dis_image.get(self.dis_image_key))1364 1365 def update_background(self):1366 #self.dis_image_trans = {}1367 if transform_obj.check_update_condition():1368 for self.dis_image_key in self.dis_image.keys():1369 self.dis_image_trans[self.dis_image_key] = transform_obj.transform_surface(self.dis_image.get(self.dis_image_key))1370 rect = self.dis_image_trans[self.dis_image_key].get_rect()1371 (self.x_inc ,self.y_inc) = rect.size 1372 self.img_x_init = int(transform_obj.pos_x/self.x_inc)1373 self.img_y_init = int(transform_obj.pos_y/self.y_inc)1374 self.ratio = transform_obj.ratio1375 self.pos_x_init = (self.x_inc*self.img_x_init) - transform_obj.pos_x1376 self.pos_y_init = (self.y_inc*self.img_y_init) - transform_obj.pos_y1377 self.pos_x = self.pos_x_init 1378 self.pos_y = self.pos_y_init 1379 self.img_x = self.img_x_init1380 self.img_y = self.img_y_init1381 1382 while self.pos_x < resize_pt_x(1000):1383 self.img_y = self.img_y_init1384 self.pos_y = self.pos_y_init1385 while self.pos_y < resize_pt_y(600):1386 screen.blit(self.dis_image_trans[load_images.back_image_level1[self.img_y][self.img_x]],(self.pos_x,self.pos_y),rect)1387 1388 self.img_y += 11389 self.pos_y += self.y_inc1390 self.img_x += 11391 self.pos_x += self.x_inc1392class Environment(pygame.sprite.Sprite):1393 1394 def __init__(self):1395 pygame.sprite.Sprite.__init__(self)1396 spritesheet = load_images.Spritesheet('tileset.png')1397 self.tiles = spritesheet.imgat((0,0,930,560))1398 self.tiles = pygame.transform.scale(self.tiles,resize_pos((930,560)))1399 1400 def update_background(self):1401 1402 screen.blit(self.tiles,(0,resize_pt_y(40)))1403 1404class Build(pygame.sprite.Sprite):1405 1406 def __init__(self, filename, x, y, colorkey=None):1407 pygame.sprite.Sprite.__init__(self)1408 self.market_image = pygame.image.load(os.path.join('data', filename)).convert_alpha()1409 self.image = transform_obj.transform_surface(self.market_image)1410 if colorkey is not None:1411 if colorkey is -1:1412 colorkey = self.image.get_at((0, 0))1413 self.image.set_colorkey(colorkey, RLEACCEL)1414 self.rect = self.image.get_rect()1415 self.x = x1416 self.y = y1417 self.update_flag = True1418 self.ratio = transform_obj.ratio1419 self.rect = self.rect.move(transform_obj.transform_cordinates((x, y)))1420 1421 def update(self):1422 if not self.ratio == transform_obj.ratio:1423 self.update_flag = True1424 self.ratio = transform_obj.ratio1425 1426 self.rect = self.image.get_rect()1427 self.rect = self.rect.move(transform_obj.transform_cordinates((self.x, self.y)))1428 1429 def set_frame(self):1430 1431 if transform_obj.check_update_condition() or self.update_flag:1432 self.image = transform_obj.transform_surface(self.market_image)1433 self.rect = self.image.get_rect()1434 self.rect = self.rect.move(transform_obj.transform_cordinates((self.x, self.y)))1435 1436 1437# Functions to add sprites to groups1438def add_sprite_all(sprite):1439 sprite.add(all) 1440 1441def add_sprite_facilities(sprite):1442 sprite.add(facilities_group) 1443# The screen sprite to clip all the sprites which are not in the drawable region1444class screen_sprite(pygame.sprite.Sprite):1445 1446 def __init__(self):1447 pygame.sprite.Sprite.__init__(self)1448 #self.image = pygame.surface.Surface(resize_pos((1200,560)))1449 self.rect = Rect(resize_rect((0,40,930,560)))1450 1451# The villager class1452class Villager(pygame.sprite.Sprite):1453 1454 def __init__(self,range_rect):1455 pygame.sprite.Sprite.__init__(self)1456 names = ['Man','Woman','Boy','Girl']1457 name = names[int(random.random()*4)]1458 self.dx = 21459 self.dy = 21460 self.update_flag = True1461 self.ratio = transform_obj.ratio1462 self.speed = [2, 0]1463 self.speed_time = 01464 self.tile_time =01465 self.name = name1466 self.dtiles_final = [0,0,0,0]1467 self.range = range_rect1468 if self.name == 'Man':1469 self.tiles = load_images.Man_tiles[0]1470 1471 if self.name == 'Woman':1472 self.tiles = load_images.Woman_tiles[0]1473 1474 if self.name == 'Boy':1475 self.tiles = load_images.Boy_tiles[0]1476 1477 if self.name == 'Girl':1478 self.tiles = load_images.Girl_tiles[0]1479 1480 self.frame = 01481 self.set_direction()1482 self.dtiles_final = self.dtiles1483 1484 self.image = self.dtiles_final[self.frame]1485 self.rect = self.image.get_rect()1486 1487 flag =True1488 while flag:1489 flag = False1490 self.initial_position = [self.range[0]+int(random.random()*self.range[2]), self.range[1]+int(random.random()*self.range[3])]1491 self.position = self.initial_position1492 self.position_rect = self.rect.move(self.position)1493 for key in model.facilities_list_sprites.keys(): 1494 sprite_list = model.facilities_list_sprites[key]1495 for sprite in sprite_list:1496 self.test_rect = sprite.get_position()1497 if self.test_rect.colliderect(self.position_rect):1498 1499 flag = True1500 1501 self.prev_disp = transform_obj.transform_cordinates(self.position)1502 self.rect = self.rect.move(self.prev_disp)1503 1504 1505 def set_direction(self):1506 1507 1508 if self.name == 'Man':1509 self.tiles = load_images.Man_tiles[0]1510 1511 if self.name == 'Woman':1512 self.tiles = load_images.Woman_tiles[0]1513 1514 if self.name == 'Boy':1515 self.tiles = load_images.Boy_tiles[0]1516 1517 if self.name == 'Girl':1518 self.tiles = load_images.Girl_tiles[0]1519 1520 sp = self.speed1521 if sp[0] > 0 and sp[1] == 0:1522 self.dtiles = self.tiles[0:4]1523 elif sp[0] < 0 and sp[1] == 0:1524 self.dtiles = self.tiles[4:8]1525 elif sp[0] == 0 and sp[1] < 0:1526 self.dtiles = self.tiles[8:12]1527 elif sp[0] == 0 and sp[1] > 0:1528 self.dtiles = self.tiles[12:16]1529 1530 self.dtiles_final = self.dtiles1531 1532 def collide_build(self):1533 1534 self.set_speed(map(lambda x: -x, self.speed))1535 1536 self.position = [self.position[0] + 5, self.position[1] + 5]1537 self.position = [self.position[0] + 5, self.position[1] + 5]1538 1539 self.update()1540 self.set_direction()1541 1542 def set_speed(self, speed):1543 1544 1545 self.speed = speed1546 self.set_direction()1547 1548 def update(self):1549 1550 self.speed_time += model.iteration_time1551 self.tile_time +=model.iteration_time1552 1553 ANIMRECT = Rect(0,0,9000,6000)1554 if self.tile_time >= 500:1555 self.tile_time =0 1556 self.frame += 11557 if self.frame >3:1558 self.frame = 01559 1560 if self.speed_time >= 6000:1561 self.speed_time = 01562 temp = self.speed[0]1563 self.speed[0] = self.speed[1]1564 self.speed[1] = temp1565 1566 1567 self.rect = self.image.get_rect()1568 self.position = [self.position[0] + (self.speed[0]*model.iteration_time/100.0), self.position[1] + (self.speed[1]*model.iteration_time/100.0)]1569 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1570 1571 if self.position[0] <= 0 or (self.position[0]+100) >= ANIMRECT.width or self.position[0] <= (self.range[0]) or self.position[0] >= (self.range[0]+self.range[2]):1572 self.speed[0] = -self.speed[0]1573 1574 self.rect = self.image.get_rect()1575 self.position[0] += self.speed[0]*model.iteration_time/100.01576 self.position[1] += self.speed[1]*model.iteration_time/100.01577 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1578 1579 elif self.position[1] <= 0 or (self.position[1]-100) >= ANIMRECT.height or self.position[1] <= (self.range[1]) or self.position[1] >= (self.range[1]+self.range[3]):1580 self.speed[1] = -self.speed[1]1581 1582 self.rect = self.image.get_rect()1583 self.position[0] += self.speed[0]*model.iteration_time/100.01584 self.position[1] += self.speed[1]*model.iteration_time/100.01585 self.rect = self.rect.move(transform_obj.transform_cordinates(self.position))1586 self.set_direction()1587 if not self.ratio == transform_obj.ratio:1588 self.update_flag = True1589 self.ratio = transform_obj.ratio1590 1591 #self.rect.clamp_ip(ANIMRECT) 1592 def set_frame(self):1593 1594 self.set_direction()1595 if transform_obj.check_update_condition() or self.update_flag:1596 self.dtiles_final = self.dtiles1597 self.image = self.dtiles_final[self.frame]1598 1599 def get_attributes(self):1600 return self.range1601 def get_name(self):1602 return self.name1603 1604# Function to check for villagers collision1605def check_villagers_self_collision():1606 1607 villagers_sprite_list = []1608 for sprite in villagers.sprites():1609 sprite.remove(villagers)1610 sprites_list = pygame.sprite.spritecollide(sprite,villagers,False)1611 if sprites_list:1612 for villager in sprites_list:1613 villager.collide_build()1614 villagers_sprite_list.append(sprite)1615 while villagers_sprite_list:1616 villager = villagers_sprite_list.pop()1617 villager.add(villagers)1618 1619class Transform:1620 def __init__(self):1621 self.pos_x = 01622 self.pos_y = 01623 self.MAX_RATIO = 0.91624 self.MIN_RATIO = 0.41625 self.ratio = 0.41626 self.motion_up = 01627 self.motion_down = 01628 self.motion_left = 01629 self.motion_right = 01630 self.mouse_move_flag = True1631 self.prev_ratio = 0.21632 1633 def check_update_condition(self):1634 ''' Checks Whether to update an image or not1635 '''1636 1637 if self.prev_ratio == self.ratio:1638 return False1639 else : 1640 return True1641 1642 def move_up(self,dist = 10):1643 1644 self.pos_y -= dist1645 1646 def stop_mouse_move(self):1647 self.mouse_move_flag = False1648 1649 def resume_mouse_move(self):1650 self.mouse_move_flag = True1651 1652 def start_move(self,dir): 1653 1654 if dir == 'up':1655 self.motion_up = 11656 elif dir == 'down':1657 self.motion_down = 11658 elif dir == 'right':1659 self.motion_right = 11660 elif dir == 'left':1661 self.motion_left = 11662 1663 def stop_move(self,dir): 1664 1665 if dir == 'up':1666 self.motion_up = 01667 elif dir == 'down':1668 self.motion_down = 01669 elif dir == 'right':1670 self.motion_right = 01671 elif dir == 'left':1672 self.motion_left = 01673 1674 def move(self):1675 speed = 2001676 if self.motion_up:1677 self.pos_y -= speed*model.iteration_time/10001678 if self.motion_down:1679 self.pos_y += speed*model.iteration_time/10001680 if self.motion_right:1681 self.pos_x+= speed*model.iteration_time/10001682 if self.motion_left:1683 self.pos_x -= speed*model.iteration_time/10001684 1685 def move_mouse(self,(x,y)):1686 1687 if self.mouse_move_flag == True:1688 self.pos_x -= x1689 self.pos_y -=y1690 1691 def move_down(self):1692 1693 self.pos_y += 101694 1695 def move_right(self,dist = 10):1696 1697 self.pos_x += dist 1698 1699 def move_left(self,dist = 10):1700 1701 self.pos_x -= dist 1702 1703 def move_free(self,(x,y)):1704 1705 self.pos_x -= x1706 self.pos_y -=y1707 1708 def check_pos(self):1709 if self.pos_x < 0:1710 self.pos_x = 01711 if self.pos_x > (int(self.ratio*6000) - 930):1712 self.pos_x = (int(self.ratio*6000) - 930)1713 if self.pos_y < 0:1714 self.pos_y = 01715 if self.pos_y > (int(self.ratio*5000) - 560):1716 self.pos_y = (int(self.ratio*5000) - 560)1717 1718 1719 def focus(self):1720 ''' Used to focus or zoom in'''1721 self.ratio = self.ratio + 0.101722 if self.ratio >= 0.9:1723 self.ratio = 0.91724 else:1725 a = self.pos_x +6001726 b = self.pos_y + 2801727 a *= self.ratio/(self.ratio - 0.10)1728 b *= self.ratio/(self.ratio - 0.10)1729 self.pos_x = int(a - 600)1730 self.pos_y = int(b - 280)1731 1732 1733 def defocus(self):1734 ''' Used to defocus or zoom out'''1735 self.ratio = self.ratio - 0.101736 if self.ratio <= 0.2:1737 self.ratio = 0.21738 else:1739 a = self.pos_x +6001740 b = self.pos_y + 2801741 a *= self.ratio/(self.ratio + 0.10)1742 b *= self.ratio/(self.ratio + 0.10)1743 self.pos_x = int(a - 600)1744 self.pos_y = int(b - 280)1745 1746 1747 def focus_at(self,(x,y)):1748 '''Used to focus at a particular position'''1749 #self.ratio = 0.61750 self.pos_x = int(x*self.ratio) -5001751 self.pos_y = int(y*self.ratio) - 801752 1753 def transform_cordinates(self,(x,y)):1754 newx = x*self.ratio - self.pos_x1755 newy = y*self.ratio - self.pos_y + resize_pt_y(40)1756 return (int(newx),int(newy))1757 1758 def inverse_transform_cordinate(self,(x,y)):1759 ''' Transform the Screen Cordinates to Village Cordinates1760 1761 Args:1762 x:int:x cordinate1763 y:int:y cordinate1764 Return:1765 newx:int:new x cordinate1766 newy:int:new y cordinate1767 '''1768 newx = ((x + self.pos_x)/self.ratio)*(1200.0/new_screen_size[0])1769 newy = ((y + self.pos_y - 40)/self.ratio)*(900.0/new_screen_size[1])1770 return(int(newx),int(newy))1771 1772 1773 def inverse_trans_cordinate(self,(x,y)):1774 ''' Transform the Screen Cordinates to Village Cordinates1775 1776 Args:1777 x:int:x cordinate1778 y:int:y cordinate1779 Return:1780 newx:int:new x cordinate1781 newy:int:new y cordinate1782 '''1783 newx = ((x + self.pos_x)/self.ratio)1784 newy = ((y + self.pos_y - resize_pt_y(40))/self.ratio)1785 return(int(newx),int(newy))1786 1787 def inverse_transform_rect(self,(x,y,w,z)):1788 ''' Transform the Screen Cordinates to Village Cordinates1789 1790 Args:1791 x:int:x cordinate1792 y:int:y cordinate1793 Return:1794 newx:int:new x cordinate1795 newy:int:new y cordinate1796 '''1797 newx = ((x + self.pos_x)/self.ratio)*(1200.0/new_screen_size[0])1798 newy = ((y + self.pos_y - 40)/self.ratio)*(900.0/new_screen_size[1])1799 neww = (w/self.ratio)*(1200.0/new_screen_size[0])1800 newz = (z/self.ratio)*(900.0/new_screen_size[1])1801 return(int(newx),int(newy),int(neww),int(newz))1802 1803 def set_ratio(self,ratio):1804 self.ratio = ratio1805 1806 def transform_surface(self,surface):1807 (x,y) = surface.get_size()1808 x *= self.ratio1809 y *= self.ratio1810 surface = pygame.transform.scale(surface, (int(x),int(y)))1811 return surface1812 1813 def village_boundary_covered(self):1814 min_x = int(self.pos_x/self.ratio)1815 min_y = int(self.pos_y/self.ratio)1816 max_x = int((self.pos_x+930) /self.ratio)1817 max_y = int((self.pos_y+560) /self.ratio)1818 return [min_x, min_y, max_x, max_y]1819 1820 1821 1822class update_images:1823 1824 def __init__(self):1825 self.House_flag = False1826 self.Workshop_flag = False1827 self.School_flag = False1828 self.Hospital_flag = False1829 self.Fountain_flag = False1830 self.Farm_flag = False1831 1832 def update_images(self):1833 1834 if transform_obj.check_update_condition():1835 if transform_obj.prev_ratio > transform_obj.ratio:1836 for i in range(len(load_images.House_tiles_list)):1837 for j in range(len(load_images.House_tiles_list[i])):1838 (x,y) = load_images.House_tiles_list[i][j].get_size()1839 x *= transform_obj.ratio/transform_obj.prev_ratio1840 y *= transform_obj.ratio/transform_obj.prev_ratio1841 load_images.House_tiles_list[i][j] = pygame.transform.scale(load_images.House_tiles_list[i][j],(int(x),int(y)))1842 1843 for i in range(len(load_images.Hospital_tiles_list)):1844 for j in range(len(load_images.Hospital_tiles_list[i])):1845 (x,y) = load_images.Hospital_tiles_list[i][j].get_size()1846 x *= transform_obj.ratio/transform_obj.prev_ratio1847 y *= transform_obj.ratio/transform_obj.prev_ratio1848 load_images.Hospital_tiles_list[i][j] = pygame.transform.scale(load_images.Hospital_tiles_list[i][j],(int(x),int(y)))1849 for i in range(len(load_images.Workshop_tiles_list)):1850 for j in range(len(load_images.Workshop_tiles_list[i])):1851 (x,y) = load_images.Workshop_tiles_list[i][j].get_size()1852 x *= transform_obj.ratio/transform_obj.prev_ratio1853 y *= transform_obj.ratio/transform_obj.prev_ratio1854 load_images.Workshop_tiles_list[i][j] = pygame.transform.scale(load_images.Workshop_tiles_list[i][j],(int(x),int(y)))1855 for i in range(len(load_images.School_tiles_list)):1856 for j in range(len(load_images.School_tiles_list[i])):1857 (x,y) = load_images.School_tiles_list[i][j].get_size()1858 x *= transform_obj.ratio/transform_obj.prev_ratio1859 y *= transform_obj.ratio/transform_obj.prev_ratio1860 load_images.School_tiles_list[i][j] = pygame.transform.scale(load_images.School_tiles_list[i][j],(int(x),int(y)))1861 1862 for i in range(len(load_images.Fountain_tiles)):1863 for j in range(len(load_images.Fountain_tiles[i])):1864 (x,y) = load_images.Fountain_tiles[i][j].get_size()1865 x *= transform_obj.ratio/transform_obj.prev_ratio1866 y *= transform_obj.ratio/transform_obj.prev_ratio1867 load_images.Fountain_tiles[i][j] = pygame.transform.scale(load_images.Fountain_tiles[i][j],(int(x),int(y)))1868 for i in range(len(load_images.Farm_tiles)):1869 for j in range(len(load_images.Farm_tiles[i])):1870 (x,y) = load_images.Farm_tiles[i][j].get_size()1871 x *= transform_obj.ratio/transform_obj.prev_ratio1872 y *= transform_obj.ratio/transform_obj.prev_ratio1873 load_images.Farm_tiles[i][j] = pygame.transform.scale(load_images.Farm_tiles[i][j],(int(x),int(y)))1874 1875 for i in range(len(load_images.Man_tiles)):1876 for j in range(len(load_images.Man_tiles[i])):1877 (x,y) = load_images.Man_tiles[i][j].get_size()1878 x *= transform_obj.ratio/transform_obj.prev_ratio1879 y *= transform_obj.ratio/transform_obj.prev_ratio1880 load_images.Man_tiles[i][j] = pygame.transform.scale(load_images.Man_tiles[i][j],(int(x),int(y)))1881 1882 for i in range(len(load_images.Woman_tiles)):1883 for j in range(len(load_images.Woman_tiles[i])):1884 (x,y) = load_images.Woman_tiles[i][j].get_size()1885 x *= transform_obj.ratio/transform_obj.prev_ratio1886 y *= transform_obj.ratio/transform_obj.prev_ratio1887 load_images.Woman_tiles[i][j] = pygame.transform.scale(load_images.Woman_tiles[i][j],(int(x),int(y)))1888 1889 for i in range(len(load_images.Boy_tiles)):1890 for j in range(len(load_images.Boy_tiles[i])):1891 (x,y) = load_images.Boy_tiles[i][j].get_size()1892 x *= transform_obj.ratio/transform_obj.prev_ratio1893 y *= transform_obj.ratio/transform_obj.prev_ratio1894 load_images.Boy_tiles[i][j] = pygame.transform.scale(load_images.Boy_tiles[i][j],(int(x),int(y)))1895 1896 for i in range(len(load_images.Girl_tiles)):1897 for j in range(len(load_images.Girl_tiles[i])):1898 (x,y) = load_images.Girl_tiles[i][j].get_size()1899 x *= transform_obj.ratio/transform_obj.prev_ratio1900 y *= transform_obj.ratio/transform_obj.prev_ratio1901 load_images.Girl_tiles[i][j] = pygame.transform.scale(load_images.Girl_tiles[i][j],(int(x),int(y)))1902 1903 1904 1905 else:1906 if self.House_flag:1907 load_images.load_images_facility('HOUSE',model.House.get_level())1908 1909 for i in range(len(load_images.House_tiles_list)):1910 for j in range(len(load_images.House_tiles_list[i])):1911 (x,y) = resize_pos(load_images.House_tiles_list[i][j].get_size())1912 x *= transform_obj.ratio1913 y *= transform_obj.ratio1914 load_images.House_tiles_list[i][j] = pygame.transform.scale(load_images.House_tiles_list[i][j],(int(x),int(y)))1915 1916 if self.Hospital_flag:1917 load_images.load_images_facility('HOSPITAL',model.Hospital.get_level())1918 1919 for i in range(len(load_images.Hospital_tiles_list)):1920 for j in range(len(load_images.Hospital_tiles_list[i])):1921 (x,y) = resize_pos(load_images.Hospital_tiles_list[i][j].get_size())1922 x *= transform_obj.ratio1923 y *= transform_obj.ratio1924 load_images.Hospital_tiles_list[i][j] = pygame.transform.scale(load_images.Hospital_tiles_list[i][j],(int(x),int(y)))1925 if self.Workshop_flag:1926 load_images.load_images_facility('WORKSHOP',model.Workshop.get_level())1927 1928 for i in range(len(load_images.Workshop_tiles_list)):1929 for j in range(len(load_images.Workshop_tiles_list[i])):1930 (x,y) = resize_pos(load_images.Workshop_tiles_list[i][j].get_size())1931 x *= transform_obj.ratio1932 y *= transform_obj.ratio1933 load_images.Workshop_tiles_list[i][j] = pygame.transform.scale(load_images.Workshop_tiles_list[i][j],(int(x),int(y)))1934 if self.School_flag: 1935 load_images.load_images_facility('SCHOOL',model.School.get_level())1936 1937 for i in range(len(load_images.School_tiles_list)):1938 for j in range(len(load_images.School_tiles_list[i])):1939 (x,y) = resize_pos(load_images.School_tiles_list[i][j].get_size())1940 x *= transform_obj.ratio1941 y *= transform_obj.ratio1942 load_images.School_tiles_list[i][j] = pygame.transform.scale(load_images.School_tiles_list[i][j],(int(x),int(y)))1943 if self.Fountain_flag:1944 load_images.load_images_facility('FOUNTAIN',model.Fountain.get_level())1945 1946 for i in range(len(load_images.Fountain_tiles)):1947 for j in range(len(load_images.Fountain_tiles[i])):1948 (x,y) = resize_pos(load_images.Fountain_tiles[i][j].get_size())1949 x *= transform_obj.ratio1950 y *= transform_obj.ratio1951 load_images.Fountain_tiles[i][j] = pygame.transform.scale(load_images.Fountain_tiles[i][j],(int(x),int(y)))1952 1953 if self.Farm_flag:1954 load_images.load_images_facility('FARM',model.Farm.get_level())1955 1956 for i in range(len(load_images.Farm_tiles)):1957 for j in range(len(load_images.Farm_tiles[i])):1958 (x,y) = resize_pos(load_images.Farm_tiles[i][j].get_size())1959 x *= transform_obj.ratio1960 y *= transform_obj.ratio1961 load_images.Farm_tiles[i][j] = pygame.transform.scale(load_images.Farm_tiles[i][j],(int(x),int(y)))1962 1963 load_images.load_images_ppl()1964 1965 for i in range(len(load_images.Man_tiles)):1966 for j in range(len(load_images.Man_tiles[i])):1967 (x,y) = resize_pos(load_images.Man_tiles[i][j].get_size())1968 x *= transform_obj.ratio1969 y *= transform_obj.ratio1970 load_images.Man_tiles[i][j] = pygame.transform.scale(load_images.Man_tiles[i][j],(int(x),int(y)))1971 1972 for i in range(len(load_images.Woman_tiles)):1973 for j in range(len(load_images.Woman_tiles[i])):1974 (x,y) = resize_pos(load_images.Woman_tiles[i][j].get_size())1975 x *= transform_obj.ratio1976 y *= transform_obj.ratio1977 load_images.Woman_tiles[i][j] = pygame.transform.scale(load_images.Woman_tiles[i][j],(int(x),int(y)))1978 1979 for i in range(len(load_images.Boy_tiles)):1980 for j in range(len(load_images.Boy_tiles[i])):1981 (x,y) = resize_pos(load_images.Boy_tiles[i][j].get_size())1982 x *= transform_obj.ratio1983 y *= transform_obj.ratio1984 load_images.Boy_tiles[i][j] = pygame.transform.scale(load_images.Boy_tiles[i][j],(int(x),int(y)))1985 1986 for i in range(len(load_images.Girl_tiles)):1987 for j in range(len(load_images.Girl_tiles[i])):1988 (x,y) = resize_pos(load_images.Girl_tiles[i][j].get_size())1989 x *= transform_obj.ratio1990 y *= transform_obj.ratio1991 load_images.Girl_tiles[i][j] = pygame.transform.scale(load_images.Girl_tiles[i][j],(int(x),int(y)))1992 1993 1994 def initialize_facility(self,facility_name = '',level = 0):1995 1996 if facility_name == 'HOUSE' and (not self.House_flag):1997 1998 load_images.load_images_facility('HOUSE',model.House.get_level())1999 self.House_flag = True 2000 for i in range(len(load_images.House_tiles_list)):2001 for j in range(len(load_images.House_tiles_list[i])):2002 (x,y) = resize_pos(load_images.House_tiles_list[i][j].get_size())2003 x *= transform_obj.ratio2004 y *= transform_obj.ratio2005 load_images.House_tiles_list[i][j] = pygame.transform.scale(load_images.House_tiles_list[i][j],(int(x),int(y)))2006 2007 if facility_name == 'HOSPITAL' and (not self.Hospital_flag):2008 2009 load_images.load_images_facility('HOSPITAL',model.Hospital.get_level())2010 self.Hospital_flag = True 2011 for i in range(len(load_images.Hospital_tiles_list)):2012 for j in range(len(load_images.Hospital_tiles_list[i])):2013 (x,y) = resize_pos(load_images.Hospital_tiles_list[i][j].get_size())2014 x *= transform_obj.ratio2015 y *= transform_obj.ratio2016 load_images.Hospital_tiles_list[i][j] = pygame.transform.scale(load_images.Hospital_tiles_list[i][j],(int(x),int(y)))2017 2018 if facility_name == 'WORKSHOP' and (not self.Workshop_flag):2019 2020 load_images.load_images_facility('WORKSHOP',model.Workshop.get_level())2021 self.Workshop_flag = True2022 for i in range(len(load_images.Workshop_tiles_list)):2023 for j in range(len(load_images.Workshop_tiles_list[i])):2024 (x,y) = resize_pos(load_images.Workshop_tiles_list[i][j].get_size())2025 x *= transform_obj.ratio2026 y *= transform_obj.ratio2027 load_images.Workshop_tiles_list[i][j] = pygame.transform.scale(load_images.Workshop_tiles_list[i][j],(int(x),int(y)))2028 2029 if facility_name == 'SCHOOL' and (not self.School_flag):2030 2031 load_images.load_images_facility('SCHOOL',model.School.get_level())2032 self.School_flag = True2033 for i in range(len(load_images.School_tiles_list)):2034 for j in range(len(load_images.School_tiles_list[i])):2035 (x,y) = resize_pos(load_images.School_tiles_list[i][j].get_size())2036 x *= transform_obj.ratio2037 y *= transform_obj.ratio2038 load_images.School_tiles_list[i][j] = pygame.transform.scale(load_images.School_tiles_list[i][j],(int(x),int(y)))2039 2040 if facility_name == 'FOUNTAIN' and (not self.Fountain_flag):2041 2042 load_images.load_images_facility('FOUNTAIN',model.Fountain.get_level())2043 self.Fountain_flag = True2044 for i in range(len(load_images.Fountain_tiles)):2045 for j in range(len(load_images.Fountain_tiles[i])):2046 (x,y) = resize_pos(load_images.Fountain_tiles[i][j].get_size())2047 x *= transform_obj.ratio2048 y *= transform_obj.ratio2049 load_images.Fountain_tiles[i][j] = pygame.transform.scale(load_images.Fountain_tiles[i][j],(int(x),int(y)))2050 2051 2052 if facility_name == 'FARM' and (not self.Farm_flag):2053 2054 load_images.load_images_facility('FARM',model.Farm.get_level())2055 self.Farm_flag = True 2056 for i in range(len(load_images.Farm_tiles)):2057 for j in range(len(load_images.Farm_tiles[i])):2058 (x,y) = resize_pos(load_images.Farm_tiles[i][j].get_size())2059 x *= transform_obj.ratio2060 y *= transform_obj.ratio2061 load_images.Farm_tiles[i][j] = pygame.transform.scale(load_images.Farm_tiles[i][j],(int(x),int(y)))2062 2063images_obj = update_images()2064class Animation:2065 2066 def __init__(self):2067 2068 2069 2070 global env2071 if model.FLAG_XO:2072 env = Environment()2073 else:2074 env = Environment2()2075 env.update_background()2076 mkt = Build('market.png',2800,2500)2077 mkt.add(all,market)2078 2079 2080 2081 def update(self):2082 ''' Creates the final surface with the background and all and with the sprites too '''2083 2084 transform_obj.move()2085 transform_obj.check_pos() 2086 if natural_calamities:2087 #natural_calamities.clear(screen,self.background)2088 natural_calamities.update()2089 2090 images_obj.update_images()2091 check_sprite = screen_sprite()2092 #screen.blit(self.background,(0,resize_pt_y(40)))2093 #all_drawable.clear(screen,self.background)2094 env.update_background()2095 2096 all_drawable.empty()2097 all.update()2098 drawable_sprites = pygame.sprite.spritecollide(check_sprite,all,False)2099 for sprite in drawable_sprites:2100 sprite.set_frame()2101 sprite.add(all_drawable)2102 2103 2104 # Checking for collision of villagers nd other facilities and the market2105 collide = pygame.sprite.groupcollide(villagers, facilities_group, False, False)2106 for villager in collide.keys():2107 villager.collide_build()2108 collide = pygame.sprite.groupcollide(villagers, market, False, False)2109 for villager in collide.keys():2110 villager.collide_build()2111 collide = pygame.sprite.groupcollide(villagers, facilities_group, False, False)2112 for villager in collide.keys():2113 new_sprite = Villager(villager.get_attributes())2114 villager.remove(all,villagers)2115 villager.kill()2116 new_sprite.add(villagers,all)2117 collide = pygame.sprite.groupcollide(villagers, market, False, False)2118 for villager in collide.keys():2119 new_sprite = Villager(villager.get_attributes())2120 villager.remove(all,villagers)2121 villager.kill()2122 new_sprite.add(villagers,all)2123 check_villagers_self_collision()2124 2125 2126 all_drawable.draw(screen) 2127 if natural_calamities:2128 natural_calamities.draw(screen)2129 transform_obj.prev_ratio = transform_obj.ratio2130 2131class Sounds:2132 '''Controls the sounds'''2133 def __init__(self):2134 self.SOUND_PATH = SOUND_PATH2135 self.SOUND_DIC = {}2136 self.SOUND_DIC = self.load_sound()2137 self.volume = SOUND_VOLUME2138 2139 def load_sound(self,sound_path = SOUND_PATH):2140 '''Gets a dictionary of sounds with just their names from SOUND_PATH and loads them into buffer'''2141 sound_list = glob.glob(os.path.join(SOUND_PATH,'*.ogg'))2142 sound_dic = {}2143 for sound_name in sound_list:2144 try:2145 sound_dic[sound_name] = pygame.mixer.Sound(sound_name)2146 except Exception is e:2147 sound_dic[sound_name] = None2148 print "Error Loading Sound: " + str(e)+ '\n ' + sound_name2149 return sound_dic2150 2151 def play_sound(self,sound_name,volume = SOUND_VOLUME):2152 '''Plays the requested sound effect2153 The function shuffles between the available sound effects2154 volume: [0.0 to 1.0] :volume [left, right]2155 '''2156 sound_set = []2157 for key in self.SOUND_DIC:2158 if sound_name in key:2159 sound_set.append(key)2160 sound_name = sound_set[random.randrange(0,len(sound_set))]2161 sound_object = self.SOUND_DIC[sound_name]2162 2163 if sound_object:2164 channel = sound_object.play()2165 channel.set_volume(volume[0],volume[1])2166 2167 def play_music(self,storyboard_music_enabled,sound_name):2168 if storyboard_music_enabled:2169 if sound_name != 'soundtrack':2170 loop = 12171 else:2172 loop = -12173 if pygame.mixer.get_busy():2174 pygame.mixer.music.stop()2175 pygame.mixer.music.load(os.path.join('storyboards',str(model.storyboard_file),sound_name+'.ogg'))2176 pygame.mixer.music.play(loop)2177 pygame.mixer.music.set_volume((self.volume[0]+self.volume[1])/2)2178 else:2179 if pygame.mixer.get_busy():2180 pygame.mixer.music.stop()2181 pygame.mixer.music.load(os.path.join('sounds','soundtrack.ogg'))2182 pygame.mixer.music.play(-1)2183 pygame.mixer.music.set_volume((self.volume[0]+self.volume[1])/2)2184 2185 def stop_soundtrack(self):2186 pygame.mixer.music.stop()2187 2188 def safe_exit(self):2189 pygame.mixer.stop()2190 2191 def pause_music(self):2192 pygame.mixer.pause()2193 2194natural_calamities = pygame.sprite.RenderUpdates()2195villagers = pygame.sprite.Group()2196all = pygame.sprite.RenderUpdates() 2197facilities_group = pygame.sprite.Group()2198market = pygame.sprite.Group()2199transform_obj = Transform()2200audio = Sounds()...

Full Screen

Full Screen

player.py

Source:player.py Github

copy

Full Screen

...6class Player(pygame.sprite.Sprite):7 def __init__(self, name, state):8 pygame.sprite.Sprite.__init__(self, self.containers)9 self.name = name10 self.walkright_images = load_images(state + '' + name + ' run 1.png', state + '' + name + ' run 2.png',11 state + '' + name + ' run 3.png', state + '' + name + ' run 2.png')12 self.walkleft_images = load_images(state + '' + name + ' run 1.png', state + '' + name + ' run 2.png',13 state + '' + name + ' run 3.png', state + '' + name + ' run 2.png')14 15 self.walkleft_images[0] = pygame.transform.flip(self.walkleft_images[0], True, False)16 self.walkleft_images[1] = pygame.transform.flip(self.walkleft_images[1], True, False)17 self.walkleft_images[2] = pygame.transform.flip(self.walkleft_images[2], True, False)18 self.walkleft_images[3] = pygame.transform.flip(self.walkleft_images[3], True, False)19 self.skid_left_images = load_images(state + '' + name + ' Skid Left.png')20 self.skid_right_images = load_images(state + '' + name + ' Skid Right.png')21 self.jumpright_images = load_images(state + '' + name + ' jump.png')22 self.jumpleft_images = load_images(state + '' + name + ' jump.png')23 self.jumpleft_images[0] = pygame.transform.flip(self.jumpleft_images[0], True, False)24 self.standleft_images = load_images(state + '' + name + ' stand.png')25 self.standleft_images[0] = pygame.transform.flip(self.standleft_images[0], True, False)26 self.standright_images = load_images(state + '' + name + ' stand.png')27 self.throw_images = load_images('Fiery Mario Throw.png')28 self.throw_images2 = load_images('Fiery Mario Throw.png')29 self.throw_images2[0] = pygame.transform.flip(self.throw_images2[0], True, False)30 if main.STATE == 1:31 self.transferimgs = load_images(name + ' stand2.png', 'Super ' + name + ' Stand.png')32 if main.STATE == 2:33 self.transferimgs = load_images('Super ' + name + ' Stand.png', 'Fiery ' + name + ' Stand.png')34 else:35 self.transferimgs = load_images(name + ' Stand2.png', 'Super ' + name + ' Stand.png')36 self.rectimage = load_image(state + name + ' Rect.png')37 self.rectimage.set_colorkey((255, 255, 255), RLEACCEL)38 self.image = load_image(state + name + ' Rect.png')39 self.x = SCREENRECT.centerx40 self.y = 18041 42 self.rect = self.image.get_rect(center=(self.x, self.y)) 43 self.speed = 044 self.max_speed = 445 self.animation_speed = 446 self.jump_speed = 047 self.jumping = True48 self.jump_power = 11.549 self.keydown_fall_speed = 0.13250 self.keyup_fall_speed = 0.7651 self.max_fall_speed = -1152 self.frame = 053 self.facing = 154 self.transfertimer = 055 self.transfering = False56 self.throw_timer = 057 def topwallcheck(self, rect):58 if self.jump_speed < 0 and \59 (self.rect.bottom - 16 < rect.top <= self.rect.bottom):60 self.rect.bottom = rect.top61 self.jump_speed = 0 62 self.jumping = False63 def bottomwallcheck(self, rect):64 if self.jump_speed > 0 and \65 (self.rect.top + 18 > rect.bottom >= self.rect.top):66 self.jump_speed = -167 self.rect.top = rect.bottom68 def sidewallcheck(self, rect, moving):69 if self.speed > 0 or self.speed < 0 and \70 (rect.left > self.rect.left or \71 rect.right < self.rect.right):72 if self.speed < 0 and self.rect.bottom > rect.top and self.rect.top < rect.bottom - 16:73 for s in self.sprites:74 s.rect.move_ip(self.speed, 0)75 if self.speed > 0 and self.rect.bottom > rect.top and self.rect.top < rect.bottom - 16:76 for s in self.sprites:77 s.rect.move_ip(self.speed, 0)78 def transfer(self):79 self.transfertimer = 2580 self.transfering = True81 def move(self, moving):82 if moving: self.facing = moving 83 if not self.transfering:84 self.rect.move_ip(0, -self.jump_speed)85 86 self.frame += 187 if self.jump_speed < 1:88 self.keyup_fall_speed = 1.289 self.keydown_fall_speed = 1.190 if self.jump_speed >= 1:91 self.keyup_fall_speed = 0.892 self.keydown_fall_speed = 0.493 if self.transfering:94 if self.transfertimer > 0:95 self.transfertimer -= 196 self.image = self.transferimgs[self.frame/4%2]97 if self.transfertimer <= 0:98 self.transfering = False99 if not moving and not self.jumping:100 if self.speed > 0:101 self.speed -= 0.25102 self.image = self.walkleft_images[self.frame/(self.animation_speed+1)%3]103 if self.speed < 0:104 self.speed += 0.25105 self.image = self.walkleft_images[self.frame/(self.animation_speed+1)%3]106 keystate = pygame.key.get_pressed()107 if keystate[K_x] and not self.jumping:108 self.max_speed = 5109 self.animation_speed = 2110 if not (keystate[K_x]) and not self.jumping:111 self.max_speed = 4112 self.animation_speed = 4113 if self.speed > 4:114 self.speed = 4115 if self.speed < -4:116 self.speed = -4117 if self.jump_speed < -2.8 and not pygame.sprite.spritecollide(self, self.platforms3, 0):118 self.jumping = True119 if moving > 0 and self.jumping == False and not self.transfering:120 if self.speed < self.max_speed:121 self.speed += 0.1875122 if self.speed < 0:123 self.image = self.skid_left_images[0]124 else:125 self.image = self.walkright_images[self.frame/self.animation_speed%3]126 if moving < 0 and self.jumping == False and not self.transfering:127 if self.speed > -self.max_speed:128 self.speed -= 0.1875129 if self.speed > 0:130 self.image = self.skid_right_images[0]131 else:132 self.image = self.walkleft_images[self.frame/self.animation_speed%3]133 if self.facing > 0 and not moving and self.jumping == False and not self.transfering:134 self.image = self.standright_images[0]135 if self.facing < 0 and not moving and self.jumping == False and not self.transfering:136 self.image = self.standleft_images[0]137 if self.facing > 0 and self.jumping == True and not self.transfering:138 if self.speed < self.max_speed and moving > 0:139 self.speed += 0.0625140 self.image = self.jumpright_images[0] 141 if self.facing < 0 and self.jumping == True and not self.transfering:142 if self.speed > -self.max_speed and moving < 0:143 self.speed -= 0.0625144 self.image = self.jumpleft_images[0]145 if (keystate[K_x]) and main.STATE == 3 and self.throw_timer > 0:146 if self.facing > 0:147 self.image = self.throw_images[0]148 if self.facing < 0:149 self.image = self.throw_images2[0]150 self.throw_timer -= 1151class PlayerDie(pygame.sprite.Sprite):152 defaultlife = 200153 animcycle = 3154 images = []155 def __init__(self, actor):156 pygame.sprite.Sprite.__init__(self, self.containers)157 self.images = load_images(actor.name + ' dead.png')158 self.image = self.images[0]159 self.orgImage = self.image.copy()160 self.rect = self.image.get_rect(center=actor.rect.center)161 self.life = self.defaultlife162 self.yspeed = -16163 self.frame = 0164 self.angle = 0165 def update(self):166 self.frame += 1167 self.rect.move_ip(0, self.yspeed)168 self.yspeed += 0.4169 self.life = self.life - 1170 if self.life <= 0:171 self.kill()172 def rotate(self, amount):173 self.oldCenter = self.rect.center174 self.angle -= -amount175 self.image = pygame.transform.rotate(self.orgImage, self.angle)176 self.rect = self.image.get_rect()177 self.rect.center = self.oldCenter178class PlayerWin(pygame.sprite.Sprite):179 animcycle = 4180 images = []181 def __init__(self, actor):182 pygame.sprite.Sprite.__init__(self, self.containers)183 if main.STATE == 1:184 self.slideimg = load_images(actor.name + ' Slide.png')185 self.fallimg = load_images(actor.name + ' Jump.png')186 self.images = load_images(actor.name + ' Run 1.png', actor.name + ' Run 2.png',187 actor.name + ' Run 3.png', actor.name + ' Run 2.png')188 if main.STATE == 2:189 self.slideimg = load_images('Super ' + actor.name + ' Slide.png')190 self.fallimg = load_images('Super ' + actor.name + ' Jump.png')191 self.images = load_images('Super ' + actor.name + ' Run 1.png',192 'Super ' + actor.name + ' Run 2.png',193 'Super ' + actor.name + ' Run 3.png',194 'Super ' + actor.name + ' Run 2.png')195 if main.STATE == 3:196 self.slideimg = load_images('Fiery Mario Slide.png')197 self.fallimg = load_images('Fiery Mario Jump.png')198 self.images = load_images('Fiery Mario Run 1.png',199 'Fiery Mario Run 2.png',200 'Fiery Mario Run 3.png',201 'Fiery Mario Run 2.png')202 self.image = self.images[0]203 self.rect = self.image.get_rect(center=actor.rect.center)204 self.rect.move_ip(2, 0)205 self.yspeed = 2206 self.frame = 0207 def update(self):208 self.frame += 1209 if not pygame.sprite.spritecollide(self, self.platforms, 0):210 if pygame.sprite.spritecollide(self, self.flags, 0):211 for flag in self.flags:212 if self.rect.left < flag.rect.left + 4:...

Full Screen

Full Screen

assets.py

Source:assets.py Github

copy

Full Screen

...4NONE_IMG = load_image(os.path.join(MAIN_PATH, "assets", "images", "none.png"))5# player animations6if (DEBUG): print("--- player animation ---")7PLAYER_ANIM = [8 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "dead*.png")), # dead9 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "idle*.png")), # idle10 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "move*.png")), # move11 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "jump*.png")), # jump12 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "fall*.png")), # fall13 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "hurt*.png")), # hurt14 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "atk1*.png")), # attack 115 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "player", "atk2*.png")), # attack 216 ]17# enemy animations18if (DEBUG): print("--- enemy animation ---")19ENEMY_ANIM = [20 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "dead*.png")), # dead21 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "idle*.png")), # idle22 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "move*.png")), # move23 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "jump*.png")), # jump24 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "fall*.png")), # fall25 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "hurt*.png")), # hurt26 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "atk1*.png")), # attack 127 load_images(os.path.join(MAIN_PATH, "assets", "images", "entity", "enemy", "atk2*.png")), # attack 228 ]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful