diff --git a/README.md b/README.md index 5f1743e..8af904b 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,19 @@ vim3 path/to/myfile.txt It's not that hard -### How do i stop the cube from spinning +### How do i stop the cube from spinning? -no +no, unless you're an absolute buzzkill + +':stop' to stop spin + +':start' to start spin again + +### How do i change the speed of the cube's spin? + +':faster' for faster spin + +':slower' for slower spin ### I don't even have vim installed, how is this possible? @@ -52,3 +62,7 @@ You might also need to do `sudo apt install libtinfo5` ### I use arch btw Try this: `sudo ln -s /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5` + +### How do I change the background to show a picture of MC Hammer? + +Enter ":stop" and then ":hammer_time" diff --git a/src/assets/hammertime.jpg b/src/assets/hammertime.jpg new file mode 100644 index 0000000..99f0882 Binary files /dev/null and b/src/assets/hammertime.jpg differ diff --git a/src/common.nim b/src/common.nim index f6d8de3..47c0667 100644 --- a/src/common.nim +++ b/src/common.nim @@ -11,6 +11,7 @@ type totalTime*: float frameWidth*: int frameHeight*: int + isHammerTime*: bool proc project*[UniT, AttrT](entity: var Entity[UniT, AttrT], left: GLfloat, right: GLfloat, bottom: GLfloat, top: GLfloat, near: GLfloat, far: GLfloat) = entity.uniforms.u_matrix.project(left, right, bottom, top, near, far) diff --git a/src/core.nim b/src/core.nim index d19d5b1..c0d59a9 100644 --- a/src/core.nim +++ b/src/core.nim @@ -36,12 +36,15 @@ proc initThreeDMetaTextureEntity(posData: openArray[GLfloat], texcoordData: open var entity: ThreeDMetaTextureEntity imageEntity: ImageEntity + hammerEntity: ImageEntity rx = degToRad(180f) ry = degToRad(40f) imageWidth: int imageHeight: int const image = staticRead("assets/bg.jpg") +const hammerTime = staticRead("assets/hammertime.jpg") + proc init*(game: var Game) = doAssert glInit() @@ -81,8 +84,11 @@ proc init*(game: var Game) = var channels: int data: seq[uint8] + hammerData: seq[uint8] data = stbi.loadFromMemory(cast[seq[uint8]](image), imageWidth, imageHeight, channels, stbi.RGBA) imageEntity = compile(game, initImageEntity(data, imageWidth, imageHeight)) + hammerData = stbi.loadFromMemory(cast[seq[uint8]](hammerTime), imageWidth, imageHeight, channels, stbi.RGBA) + hammerEntity = compile(game, initImageEntity(hammerData, imageWidth, imageHeight)) proc tick*(game: Game) = glClearColor(1f, 1f, 1f, 1f) @@ -100,6 +106,10 @@ proc tick*(game: Game) = else: (game.frameHeight.float * imageRatio, game.frameHeight.float) var e = imageEntity + if game.isHammerTime == true: + e = hammerEntity + else: + e = imageEntity e.project(float(game.frameWidth), float(game.frameHeight)) e.translate(0f, 0f) e.scale(width, height) diff --git a/src/vim3.nim b/src/vim3.nim index 8fcc591..e1c8c5a 100644 --- a/src/vim3.nim +++ b/src/vim3.nim @@ -2,6 +2,8 @@ import nimgl/glfw import common from core import nil from paravim import nil +from paravim/core as vim import nil +from pararules import nil from os import nil var game = Game() @@ -46,9 +48,41 @@ when isMainModule: game.totalTime = glfwGetTime() + var isStopped = false + var speed = 1f + var x = "" + var hasCommand = false + while not w.windowShouldClose: let ts = glfwGetTime() - game.deltaTime = ts - game.totalTime + + var vimMode = pararules.query(vim.session, vim.rules.getVim).mode + + if vimMode == 8: + hasCommand = false + + if hasCommand == false: + if vimMode == 257: + x = pararules.query(vim.session, vim.rules.getVim).commandText + if x == "stop": + isStopped = true + elif x == "start": + isStopped = false + elif x == "faster": + speed += (speed * 0.5) + elif x == "slower": + speed -= (speed * 0.5) + hasCommand = true + if isStopped == true: + game.deltaTime = 0 + if x == "hammer_time": + isStopped = false + game.isHammerTime = true + elif isStopped == false: + game.deltaTime = (ts - game.totalTime) * speed + + + game.totalTime = ts core.tick(game) w.swapBuffers() diff --git a/vim3 b/vim3 new file mode 100755 index 0000000..fbe8f5d Binary files /dev/null and b/vim3 differ