Skip to content

Commit

Permalink
taptapir_adventure, code_editor_3.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokepetter committed Jan 5, 2025
1 parent 4f499c8 commit 2d527d9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 27 deletions.
2 changes: 2 additions & 0 deletions cmyk_swap/cmyk_swap.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@
# achievements
# share score

# cheats
def input(key):
if key == 'u':
set_score(SCORE + 100)
Expand All @@ -606,6 +607,7 @@
refresh_upgrade_menu()



</script>
<script src="../taptapir/sunsnake_compiler.js"></script>
</html>
19 changes: 13 additions & 6 deletions monke/monke.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
54 changes: 34 additions & 20 deletions samples/code_editor_3.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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);



Expand Down
52 changes: 52 additions & 0 deletions tapir_adventure/tapir_adventure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" />
<title>CMYK Swap</title><link rel="icon" href="icon.png">
</head><body></body>
<script src="../taptapir/taptapir.js"></script>
<script type='text/sunsnake'>

set_background_color("#111111")
set_window_color("#222")

player = Entity(scale=.1, color=color.green, roundness=.5, text='@', speed=1/60*.5, z=-1, shadow=True)


$virtual_joystick = Entity(parent=camera.ui, scale=.3, target_alpha=.1, roundness=.5)
_.direction_indicator = Entity(static=True, parent=_, color=color.azure, scale=[.5,.05], origin=[-.5,0], roundness=.5)
_.alpha = _.target_alpha
_.input = def (key):
if key == 'left mouse down':
_.position = mouse.position
_.animate('alpha', _.target_alpha, duration=.1)
_.animate('alpha', _.target_alpha, duration=.1)

if key == 'left mouse up':
_.animate('alpha', 0, duration=.5)

_.update = def():
_.direction_indicator.enabled = mouse.left
if mouse.left:
direction = normalize([mouse.x-_.x, mouse.y-_.y])
_.direction_indicator.look_at(direction)
input_speed = clamp(abs(distance(_.position, mouse.position)* 5), 0, .5) * mouse.left
_.direction_indicator.scale_x = input_speed
# print(input_speed * player.speed * delta_time)
player.x += input_speed * player.speed * 1 * direction[0]
player.y += input_speed * player.speed * 1 * direction[1]
else:


$smooth_camera = Entity(visible_self=False, target=player, bounds=[8,8], offset=[0,0])
_.update = def():
speed = 10
camera.x = lerp(camera.x, _.target.x+_.offset[0], .1)
camera.y = lerp(camera.y, _.target.y+_.offset[1], .1)
# camera.x = clamp(camera.x, 1, _.bounds[0]-1)
# camera.y = clamp(camera.y, 1, _.bounds[1]-2)



level = Entity(texture='https://cdnb.artstation.com/p/assets/images/images/082/650/175/large/artem-chebokha-415-inevitable-fading-1400.jpg?1733529524', scale=1)

</script>
<script src="../taptapir/sunsnake_compiler.js"></script>
</html>
2 changes: 1 addition & 1 deletion taptapir
Submodule taptapir updated 2 files
+28 −7 sunsnake_compiler.js
+33 −7 taptapir.js

0 comments on commit 2d527d9

Please sign in to comment.