Пример #1
0
def lose():
	s.playing = False
	mesg = 'Score %d - press space to play again' % s.score
	turtle.goto(0, 0)
	turtle.color(TEXTCOLOR)
	turtle.write(mesg, True, align='center', font=('Arial', 24, 'italic'))
	engine.del_obj(s.me)
Пример #2
0
def coll_loselife1(me, bomb):
    if iscoll_circle(me, bomb):
        engine.del_obj(bomb)
        s.lostlives = s.lostlives + 1
        if s.lostlives != LIVES:
            # change color
            me.update()
Пример #3
0
def col_gameover(obj1, obj2):
    if iscoll_circle(obj1, obj2):
        x1, y1, r1 = obj1.get_bc()
        x2, y2, r2 = obj2.get_bc()
        engine.del_obj(obj1)
        engine.del_obj(obj2)
        lose()
Пример #4
0
 def on_ground(self):
     if self.y > GROUND_Y:
         return
     else:
         engine.add_obj(Explosion(self.x, self.y))
         engine.add_obj(Hole(self.x))
         engine.del_obj(self)
Пример #5
0
def col_gameover(obj1, obj2):
	if iscoll_circle(obj1, obj2):
		x1, y1, r1 = obj1.get_bc()
		x2, y2, r2 = obj2.get_bc()
		engine.del_obj(obj1)
		engine.del_obj(obj2)
		lose()
Пример #6
0
	def step(self):
		newsize = abs(math.sin(math.radians(self.age) + 180))
		if newsize < 0.05:
			engine.del_obj(self)
			return
		self.diameter = newsize * (self.maxdiameter * 2)
		super().step()
Пример #7
0
def coll_loselife1(me, bomb):
	if iscoll_circle(me, bomb):
		engine.del_obj(bomb)
		s.lostlives = s.lostlives + 1
		if s.lostlives != LIVES:
			# change color
			me.update()
Пример #8
0
def lose():
    s.playing = False
    mesg = 'Score %d - press space to play again' % s.score
    turtle.goto(0, 0)
    turtle.color(TEXTCOLOR)
    turtle.write(mesg, True, align='center', font=('Arial', 24, 'italic'))
    engine.del_obj(s.me)
Пример #9
0
    def move(self):

        global bossbeaten

        self.x += self.speed * math.cos(math.radians(180 - self.angle))
        self.y -= self.speed * math.sin(math.radians(180 - self.angle))

        for badguy in badguys[posi][posj]:
            if collide_round_round(self, badguy):
                engine.del_obj(badguy)
                badguys[posi][posj].remove(badguy)
                self.shape = 'whitebullet'
                engine.del_obj(self)
                bullets.remove(self)

        if posi == 2 and posj == 3 and collide_round_round(self, boss):
            self.shape = 'whitebullet'
            engine.del_obj(self)
            bullets.remove(self)
            if boss.life > 0:
                boss.life -= 1
            elif bossbeaten == 0:
                engine.del_obj(boss)
                banner('Boss defeated')
                bossbeaten = 1

        if collide_gnd(self):
            self.shape = 'whitebullet'
            engine.del_obj(self)
Пример #10
0
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()
Пример #11
0
 def dooropening(self, key_index=0, proximity=100):
     if not game.Game.pause and abs(game.Game.rocket.x - self.x_init) < proximity and \
             abs(game.Game.rocket.y - self.y_init) < proximity:
         got_all_keys = True
         for key_id in self.keys_required:
             got_all_keys = got_all_keys and key_id in Key.pickedupkeys
         if got_all_keys:
             key = Key.lkey[game.Game.posi][game.Game.posj][key_index]
             xmvt = 0 if self.angle % 180 == 0 else 10
             ymvt = 10 if self.angle % 180 == 0 else 0
             if abs(self.x) < 400 and abs(self.y) < 400:  # moving the door
                 self.x += xmvt
                 self.y += ymvt
                 key.x += xmvt
                 key.y += ymvt
             else:  # removing the door
                 Door.ldoor[game.Game.posi][game.Game.posj].remove(self)
                 engine.del_obj(self)
                 for key in Key.lkey[game.Game.posi][
                         game.Game.
                         posj]:  # removing the keys used to open the door
                     if key.id in self.keys_required:
                         Key.lkey[game.Game.posi][game.Game.posj].remove(
                             key)
                         engine.del_obj(key)
                 Door.doorsopened += 1
                 game.Stats.points += game.Stats.POINTS_PER_DOOR_OPENED
Пример #12
0
def load():
    for bullet in bullets.Bullet.bullet_list:
        engine.del_obj(bullet)
    bullets.Bullet.bullet_list = []

    engine.del_obj(Game.ground)
    Game.ground = shapes.Ground(Game.level[Game.posi][Game.posj])

    for i in range(Game.height):
        for j in range(Game.length):
            if i != Game.posi or j != Game.posj:
                for door in shapes.Door.ldoor[i][j]:
                    engine.del_obj(door)
                for key in shapes.Key.lkey[i][j]:
                    engine.del_obj(key)
                for badguy in bad_guys.BadGuy.badguys[i][j]:
                    engine.del_obj(badguy)

    #for _ in range(3):
    for badguy in bad_guys.BadGuy.badguys[Game.posi][Game.posj]:
        engine.add_obj(badguy)
        badguy.countdown = 0
    for door in shapes.Door.ldoor[Game.posi][Game.posj]:
        engine.add_obj(door)
    for key in shapes.Key.lkey[Game.posi][Game.posj]:
        engine.add_obj(key)

    if Game.posi == Game.boss.posi and Game.posj == Game.boss.posj and not bad_guys.Boss.bossbeaten:
        engine.add_obj(Game.boss)
Пример #13
0
    def move(self):
        if not game.Game.pause:
            self.x += self.speed * math.cos(math.radians(180 - self.angle))
            self.y -= self.speed * math.sin(math.radians(180 - self.angle))

            if self.nice:
                for badguy in bad_guys.BadGuy.badguys[game.Game.posi][
                        game.Game.posj]:  # collision with a bad_guy
                    if shapes.collide_round_round(self, badguy):
                        engine.del_obj(badguy)
                        bad_guys.BadGuy.badguys[game.Game.posi][
                            game.Game.posj].remove(badguy)
                        self.hit(earn_points=True)

                if game.Game.posi == game.Game.boss.posi and game.Game.posj == game.Game.boss.posj and \
                        shapes.collide_round_round(self, game.Game.boss) and not game.Game.boss.bossbeaten:
                    self.hit(earn_points=True)
                    game.Game.boss.life -= 1
                    if game.Game.boss.life == 0:
                        engine.del_obj(game.Game.boss)
                        game.banner('Boss defeated')
                        bad_guys.Boss.bossbeaten = True

            elif shapes.collide_round_round(
                    self,
                    game.Game.rocket):  # bad bullets collides with the rocket
                self.hit()
                if not game.Game.rocket.bulletproof:
                    game.Game.rocket.losealife()

            # if shapes.collide_gnd(self) or shapes.collide_door(self):
            if math.sqrt((self.x - self.pt_coll[0]) ** 2 + (self.y - self.pt_coll[1]) ** 2) <= self.radius or \
                    shapes.collide_door(self):
                self.hit()
Пример #14
0
def cheat():
    """For an easier debug"""
    if '0' in sys.argv:
        print("cheat version")
        key_order = [(0, 4), (1, 4), (0, 0), (0, 1), (2, 3)]
        door_order = [(0, 4), (1, 2), (1, 1), (2, 2), (2, 3)]
        Game.posi = 2
        Game.posj = 2
        Game.rocket.x = 0
        Game.rocket.y = 0
        shapes.Key.pickedupkeys = list(range(4))
        bad_guys.Boss.bossbeaten = False
        doors_opened = 1
        Game.rocket.bulletproof = True

        for door_index in range(doors_opened):
            i, j = door_order[door_index]
            door = shapes.Door.ldoor[i][j][0]
            engine.del_obj(door)
            shapes.Door.ldoor[i][j].remove(door)
        for key_index in shapes.Key.pickedupkeys:
            i, j = key_order[key_index]
            key = shapes.Key.lkey[i][j][0]
            shapes.Key.lkey[i][j].remove(key)
            if key_index >= doors_opened:
                key.x = key.newx
                key.y = key.newy
                shapes.Key.lkey[key.newi][key.newj].append(key)
            else:
                engine.del_obj(key)
    else:
        print("Version sans cheat")
Пример #15
0
 def __init__(self, x, y, color, keys_required=(), angle=0):
     self.angle = angle
     self.x_init = x
     self.y_init = y
     self.keys_required = keys_required[:]
     super().__init__(x, y, 0, 0, 'door', color)
     engine.del_obj(self)
Пример #16
0
 def step(self):
     newsize = abs(math.sin(math.radians(self.age) + 100))
     if newsize < 0.05:
         engine.del_obj(self)
         return
     self.diameter = newsize * (self.maxdiameter * 2)
     super().step()
Пример #17
0
def car_miss_collision_cb(car, miss):
    global score
    if (car.x < miss.x < car.x + 30) and (miss.y < car.y + 20) and miss.deltay == -SPEED:
        engine.add_obj(Explosion(car.x, car.y))
        engine.del_obj(car)
        engine.del_obj(miss)
        draw_score(True)
Пример #18
0
def dooropening(i,
                j,
                picked,
                opened,
                xptactiv,
                yptactiv,
                xmvt,
                ymvt,
                proximity=100,
                doorindex=0,
                keyindex=0):
    global doorsopened
    if pickedupkeys == picked:
        if doorsopened == opened and posi == i and posj == j and abs(
                rocket.x - xptactiv) < proximity and abs(rocket.y -
                                                         yptactiv) < proximity:
            (door, x, y) = ldoor[i][j][doorindex]
            key = lkey[i][j][keyindex]
            if abs(door.x) < 400 and abs(door.y) < 400:
                door.x += xmvt
                door.y += ymvt
                key.x += xmvt
                key.y += ymvt
            else:
                ldoor[i][j].remove((door, x, y))
                engine.del_obj(door)
                lkey[i][j].remove(key)
                engine.del_obj(key)
                doorsopened += 1
Пример #19
0
def coll1(shot, target):
	global ntargets
	if pointinrect(shot.getxy(), target.getul(), target.getlr()):
		engine.del_obj(target)
		ntargets -= 1
		if ntargets == 0:
			win(timer.gettime())
Пример #20
0
def load():
    global ground, bosshere, bullets
    engine.del_obj(ground)
    ground = Ground(level[posi][posj])
    for i in range(3):
        for j in range(5):
            if i != posi or j != posj:
                for (door, _, _) in ldoor[i][j]:
                    engine.del_obj(door)
                for key in lkey[i][j]:
                    engine.del_obj(key)
                for badguy in badguys[i][j]:
                    engine.del_obj(badguy)
    for bullet in bullets:
        engine.del_obj(bullet)
    bullets = []

    for _ in range(3):
        for badguy in badguys[posi][posj]:
            engine.add_obj(badguy)
        for (door, _, _) in ldoor[posi][posj]:
            engine.add_obj(door)
        for key in lkey[posi][posj]:
            engine.add_obj(key)

    if posi == 2 and posj == 3 and bossbeaten == 0 and boss.life > 0 and bosshere < 2:
        engine.add_obj(boss)
        bosshere += 1
    if (posi != 2 or posj != 3) and bossbeaten == 0:
        bosshere = 0
Пример #21
0
def car_ufo_collision_cb(car, ufo):
    global score
    if ufo.in_ufo(car.x, car.y + 20) or ufo.in_ufo(car.x + 30, car.y + 20):
        engine.add_obj(Explosion(car.x, car.y))
        engine.add_obj(Explosion(ufo.x, ufo.y))
        engine.del_obj(car)
        engine.del_obj(ufo)
        draw_score(True)
Пример #22
0
def coll_air2air(obj1, obj2, points=100):
    if iscoll_circle(obj1, obj2):
        x1, y1, r1 = obj1.get_bc()
        x2, y2, r2 = obj2.get_bc()
        engine.del_obj(obj1)
        engine.del_obj(obj2)
        s.score = s.score + points
        draw_score()
Пример #23
0
 def hit(self, earn_points=False):
     """invoked when a bullet hits something and should be removed"""
     self.shape = 'whitebullet'
     engine.del_obj(self)
     Bullet.bullet_list.remove(self)
     if earn_points:
         game.Stats.bullets_hit += 1
         game.Stats.points += game.Stats.POINTS_PER_BAD_GUY
Пример #24
0
	def hit(self):
		self.hits = self.hits + 1
		if self.hits == CITYLIVES:
			engine.del_obj(self)
			citygoboom()
		else:
			self.setcolor()
			self.update()
Пример #25
0
 def __init__(self, x, y, color, key_id, newi, newj, newx, newy):
     self.key_id = key_id
     self.newi = newi  # room after pickup
     self.newj = newj
     self.newx = newx  # coordinates after pickup
     self.newy = newy
     super().__init__(x, y, 0, 0, 'key', color)
     engine.del_obj(self)
Пример #26
0
def coll_circle(obj1, obj2):
	if iscoll_circle(obj1, obj2):
		x1, y1, r1 = obj1.get_bc()
		x2, y2, r2 = obj2.get_bc()
		engine.add_obj(Boom(x1, y1, r1))
		engine.add_obj(Boom(x2, y2, r2))
		engine.del_obj(obj1)
		engine.del_obj(obj2)
Пример #27
0
def coll_circle(obj1, obj2):
    if iscoll_circle(obj1, obj2):
        x1, y1, r1 = obj1.get_bc()
        x2, y2, r2 = obj2.get_bc()
        engine.add_obj(Boom(x1, y1, r1))
        engine.add_obj(Boom(x2, y2, r2))
        engine.del_obj(obj1)
        engine.del_obj(obj2)
Пример #28
0
def coll_air2air(obj1, obj2, points=100):
	if iscoll_circle(obj1, obj2):
		x1, y1, r1 = obj1.get_bc()
		x2, y2, r2 = obj2.get_bc()
		engine.del_obj(obj1)
		engine.del_obj(obj2)
		s.score = s.score + points
		draw_score()
Пример #29
0
 def hit(self):
     self.hits = self.hits + 1
     if self.hits == CITYLIVES:
         engine.del_obj(self)
         citygoboom()
     else:
         self.setcolor()
         self.update()
Пример #30
0
def miss_turt_collision_cb(miss, turt):
    global score
    if turt.in_turtle( (miss.x), (miss.y-10) ):
        engine.add_obj(Explosion(miss.x, miss.y))
        engine.add_obj(Explosion(turt.x, turt.y))
        engine.del_obj(miss)
        engine.del_obj(turt)
        score += 10
        draw_score(False)
Пример #31
0
def miss_ufo_collision_cb(miss, ufo):
    global score
    if ufo.in_ufo(miss.x, miss.y):
        engine.add_obj(Explosion(miss.x, miss.y))
        engine.add_obj(Explosion(ufo.x, ufo.y))
        engine.del_obj(miss)
        engine.del_obj(ufo)
        score += 100
        draw_score(False)
Пример #32
0
 def __init__(self, posi, posj, x, y):
     self.countdown = 0
     self.tresh = 70
     self.life = 80
     self.radius = 100
     self.posi = posi
     self.posj = posj
     super().__init__(x, y, 0, 0, 'boss', 'black')
     engine.del_obj(self)
Пример #33
0
 def pickupkey(self):
     if game.Game.rocket.landed and self.key_id not in Key.pickedupkeys:
         Key.pickedupkeys.append(self.key_id)
         game.Stats.points += game.Stats.POINTS_PER_KEY_PICKED
         game.banner('Key collected')
         self.x = self.newx
         self.y = self.newy
         if self.newi != game.Game.posi or self.newj != game.Game.posj:  # the door isn"t in the same room as the key
             Key.lkey[game.Game.posi][game.Game.posj].remove(self)
             Key.lkey[self.newi][self.newj].append(self)
             engine.del_obj(self)
Пример #34
0
def collrtr(rocket1, rock1):
    if iscoll(rocket1, rock1):
        x1, y1, r1 = rocket1.get_bc()
        x2, y2, r2 = rock1.get_bc()
        engine.del_obj(rocket1)
        engine.del_obj(rock1)
        engine.add_obj(Boom(x1, y1, r1))
        engine.add_obj(Boom(x2, y2, r2))
        global count  #score update and rocket counter
        count = count - 1
        points()
Пример #35
0
def pickupkey(i, j, picked, newi, newj, newx, newy, keyindex=0):
    global pickedupkeys
    if pickedupkeys == picked and posi == i and posj == j and rocket.speed == gravity == 0:
        pickedupkeys += 1
        banner('Key collected')
        key = lkey[i][j][keyindex]
        key.x = newx
        key.y = newy
        if newi != i or newj != j:
            lkey[i][j].remove(key)
            lkey[newi][newj].append(key)
            engine.del_obj(key)
Пример #36
0
    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)
Пример #37
0
    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 collide_round_round(self, rocket):
            rocket.losealife()
            self.shape = 'whitebullet'
            engine.del_obj(self)

        if collide_gnd(self):
            self.shape = 'whitebullet'
            engine.del_obj(self)
            bullets.remove(self)
Пример #38
0
	def update(self):
		turtle.shapesize(0.2,0.2)
		turtle.settiltangle(0)
		
		#screen wraparound
		if self.x >= WIDTH / 2:
			self.x = -WIDTH / 2
		elif self.x <= -WIDTH / 2:
			self.x = WIDTH / 2 - 2
		elif self.y >= HEIGHT / 2:
			self.y = -HEIGHT / 2
		elif self.y <= -HEIGHT / 2:
			self.y = HEIGHT / 2
		
		super().update()

		if self.age >= SHOTLIFE:
			engine.del_obj(self)
			s.shots -= 1
Пример #39
0
def col_asteroid(obj1, obj2):
	if iscoll_circle(obj1, obj2):
		x1, y1, r1 = obj1.get_bc()
		x2, y2, r2 = obj2.get_bc()
		engine.del_obj(obj1)
		engine.del_obj(obj2)
		s.shots -= 1
		s.curas -= 1
		s.score += 1
		draw_score()
		#create 2 new asteroids
		if(obj1.sizex > 2 or obj1.sizey > 2):
			xpos = obj1.x
			ypos = obj1.y
			if(obj1.sizex == 1):
				xsize = 1
			else:
				xsize = random.randint(1, obj1.sizex-1)
			if(obj1.sizey == 1):
				ysize = 1
			else:
				ysize = random.randint(1, obj1.sizey-1)
			deltx = random.randint(-1, 1)
			delty = random.randint(-1, 1)
			obj = Asteroid(xpos, ypos, deltx, delty, xsize, ysize)
			engine.add_obj(obj)
			xpos = obj1.x
			ypos = obj1.y
			if(obj1.sizex == 1):
				xsize = 1
			else:
				xsize = random.randint(1, obj1.sizex-1)
			if(obj1.sizey == 1):
				ysize = 1
			else:
				ysize = random.randint(1, obj1.sizey-1)
			deltx = random.randint(-1, 1)
			delty = random.randint(-1, 1)
			obj = Asteroid(xpos, ypos, deltx, delty, xsize, ysize)
			engine.add_obj(obj)
Пример #40
0
def collision_en_bl(en, bl):
    if math.sqrt((bl.x - en.x) ** 2 + (bl.y - en.y) ** 2) <= 4 * basesize:
        engine.del_obj(en)
        engine.del_obj(bl)
Пример #41
0
def coll_cb(me, pipe):
	if pipe.xyinrect(me.getx(), me.gety()):
		engine.del_obj(me)
		lose()
Пример #42
0
def coll_boom1(obj1, obj2):
	# circle getting drawn into an explosion in progress - obj1 is Boom inst
	if iscoll_circle(obj1, obj2):
		x, y, r = obj2.get_bc()
		engine.add_obj(Boom(x, y, r))
		engine.del_obj(obj2)
Пример #43
0
def coll_groundnoboom1(ground, obj):
	x, y, r = obj.get_bc()
	if y <= ground.get_groundlevel():
		engine.del_obj(obj)
Пример #44
0
def coll_ground1(ground, obj):
	x, y, r = obj.get_bc()
	if y <= ground.get_groundlevel():
		engine.add_obj(Boom(x, y, r))
		engine.del_obj(obj)
Пример #45
0
def coll_city1(city, obj):
	if iscoll_circle(city, obj):
		x, y, r = city.get_bc()
		engine.add_obj(Boom(x, y, r))
		engine.del_obj(obj)
		city.hit()