-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrotation.nim
58 lines (47 loc) · 1.17 KB
/
rotation.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import nico
import nico/vec
import math
var angle = 0f
var mode = 0
var rotFn = sprRot
var pos: Vec2f
proc gameInit() =
# load all our assets
loadSpriteSheet(0, "rotation.png", 16, 16)
angle = 0f
pos = vec2f(screenWidth div 2, screenHeight div 2)
proc gameUpdate(dt: Pfloat) =
if btn(pcLeft):
angle -= 3f * dt
if btn(pcRight):
angle += 3f * dt
if btn(pcUp):
pos += angle.angleToVec * 50f * dt
if btnp(pcA):
mode += 1
if mode > 2:
mode = 0
if keyp(K_RETURN):
rotFn = if rotFn == sprRot: sprShearRot else: sprRot
proc gameDraw() =
cls()
var i = 0
for ty in 0..<screenHeight div 16:
for tx in 0..<screenWidth div 16:
sprRot90(16, tx * 16, ty * 16, i mod 4)
i+=1
if mode == 0:
rotFn(0, pos.x, pos.y, angle, 1, 1)
elif mode == 1:
rotFn(1, pos.x, pos.y, angle, 2, 1)
else:
rotFn(3, pos.x, pos.y, angle, 1, 2)
# initialization
nico.init("nico", "test")
# we want a fixed sized screen with perfect square pixels
fixedSize(true)
integerScale(true)
# create the window
nico.createWindow("nico",128,128,4)
# start, say which functions to use for init, update and draw
nico.run(gameInit, gameUpdate, gameDraw)