|
| 1 | +#! /usr/bin/python |
| 2 | +#-*- coding: utf-8 -*- |
| 3 | + |
| 4 | +from robot import Robot #Import a base Robot |
| 5 | + |
| 6 | + |
| 7 | +class Demo(Robot): #Create a Robot |
| 8 | + |
| 9 | + def init(self):# NECESARY FOR THE GAME To initialyse your robot |
| 10 | + |
| 11 | + |
| 12 | + #Set the bot color in RGB |
| 13 | + self.setColor(0, 200, 100) |
| 14 | + self.setGunColor(200, 200, 0) |
| 15 | + self.setRadarColor(255, 60, 0) |
| 16 | + self.setBulletsColor(0, 200, 100) |
| 17 | + |
| 18 | + #get the map size |
| 19 | + size = self.getMapSize() #get the map size |
| 20 | + self.radarVisible(True) # show the radarField |
| 21 | + |
| 22 | + |
| 23 | + def run(self): #NECESARY FOR THE GAME main loop to command the bot |
| 24 | + |
| 25 | + |
| 26 | + self.move(90) # for moving (negative values go back) |
| 27 | + self.turn(360) #for turning (negative values turn counter-clockwise) |
| 28 | + self.stop() |
| 29 | + """ |
| 30 | + the stop command is used to make moving sequences: here the robot will move 90steps and turn 360° at the same time |
| 31 | + and next, fire |
| 32 | + """ |
| 33 | + |
| 34 | + |
| 35 | + self.fire(3) # To Fire (power between 1 and 10) |
| 36 | + |
| 37 | + self.move(100) |
| 38 | + self.turn(50) |
| 39 | + self.stop() |
| 40 | + bulletId = self.fire(2) #to let you you manage if the bullet hit or fail |
| 41 | + self.move(180) |
| 42 | + self.turn(180) |
| 43 | + self.gunTurn(90) #to turn the gun (negative values turn counter-clockwise) |
| 44 | + self.stop() |
| 45 | + self.fire(1) # To Fire (power between 1 and 10) |
| 46 | + self.radarTurn(180) #to turn the radar (negative values turn counter-clockwise) |
| 47 | + self.stop() |
| 48 | + |
| 49 | + def sensors(self): #NECESARY FOR THE GAME |
| 50 | + """Tick each frame to have datas about the game""" |
| 51 | + |
| 52 | + pos = self.getPosition() #return the center of the bot |
| 53 | + x = pos.x() #get the x coordinate |
| 54 | + y = pos.y() #get the y coordinate |
| 55 | + |
| 56 | + angle = self.getGunHeading() #Returns the direction that the robot's gun is facing |
| 57 | + angle = self.getHeading() #Returns the direction that the robot is facing |
| 58 | + angle = self.getRadarHeading() #Returns the direction that the robot's radar is facing |
| 59 | + list = self.getEnemiesLeft() #return a list of the enemies alive in the battle |
| 60 | + for robot in list: |
| 61 | + id = robot["id"] |
| 62 | + name = robot["name"] |
| 63 | + # each element of the list is a dictionnary with the bot's id and the bot's name |
| 64 | + |
| 65 | + def onHitByRobot(self, robotId, robotName): |
| 66 | + self.rPrint("damn a bot collided me!") |
| 67 | + |
| 68 | + def onHitWall(self): |
| 69 | + self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event) |
| 70 | + self.pause(100) |
| 71 | + self.move(-100) |
| 72 | + self.rPrint('ouch! a wall !') |
| 73 | + self.setRadarField("large") #Change the radar field form |
| 74 | + |
| 75 | + def onRobotHit(self, robotId, robotName): # when My bot hit another |
| 76 | + self.rPrint('collision with:' + str(robotName)) #Print information in the robotMenu (click on the righ panel to see it) |
| 77 | + |
| 78 | + def onHitByBullet(self, bulletBotId, bulletBotName, bulletPower): #NECESARY FOR THE GAME |
| 79 | + """ When i'm hit by a bullet""" |
| 80 | + self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event) |
| 81 | + self.rPrint ("hit by " + str(bulletBotName) + "with power:" +str( bulletPower)) |
| 82 | + |
| 83 | + def onBulletHit(self, botId, bulletId):#NECESARY FOR THE GAME |
| 84 | + """when my bullet hit a bot""" |
| 85 | + self.rPrint ("fire done on " +str( botId)) |
| 86 | + |
| 87 | + |
| 88 | + def onBulletMiss(self, bulletId):#NECESARY FOR THE GAME |
| 89 | + """when my bullet hit a wall""" |
| 90 | + self.rPrint ("the bullet "+ str(bulletId) + " fail") |
| 91 | + self.pause(10) #wait 10 frames |
| 92 | + |
| 93 | + def onRobotDeath(self):#NECESARY FOR THE GAME |
| 94 | + """When my bot die""" |
| 95 | + self.rPrint ("damn I'm Dead") |
| 96 | + |
| 97 | + def onTargetSpotted(self, botId, botName, botPos):#NECESARY FOR THE GAME |
| 98 | + "when the bot see another one" |
| 99 | + self.fire(5) |
| 100 | + self.rPrint("I see the bot:" + str(botId) + "on position: x:" + str(botPos.x()) + " , y:" + str(botPos.y())) |
| 101 | + |
0 commit comments