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