Best Python code snippet using autotest_python
level_loader.py
Source:level_loader.py
...24 pos[1] = data['starty']25 player.set_pos(pos)26 bullet = player.get_bullet_system().bullet()27 if l.scroll == level.SIDESCROLL:28 bullet.set_velocity((bullet.get_speed()[0], 0))29 l.set_scroll(level.SIDESCROLL)30 if l.scroll == level.TOPDOWN:31 l.set_scroll(level.TOPDOWN)32 bullet.set_velocity((0, -bullet.get_speed()[1]))33 for child in player.get_children():34 child.hide()35 child.kill()36 child.set_on_collision(scene.on_helper_collision)37 child.set_pos((player.get_pos()[0], player.get_pos()[1]))38 bullet = child.get_bullet_system().bullet()39 if l.scroll == level.SIDESCROLL:40 child.set_velocity((-child.get_speed()[0], 0))41 bullet.set_velocity((bullet.get_speed()[0], 0))42 if l.scroll == level.TOPDOWN:43 child.set_velocity((0, child.get_speed()[1]))44 bullet.set_velocity((0, -bullet.get_speed()[1]))45 l.set_player(player)46 if 'enemies' in data:47 for enemy_data in data['enemies']:48 if 'id' in enemy_data:49 enemy = scene.node_loader.load('enemies/{}.node'.format(enemy_data['id']))50 enemy.set_on_collision(scene.on_enemy_collision)51 enemy.birth()52 enemy.hide()53 pos = enemy.get_pos()54 if 'x' in enemy_data:55 pos[0] = enemy_data['x']56 if 'y' in enemy_data:57 pos[1] = enemy_data['y']58 enemy.set_pos(pos)59 vel = [0, 0]60 if enemy.get_bullet_system():61 bullet = enemy.get_bullet_system().bullet()62 if l.scroll == level.SIDESCROLL:63 vel[0] = -enemy.get_speed()[0]64 if bullet:65 bullet.set_velocity((-bullet.get_speed()[0], 0))66 elif l.scroll == level.TOPDOWN:67 vel[1] = enemy.get_speed()[1]68 if bullet:69 bullet.set_velocity((0, bullet.get_speed()[1]))70 enemy.set_velocity(vel)71 l.add_enemy(enemy)72 else:73 print(level_file, ":Enemy ID Missing")...
Car.py
Source:Car.py
...13 def get_year_model(self):14 return self.__year_model15 def get_make(self):16 return self.__make17 def get_speed(self):18 return self.__speed19 def accelerate(self):20 self.__speed += 521 def brake(self):22 self.__speed -= 523 if (self.__speed<0):24 self.__speed = 025if __name__ == '__main__':26 Car = Car(2000, 'Rain')27 print()28 print('Accelerate')29 #130 Car.accelerate()31 print(Car.get_speed())32 #233 Car.accelerate()34 print(Car.get_speed())35 #336 Car.accelerate()37 print(Car.get_speed())38 #439 Car.accelerate()40 print(Car.get_speed())41 #542 Car.accelerate()43 print(Car.get_speed())44 print()45 print('Brake')46 # 147 Car.brake()48 print(Car.get_speed())49 # 250 Car.brake()51 print(Car.get_speed())52 # 353 Car.brake()54 print(Car.get_speed())55 # 456 Car.brake()57 print(Car.get_speed())58 # 559 Car.brake()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!