From 2d527d9604b9c659c2f19c96c4d499b05810d9ec Mon Sep 17 00:00:00 2001 From: pokepetter Date: Sun, 5 Jan 2025 23:21:57 +0100 Subject: [PATCH] taptapir_adventure, code_editor_3. --- cmyk_swap/cmyk_swap.html | 2 ++ monke/monke.html | 19 ++++++---- samples/code_editor_3.html | 54 +++++++++++++++++----------- tapir_adventure/tapir_adventure.html | 52 +++++++++++++++++++++++++++ taptapir | 2 +- 5 files changed, 102 insertions(+), 27 deletions(-) create mode 100644 tapir_adventure/tapir_adventure.html diff --git a/cmyk_swap/cmyk_swap.html b/cmyk_swap/cmyk_swap.html index 8ff8bd8..96825f6 100644 --- a/cmyk_swap/cmyk_swap.html +++ b/cmyk_swap/cmyk_swap.html @@ -588,6 +588,7 @@ # achievements # share score +# cheats def input(key): if key == 'u': set_score(SCORE + 100) @@ -606,6 +607,7 @@ refresh_upgrade_menu() + diff --git a/monke/monke.html b/monke/monke.html index 1a7818e..d16ca49 100644 --- a/monke/monke.html +++ b/monke/monke.html @@ -193,12 +193,19 @@ elif key == 'a': move(-1,0) -def update(): - camera.x = lerp(camera.x, player.x, .1) - camera.x = clamp(camera.x, 1, level_size[0]-1) - camera.y = lerp(camera.y, player.y+1, .1) - camera.y = clamp(camera.y, 1, level_size[1]-2) - +# def update(): +# camera.x = lerp(camera.x, player.x, .1) +# camera.x = clamp(camera.x, 1, level_size[0]-1) +# camera.y = lerp(camera.y, player.y+1, .1) +# camera.y = clamp(camera.y, 1, level_size[1]-2) + + +smooth_camera = Entity(visible=False, target=player, bounds=level_size) +smooth_camera.update = def _(self=smooth_camera): + camera.x = lerp(camera.x, self.target.x, .1) + camera.x = clamp(camera.x, 1, self.bounds[0]-1) + camera.y = lerp(camera.y, self.target.y+1, .1) + camera.y = clamp(camera.y, 1, self.bounds[1]-2) diff --git a/samples/code_editor_3.html b/samples/code_editor_3.html index bad798c..3b3b2fa 100644 --- a/samples/code_editor_3.html +++ b/samples/code_editor_3.html @@ -15,27 +15,18 @@ text += ' player.color = hsv(random_int(0,360),.8,.9)\n' text += ' player.xy = [random_int(-5,5)*.1, random_int(-5,5)*.1]\n' -ingame_console = Text(text='', color=color.clear, xy=top_left, origin=[-.5,.5], text_size=2, text_color=color.white, color=color.black, alpha=.8, enabled=False) -# print('seofiujsehofij') -# Entity(color=color.black) -ingame_console.model.style.wordBreak = 'break-word' -ingame_console.model.style.whiteSpace = 'pre-wrap' -original_print = print -def print_ingame(message): - ingame_console.text += '\n' + message -console.error = print_ingame -# print = print_ingame -print('------') + # text_size = 20 # character_spacing = 11 # ctx.font = `${text_size}px monospace` - +DEFAULT_FONT = 'monospace' # text_color = hsv(0,0,.9) background_color = '#0a0a0a' set_window_color(background_color) -text_field = TextField(scale=[.9,1], origin=[0,.5], roundness=.01, y=.45*aspect_ratio, color='#141414', text_color='#d1a469') + +text_field = TextField(scale=[.9,1], origin=[0,.5], roundness=.01, y=.45*aspect_ratio, color='#141414', text_color='#d1a469', text_size=1.5) preview_canvas = Entity(name='preview_canvas', parent=camera.ui, scale=[.9,aspect_ratio*.9], y=.05, z=-1, color=hsv(0,0,.1), shadow=1, enabled=False) @@ -46,6 +37,19 @@ Entity(parent=border_parent, origin=[0,-.5], scale=2, color=color.black, z=-1, y=.5) Entity(parent=border_parent, origin=[0,.5], scale=2, color=color.black, z=-1, y=-.5) +ingame_console = Text(text='console log:', y=.45*aspect_ratio, origin=[0,.5], text_size=2, text_color=color.red, color='#123', enabled=False) +# print('seofiujsehofij') +# Entity(color=color.black) +ingame_console.model.style.wordBreak = 'break-word' +ingame_console.model.style.whiteSpace = 'pre-wrap' +original_print = print +def print_ingame(message): + ingame_console.text += '\n' + message +console.error = print_ingame +# print = print_ingame +print('------') + + close_button = Button(scale=[.15,.075], origin=[.5,-.5], position=[.5-.2,-.5*aspect_ratio], text='close', color=color.gray, enabled=False, text_size=2.5, z=-2) close_button.on_click = def close(): if preview_canvas.entity_parent: @@ -56,6 +60,7 @@ camera.ui = _original_camera_ui print = original_print ingame_console.text = '' + ingame_console.enabled = False preview_button = Button(scale=[.2,.075], origin=[.5,-.5], position=bottom_right, text='preview', color=color.azure, text_color=color.white, text_size=2.5, z=-2) preview_button.on_click = def preview(): @@ -69,6 +74,10 @@ text_to_compile = text_field.value _original_scene = scene _original_camera_ui = camera.ui + set_window_color = def (value): + preview_canvas.color = value + set_background_color = def (value): + return preview_canvas.entity_parent = Entity(parent=preview_canvas, visible_self=False, scale_y=1/aspect_ratio) fake_camera_ui = Entity(parent=preview_canvas.entity_parent, visible_self=False) @@ -78,18 +87,23 @@ result = compile(text_to_compile) print('compiled sucessfully') catch (error): + ingame_console.enabled = True + ingame_console.text += error.message print('error compiling:', error) try: eval(result) print('evaluated sucessfully') catch (error): - line_number = '' - for l in error.stack.split('\n'): # get line number - if 'eval:' in l: - line_number = 'line: ' + l.split('eval:')[1] - break - - print(error + ' \n' + line_number); + ingame_console.enabled = True + ingame_console.text += error.message + + # line_number = '' + # for l in error.stack.split('\n'): # get line number + # if 'eval:' in l: + # line_number = 'line: ' + l.split('eval:')[1] + # break + + # print(error + ' \n' + line_number); diff --git a/tapir_adventure/tapir_adventure.html b/tapir_adventure/tapir_adventure.html new file mode 100644 index 0000000..170086e --- /dev/null +++ b/tapir_adventure/tapir_adventure.html @@ -0,0 +1,52 @@ + + CMYK Swap + + + + + diff --git a/taptapir b/taptapir index c577f34..9893de8 160000 --- a/taptapir +++ b/taptapir @@ -1 +1 @@ -Subproject commit c577f343e03a91382111f95f3eb91b33fef33e65 +Subproject commit 9893de8c015599a5256c1f3429f285741d93b682