class FixedStrategy:
- def end_condition(self):
+ def win_condition(self):
return True
self._positions = []
self._rotations = []
- def end_condition(self):
+ def win_condition(self):
self._positions += [self._np.get_pos()]
self._rotations += [self._np.get_hpr()]
if len(self._positions) > 10:
self._model_path = model_path
self._commands = []
self._command_idx = -1
+ self._positions = []
+ self._rotations = []
if count:
self.node = BulletGhostNode(self.__class__.__name__)
else:
if hasattr(self, '_txt') and not self._txt.is_empty():
self._txt.set_alpha_scale(1)
+ def fail_condition(self):
+ if self._np.get_z() < -10:
+ return True
+ self._positions += [self._np.get_pos()]
+ self._rotations += [self._np.get_hpr()]
+ if len(self._positions) > 10:
+ self._positions.pop(0)
+ if len(self._rotations) > 10:
+ self._rotations.pop(0)
+ if len(self._positions) < 8:
+ return
+ avg_x = sum(pos.x for pos in self._positions) / len(self._positions)
+ avg_y = sum(pos.y for pos in self._positions) / len(self._positions)
+ avg_z = sum(pos.z for pos in self._positions) / len(self._positions)
+ avg_h = sum(rot.x for rot in self._rotations) / len(self._rotations)
+ avg_p = sum(rot.y for rot in self._rotations) / len(self._rotations)
+ avg_r = sum(rot.z for rot in self._rotations) / len(self._rotations)
+ avg_pos = Point3(avg_x, avg_y, avg_z)
+ avg_rot = Point3(avg_h, avg_p, avg_r)
+ return all((pos - avg_pos).length() < .1 for pos in self._positions) and \
+ all((rot - avg_rot).length() < 1 for rot in self._rotations)
+
def destroy(self):
self._np.remove_node()
taskMgr.remove(self._box_tsk)
self._set_mouse_plane()
self.items = []
self.reset()
+ self._state = 'init'
self._paused = False
self._item_active = None
if auto_close_instr:
def reset(self):
[itm.destroy() for itm in self.items]
self._set_items()
+ self._state = 'init'
self._commands = []
self._command_idx = 0
if hasattr(self, '_success_txt'):
def on_aspect_ratio_changed(self):
self.repos()
- def _end_condition(self):
+ def _win_condition(self):
pass
+ def _fail_condition(self):
+ return all(itm.fail_condition() for itm in self.items) and not self._paused and self._state == 'playing'
+
def on_frame(self, task):
hits = self._get_hits()
pos = None
self._item_active.on_mouse_move(pos)
if self._dbg_items:
self._update_info(items_hit[0] if items_hit else None)
- if self._end_condition():
- self._set_end()
+ if self._win_condition():
+ self._set_win()
+ elif self._state == 'playing' and self._fail_condition():
+ self._set_fail()
if any(itm._overlapping for itm in self.items):
self._cursor.cursor_img.img.set_color(.9, .1, .1, 1)
else:
self.items += [item]
def on_play(self):
+ self._state = 'playing'
self.__prev_btn['state'] = DISABLED
self.__next_btn['state'] = DISABLED
self.__right_btn['state'] = DISABLED
clickSound=loader.load_sfx('assets/audio/sfx/click.ogg'))
btn.set_transparency(True)
- def _set_end(self):
+ def _set_win(self):
loader.load_sfx('assets/audio/sfx/success.ogg').play()
self._paused = True
self.__store_state()
btn['state'] = NORMAL if enabled else DISABLED
btn.set_transparency(True)
+ def _set_fail(self):
+ loader.load_sfx('assets/audio/sfx/success.ogg').play()
+ self._paused = True
+ self.__store_state()
+ frm = DirectFrame(frameColor=(.4, .4, .4, .06),
+ frameSize=(-.6, .6, -.3, .3))
+ font = base.loader.load_font('assets/fonts/Hanken-Book.ttf')
+ font.clear()
+ font.set_pixels_per_unit(60)
+ font.set_minfilter(Texture.FTLinearMipmapLinear)
+ font.set_outline((0, 0, 0, 1), .8, .2)
+ self._txt = OnscreenText(
+ _('You have failed!'),
+ parent=frm,
+ font=font, scale=0.2,
+ fg=(.9, .9, .9, 1))
+ u_l = self._txt.textNode.get_upper_left_3d()
+ l_r = self._txt.textNode.get_lower_right_3d()
+ w, h = l_r[0] - u_l[0], u_l[2] - l_r[2]
+ btn_scale = .05
+ mar = .06 # margin
+ z = h / 2 - font.get_line_height() * self._txt['scale'][1]
+ z += (btn_scale + 2 * mar) / 2
+ self._txt['pos'] = 0, z
+ u_l = self._txt.textNode.get_upper_left_3d()
+ l_r = self._txt.textNode.get_lower_right_3d()
+ c_l_r = l_r[0], l_r[1], l_r[2] - 2 * mar - btn_scale
+ fsz = u_l[0] - mar, l_r[0] + mar, c_l_r[2] - mar, u_l[2] + mar
+ frm['frameSize'] = fsz
+ colors = [
+ (.6, .6, .6, 1), # ready
+ (1, 1, 1, 1), # press
+ (.8, .8, .8, 1), # rollover
+ (.4, .4, .4, .4)]
+ imgs = [self.__load_img_btn('home', col) for col in colors]
+ btn = DirectButton(
+ image=imgs, scale=btn_scale,
+ pos=(-2.8 * btn_scale, 1, l_r[2] - mar - btn_scale),
+ parent=frm, command=self._on_end_home, extraArgs=[frm],
+ relief=FLAT, frameColor=(.6, .6, .6, .08),
+ rolloverSound=loader.load_sfx('assets/audio/sfx/rollover.ogg'),
+ clickSound=loader.load_sfx('assets/audio/sfx/click.ogg'))
+ btn.set_transparency(True)
+ imgs = [self.__load_img_btn('rewind', col) for col in colors]
+ btn = DirectButton(
+ image=imgs, scale=btn_scale,
+ pos=(0, 1, l_r[2] - mar - btn_scale),
+ parent=frm, command=self._on_restart, extraArgs=[frm],
+ relief=FLAT, frameColor=(.6, .6, .6, .08),
+ rolloverSound=loader.load_sfx('assets/audio/sfx/rollover.ogg'),
+ clickSound=loader.load_sfx('assets/audio/sfx/click.ogg'))
+ btn.set_transparency(True)
+
def _on_restart(self, frm):
self.__on_close_instructions(frm)
self.reset()