Last active
February 3, 2026 05:11
-
-
Save jmccardle/a62c61a11d0928b8e43e0acf5d16718e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mcrfpy | |
| # the default "playground" scene | |
| scene = mcrfpy.current_scene | |
| # Frame: | |
| frame = mcrfpy.Frame((10, 10), (50, 50), fill_color=(30,30,80)) | |
| scene.children.append(frame) | |
| # Caption: | |
| caption = mcrfpy.Caption((10,60), text="Hello\nMcRogueFace!", font_size=32) # uses default font | |
| scene.children.append(caption) | |
| # Sprite: | |
| sprite = mcrfpy.Sprite((10, 150), sprite_index=84, scale=4.0) # uses default sprite sheet | |
| scene.children.append(sprite) | |
| # Grid: | |
| grid = mcrfpy.Grid((250,10), (320,320), grid_size=(10,10), zoom=2.0) | |
| scene.children.append(grid) | |
| # place entities on grid squares | |
| mcrfpy.Entity((4,5), sprite_index=85, grid=grid) # uses default sprite sheet | |
| mcrfpy.Entity((5,9), sprite_index=87, grid=grid) | |
| mcrfpy.Entity((3,7), sprite_index=89, grid=grid) | |
| # fill with some dirt | |
| import random | |
| for x in range(10): | |
| for y in range(10): | |
| # mostly 0 for plain dirt, with two variations | |
| grid[x,y].tilesprite = random.choice([0, 0, 0, 0, 0, 0, 12, 24]) | |
| # make the wizard sprite clickable | |
| def poke(position, mousebtn, inputstate): | |
| if inputstate != mcrfpy.InputState.PRESSED: | |
| return | |
| say = random.choice(["oof", "ouch", "uff"]) | |
| new_txt = mcrfpy.Caption(position, text=say) | |
| scene.children.append(new_txt) | |
| done = lambda *args: scene.children.remove(new_txt) | |
| new_txt.animate("y", # property | |
| -100, # target value | |
| 10.0 + random.randint(-4, 2), # duration | |
| callback=done # called on completion | |
| ) | |
| new_txt.animate("x", position.x + random.randint(-70, +270), 5.5) | |
| new_txt.animate("fill_color.a", 0, 5.5) | |
| sprite.on_click = poke | |
| # make the wizard sprite moveable | |
| def keypress(key, inputstate): | |
| actions = { mcrfpy.Key.W: mcrfpy.Vector(0, -10), | |
| mcrfpy.Key.A: mcrfpy.Vector(-10, 0), | |
| mcrfpy.Key.S: mcrfpy.Vector(0, 10), | |
| mcrfpy.Key.D: mcrfpy.Vector(10, 0) } | |
| if inputstate != mcrfpy.InputState.PRESSED: | |
| return | |
| if key in actions: | |
| sprite.pos += actions[key] | |
| scene.on_key = keypress | |
| print(mcrfpy.current_scene.children) | |
| # Press F3 for stats | |
| # create a new scene and switch to it: | |
| #new_scene = mcrfpy.Scene("test") | |
| #new_scene.activate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment