Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Stop and Start Spin commands #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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"
Binary file added src/assets/hammertime.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
36 changes: 35 additions & 1 deletion src/vim3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Binary file added vim3
Binary file not shown.