def move(self): #self.x += 2 #self.y += 1 # with the following code we get the frantic move we expected #self.x += random.randrange(-1,2) #self.y += random.randrange(-1,2) global speed global xspeed global lost global box global countreac if self.y >= HEIGHT / 2. - 3 * basesize - sundiam / 2: speed = 0 banner("Burnt!") lost = True engine.exit_engine() elif self.y > (-1 * HEIGHT / 2 + basesize + speed + 20) or speed < 0: # le zéro de la fusée est au coin supérieur droit du réacteur gauche self.y -= speed speed += 0.02 else: if abs(speed) > 2: banner("Crashed!") else: banner("Landed!") self.y = -1 * HEIGHT / 2 + basesize speed = 0 engine.exit_engine() countreac += 1 if countreac > 20: box.color = "black"
def keyboard_cb(key): global ship # assuming it's unique (and this is the case!) global spd # the accelerometer if key == 'q' and ship.fuel_level > 0: ship.mode = 1 ship.acceleration += 0.05 reg_speed_bar(100 * ship.acceleration) spd.shape = "speed" ship.shape = "powered_lander" elif key == 's': ship.acceleration -= 0.05 reg_speed_bar(100 * ship.acceleration) spd.shape = "speed" if ship.acceleration <= 0: ship.acceleration = 0 ship.mode = 0 ship.shape = "lander" elif key == 'Escape': engine.exit_engine() elif key == 'Right': ship.head -= 8 elif key == 'Left': ship.head += 8 elif key == "space": shoot(ship)
def keyboard_cb(key): # Problem on some machines: if a key stays pressed, then # there is a delay between the first key event being triggered # and the next ones (this is the damn repeat delay) # How to get around this issue? global ship global countreac if key == 'q' and ship.fuelLevel > 0: ship.mode = 1 ship.gazpower += 0.05 drawSpeedBar(100 * ship.gazpower) spd.shape = "speed" ship.shape = "fusee reac" elif key == 's': ship.gazpower -= 0.05 drawSpeedBar(100 * ship.gazpower) spd.shape = "speed" if ship.gazpower <= 0: ship.gazpower = 0 ship.mode = 0 ship.shape = "fusee" elif key == 'Escape': #print("Au revoir...") engine.exit_engine() elif key == 'Right': ship.head -= 2 elif key == 'Left': ship.head += 2
def genericGroundCollisionCall(ship, gnd): step = 0 orig = 0 for i in range(len(gnd.ground) - 1): x0 = gnd.ground[i][0] y0 = gnd.ground[i][1] x1 = gnd.ground[i + 1][0] y1 = gnd.ground[i + 1][1] y = ship.y + HEIGHT / 2 x = ship.x if x0 <= ship.x and ship.x <= x1: # Here we are! a = -1 * (y1 - y0) / (x1 - x0) b = 1 c = -1 * y0 + x0 * (y1 - y0) / (x1 - x0) d = abs(a * x + b * y + c) / math.sqrt(a**2 + b**2) print(math.sqrt(xspeed**2 + yspeed**2)) if (d <= 2 * basesize and a != 0) or (d <= 2 * basesize and a == 0 and (abs(shiphead) >= 15 or math.sqrt(xspeed**2 + yspeed**2) >= 1)): banner("Crashed!") engine.exit_engine() elif (d <= 2 * basesize and a == 0 and abs(shiphead) < 15): banner("Landed!") engine.exit_engine()
def move(self): global speed global xspeed global lost global box global countreac if self.y >= HEIGHT / 2. - 3 * basesize - sundiam / 2: speed = 0 banner("Burnt!") lost = True engine.exit_engine() elif self.y > (-1 * HEIGHT / 2 + basesize + speed + 20) or speed < 0: # le zéro de la fusée est au coin supérieur droit du réacteur gauche self.y -= speed speed += 0.02 else: if abs(speed) > 2: banner("Crashed!") else: banner("Landed!") self.y = -1 * HEIGHT / 2 + basesize speed = 0 engine.exit_engine() countreac += 1 if countreac > 20: box.color = "black"
def gameplay(self): global pickedupkeys, doorsopened, lkey pickupkey(0, 4, 0, 0, 4, -268, 0) dooropening(0, 4, 1, 0, -300, 0, 0, 10) pickupkey(1, 4, 1, 1, 2, -268, 0) dooropening(1, 2, 2, 1, -300, 0, 0, 10) pickupkey(0, 0, 2, 1, 1, 0, 268) dooropening(1, 1, 3, 2, 0, 300, 10, 0) pickupkey(0, 1, 3, 2, 2, 268, 0) dooropening(2, 2, 4, 3, 300, 0, 0, 10) if bossbeaten == 1: if ldoor[2][3] != []: (door, x, y) = ldoor[2][3][0] key = lkey[2][3][0] if door.y < 400: door.y += 10 key.y += 10 else: engine.del_obj(door) engine.del_obj(key) ldoor[2][3].remove((door, x, y)) lkey[2][3].remove(key) if posi == 2 and posj == 4: banner('You won!') engine.exit_engine()
def move(self): global COUNTDOWN, rocket, gravity self.x += self.speed * math.cos(math.radians(180 - self.angle)) self.y -= self.speed * math.sin( math.radians(180 - self.angle)) + gravity gravity = min(gravity + GRAVITYSTEP, GRAVITYMAX) if self.speed < 0: self.speed += SPEEDDECREASESTEP if COUNTDOWN > 0: COUNTDOWN -= 1 else: rocket.shape = skin Lplatform = self.canland() for landingpad in Lplatform: if landingpad > -LENGTH and self.y <= landingpad + radius: if gravity - self.speed > 1 or self.angle % 360 != 90: banner('Game over') engine.exit_engine() else: self.speed = 0 gravity = 0 if self.collide_gnd(): banner('Game over') engine.exit_engine()
def input_cb(key): if key == 'q' or key == 'Q': engine.exit_engine() elif key == 'Up': me.adjustalpha(STEPALPHA) elif key == 'Down': me.adjustalpha(-STEPALPHA) elif key == 'Left': me.adjustbeta(-STEPBETA) elif key == 'Right': me.adjustbeta(STEPBETA) elif key == 'space': if not me.canshoot(): return me.recoil() # ignore travel distance and make the bullet instantaneous # just need to find the coordinates where it hit alpha = me.getalpha() beta = me.getbeta() alpharad = math.radians(alpha) betarad = math.radians(beta) # find y using trigonometry from side view y = DISTANCE * math.tan(alpharad) + GUNY # this calculation isn't correct from a 3D point of view # but it looks right onscreen x = GUNLEN * math.tan(betarad) engine.add_obj(Shot(x, y))
def keyboard_cb(key): global rocket, countdown, gravity if key == 'Escape': engine.exit_engine() if key == 'Up': rocket.speed -= SPEEDBOOST rocket.shape = skin + " powered" countdown = 20 gravity = max(0, gravity - 1) if key == 'Left': rocket.angle += 30 if key == 'Right': rocket.angle -= 30 if key == 'm': rocket.speed = 0 rocket = Rocket() engine.add_obj(rocket) if key == 'space': engine.add_obj(NiceBullet(rocket.x, rocket.y, 90 + rocket.angle))
def keyboard_cb(key): global IN_JUMP if key == 'e': engine.exit_engine() elif key == 'Return' and not IN_JUMP: IN_JUMP = True elif key == 'space'and not IN_JUMP and MISSILE_COUNT_UP < 2 and MISSILE_COUNT_RIGHT < 2 and IS_CAR: engine.add_obj(MissleVertical(15, GROUND_Y + 10, (SPEED * 2), 'blue')) engine.add_obj(MissileRight())
def keyboard_cb(key): if key == 'space': box = Box() engine.add_obj(box) elif key == 'Escape': print("Au revoir... Giscard!") engine.exit_engine() else: print(key)
def input_cb(key): global heading if key == 'q' or key == 'Q': engine.exit_engine() elif key == 'Left': heading = (heading + HEADINGSTEP) % 360 elif key == 'Right': heading = (heading - HEADINGSTEP) % 360 recalcdeltas()
def keyboard_cb(key): global speed if key == 'Escape': engine.exit_engine() if key == 'space': speed -= 5 if key == 'm' : speed = 0 box = Box() engine.add_obj(box)
def move(self): self.x += self.speed * math.cos(math.radians(180 - self.angle)) self.y -= self.speed * math.sin(math.radians(180 - self.angle)) if self.collide(): banner('Game over') engine.exit_engine() if self.collide_gnd(): self.shape = 'whitebullet' engine.del_obj(self)
def input_cb(key): x, y, r = s.me.get_bc() if key == 'q' or key == 'Q': engine.exit_engine() elif key == 'Left' and x - r > MINX: s.me.setx(x - MOVELEN) s.me.update() elif key == 'Right' and x + r < MAXX: s.me.setx(x + MOVELEN) s.me.update() elif key == 'space': engine.add_obj(MyShot(x, y, 0, MYSHOTSPEED))
def input_cb(key): x, y, r = s.me.get_bc() if key == "q" or key == "Q": engine.exit_engine() elif key == "Left" and x - r > MINX: s.me.setx(x - MOVELEN) s.me.update() elif key == "Right" and x + r < MAXX: s.me.setx(x + MOVELEN) s.me.update() elif key == "space": engine.add_obj(MyShot(x, y, 0, MYSHOTSPEED))
def collision_ship_ground(lander, terrain): step = 0 orig = 0 y = lander.y + HEIGHT / 2 x = lander.x - terrain.x for i in range(len(terrain.ground) - 1): x0 = terrain.ground[i][0] y0 = terrain.ground[i][1] x1 = terrain.ground[i + 1][0] y1 = terrain.ground[i + 1][1] if x0 <= x and x <= x1 and x1 != x0 and y - 2 * basesize < max(y1, y0): # BAD HACK: there should be no test on y a = y0 - y1 b = x1 - x0 c = (x0 - x1) * y0 + (y1 - y0) * x0 d = abs(a * x + b * y + c) / math.sqrt(a**2 + b**2) if (d <= basesize and a != 0): banner("Crash!") engine.exit_engine() elif (d <= 2 * basesize and abs(a) <= 1 and abs(lander.head) >= 15): banner("Crash on one reactor!") engine.exit_engine() elif (d <= 2 * basesize and abs(a) <= 1 and math.sqrt(lander.xspeed**2 + lander.yspeed**2) >= 2): banner("Fast crash...") engine.exit_engine() elif (d <= 2 * basesize and abs(a) <= 1 and abs(lander.head) < 15): banner("Landed!") engine.exit_engine()
def genericGroundCollisionCall(ship, gnd): step = 0 orig = 0 y = ship.y + HEIGHT /2 x = ship.x - gnd.x for i in range(len(gnd.ground)-1): x0 = gnd.ground[i][0] y0 = gnd.ground[i][1] x1 = gnd.ground[i+1][0] y1 = gnd.ground[i+1][1] if x0 <= x and x <= x1 and x1 != x0 and y - 2 * basesize < max(y1, y0): # BAD HACK: le test sur y ne doit pas être nécessaire # mathématiquement parlant a = y0 - y1 b = x1 - x0 c = (x0 - x1) * y0 + (y1 - y0) * x0 d = abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2) #print(d) if (d <= basesize and a != 0): #print(str(x0) + ":" + str(y0) + ";" + str(x1) + ":" + str(y1)) banner("Crashed!") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and abs(ship.head) >= 15): banner("Crash on one reactor!") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and math.sqrt(ship.xspeed ** 2 + \ ship.yspeed ** 2) >= 1 ): banner("Fast crash...") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and abs(ship.head) < 15): banner("Landed!") engine.exit_engine()
def collision_ship_ground(lander, terrain): step = 0 orig = 0 y = lander.y + HEIGHT / 2 x = lander.x - terrain.x for i in range(len(terrain.ground)-1): x0 = terrain.ground[i][0] y0 = terrain.ground[i][1] x1 = terrain.ground[i+1][0] y1 = terrain.ground[i+1][1] if x0 <= x and x <= x1 and x1 != x0 and y - 2 * basesize < max(y1, y0): # BAD HACK: there should be no test on y a = y0 - y1 b = x1 - x0 c = (x0 - x1) * y0 + (y1 - y0) * x0 d = abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2) if (d <= basesize and a != 0): banner("Crash!") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and abs(lander.head) >= 15): banner("Crash on one reactor!") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and math.sqrt(lander.xspeed ** 2 + lander.yspeed ** 2) >= 2): banner("Fast crash...") engine.exit_engine() elif (d <= 2*basesize and abs(a) <= 1 and abs(lander.head) < 15): banner("Landed!") engine.exit_engine()
def inputs(key): global count global county if key == 'Q' or key == 'q': engine.exit_engine() if key == 'space': if buggy1.deltay == 0: buggy1.deltay = 5 if key == 'Return' and jumping == False and count != 3 and count < 4 and county < 2: county = county + 1 count = count + 2 rocket1 = _rocket() rocket2 = _rocket2() engine.add_obj(rocket2) engine.add_obj(rocket1)
def losealife(self): global gravity, posi, posj, ground if self.lives == 0: banner('Game over') engine.exit_engine() else: self.lives -= 1 self.speed = 0 self.angle = 90 self.x = 0 self.y = 0 gravity = GRAVITYBASE banner("Life lost, {} remaining".format(self.lives)) posi = 0 posj = 4 load()
def keyboard_cb(key): global speed global xspeed global box global countreac if key == 'space': speed -= 0.2 box.color = "red" countreac = 0 elif key == 'Escape': print("Au revoir...") engine.exit_engine() elif key == 'Left': xspeed -= 0.1 elif key == 'Right': xspeed += 0.1 else: print(key)
def losealife(self): if self.lives == 0: game.banner('Game over') engine.exit_engine() game.Stats.display_stats() else: self.lives -= 1 self.speed[0] = self.speed[1] = 0 self.angle = 90 self.x = 0 self.y = 0 self.skin = Rocket.skin game.Game.freeze_spawn = True game.banner("Life lost, {} remaining".format(self.lives)) if game.Game.posi == 2 and game.Game.posj == 3 and not bad_guys.Boss.bossbeaten: engine.del_obj(game.Game.boss) game.Game.posi = 0 game.Game.posj = 4 game.load()
def move(self): global GRAVITY self.speed = self.speed + GRAVITY if self.motor_enable: self.speed = self.speed + LunarLander.MOTOR_ACCELERATION.rotate( self.heading()) self.position = self.position + self.speed if self.y > HEIGHT / 2 - 50: banner('Aaaaaah') engine.exit_engine() if self.y < -HEIGHT / 2 + 30: if abs(self.speed.y) > 2: banner('Yo Dead') else: banner('Landed') engine.exit_engine()
def move(self): global speed, countdown, rocket, gravity self.x += speed * math.cos(math.radians(180 - angle)) self.y -= speed * math.sin(math.radians(180 - angle)) + gravity gravity += gravitystep if speed < 0: speed += speeddecreasestep if countdown > 0: countdown -= 1 else: rocket.shape = skin if math.sqrt((self.y - 1170)**2 + self.x**2) < 1000 + radius: banner('Game over') engine.exit_engine() if self.y <= -220 + radius: if gravity - speed > 1 or angle % 360 != 90: banner('Game over') engine.exit_engine() else: banner('You won!') engine.exit_engine()
def keyboard_cb(key): global speed global xspeed global yspeed global ship global countreac global shiphead if key == "space" or key == "Up": xspeed = xspeed + math.sin(-3.1415926535 * shiphead / 180) * 0.2 yspeed = yspeed + math.cos(3.1415926535 * shiphead / 180) * 0.2 ship.shape = "fusee reac" countreac = 0 elif key == "Escape": print("Au revoir...") engine.exit_engine() elif key == "Right": shiphead -= 2 elif key == "Left": shiphead += 2 else: print(key)
def keyboard_cb(key): global speed global xspeed global yspeed global ship global countreac global shiphead if key == 'space' or key == 'Up': xspeed = xspeed + math.sin(-3.1415926535 * shiphead / 180) * 0.2 yspeed = yspeed + math.cos(3.1415926535 * shiphead / 180) * 0.2 ship.shape = "fusee reac" countreac = 0 elif key == 'Escape': print("Au revoir...") engine.exit_engine() elif key == 'Right': shiphead -= 2 elif key == 'Left': shiphead += 2 else: print(key)
def keyboard_cb(key): """keyboard manager""" turtle.setx(0) turtle.sety(0) Stats.key_pressed += 1 Game.freeze_spawn = False if key == 'Return': # Enter Game.pause = not Game.pause if key == 'Escape': engine.exit_engine() Stats.display_stats() if not Game.pause: if key == 'Up' or key == 'z': Game.rocket.rocket_up() if key == 'Left' or key == 'q': Game.rocket.rocket_left() if key == 'Right' or key == 'd': Game.rocket.rocket_right() if key == 'space': engine.add_obj( bullets.Bullet(Game.rocket.x, Game.rocket.y, 90 + Game.rocket.angle, True)) Stats.bullets_fired += 1
def gameplay(self): for door in shapes.Door.ldoor[Game.posi][Game.posj]: door.dooropening() for key in shapes.Key.lkey[Game.posi][Game.posj]: key.pickupkey() if bad_guys.Boss.bossbeaten: if shapes.Door.ldoor[Game.boss.posi][Game.boss.posj] != []: door = shapes.Door.ldoor[Game.boss.posi][Game.boss.posj][0] key = shapes.Key.lkey[Game.boss.posi][Game.boss.posj][0] if door.y < 400: door.y += 10 key.y += 10 else: engine.del_obj(door) engine.del_obj(key) shapes.Door.ldoor[Game.boss.posi][Game.boss.posj].remove(door) shapes.Key.lkey[Game.boss.posi][Game.boss.posj].remove(key) if Game.posi == Game.win_posi and Game.posj == Game.win_posj: banner('You won!') engine.exit_engine() Stats.display_stats()
def keyboard_main(key): """keyboard manager for the main menu""" y0 = game.Game.LENGTH / 9 if key == "Return": # enter engine.del_obj(Menu.select_arrow) Menu.select_arrow = None if Menu.cursor_position == 0: Menu.load_level_selection_menu() elif Menu.cursor_position == 2: Menu.load_skin_selection_menu() elif Menu.cursor_position == 3: engine.exit_engine() else: print("Feature not implemented yet") Menu.load_main_menu() else: if key == "Up": Menu.cursor_position = (Menu.cursor_position - 1) % 4 elif key == "Down": Menu.cursor_position = (Menu.cursor_position + 1) % 4 Menu.select_arrow.y = y0 - Menu.LINE_HEIGHT * Menu.cursor_position
def keyboard_cb(key): global speed, rocket, countdown, angle, gravity if key == 'Escape': engine.exit_engine() if key == 'Up': speed -= speedboost rocket.shape = skin + " powered" countdown = 20 gravity = 0 if key == 'Left': angle += 30 if key == 'Right': angle -= 30 if key == 'm': speed = 0 rocket = Rocket() engine.add_obj(rocket)
def genericGroundCollisionCall(ship, gnd): step = 0 orig = 0 for i in range(len(gnd.ground) - 1): x0 = gnd.ground[i][0] y0 = gnd.ground[i][1] x1 = gnd.ground[i + 1][0] y1 = gnd.ground[i + 1][1] y = ship.y + HEIGHT / 2 x = ship.x if x0 <= ship.x and ship.x <= x1: # Here we are! a = -1 * (y1 - y0) / (x1 - x0) b = 1 c = -1 * y0 + x0 * (y1 - y0) / (x1 - x0) d = abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2) print(math.sqrt(xspeed ** 2 + yspeed ** 2)) if (d <= 2 * basesize and a != 0) or ( d <= 2 * basesize and a == 0 and (abs(shiphead) >= 15 or math.sqrt(xspeed ** 2 + yspeed ** 2) >= 1) ): banner("Crashed!") engine.exit_engine() elif d <= 2 * basesize and a == 0 and abs(shiphead) < 15: banner("Landed!") engine.exit_engine()
def citygoboom(): global cities cities = cities - 1 if cities == 0: banner('LOSER!') engine.exit_engine()
def collision_sh_bl(lander, bl): if math.sqrt((bl.x - lander.x) ** 2 + (lander.y - bl.y) ** 2) \ <= 2 * basesize: banner("Killed by bullet") engine.exit_engine()
def collision_enemy(en, lander): if math.sqrt((lander.x - en.x) ** 2 + (lander.y - en.y) ** 2) \ <= 4 * basesize: banner("Crash against enemy") engine.exit_engine()
def collision_cb_SL(sun, lander): if math.sqrt((lander.x - sun.x) ** 2 + (lander.y - sun.y) ** 2) \ <= sundiam/2 + 2 * basesize: banner("Sunned!") engine.exit_engine()
def delete(self): super().delete() engine.exit_engine()
def delete(self): """ End the game. """ super().delete() engine.exit_engine()
def quit_cb(key): if key == 'q' or key == 'Q': engine.exit_engine()
def demo_keypress_cb(dummy): global exitdemo exitdemo = True engine.exit_engine()
def keyboard_cb(key): if key == 'space': box = Box() engine.add_obj(box) if key == 'Escape' : engine.exit_engine()