January 15, 2021, 05:49:48 PM

### Author Topic: [bmx] Isometric mouse position by Enyaw [ 1+ years ago ]  (Read 443 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] Isometric mouse position by Enyaw [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Isometric mouse position
Author : Enyaw
Posted : 1+ years ago

Description : A small program which works out the position of the mouse on a isometric grid without using any lookup pixmap.

Code :
Code: BlitzMax
1. Const offsetx = 416
2. Const offsety = 0
3.
4. Global xs = 16
5. Global ys = 8
6.
7. Function px(x:Int, y:Int, z:Int)
8.         xp = offsetx - 16 + (x - y) Shl 4
9.         Return xp
10. End Function
11.
12. Function py(x:Int, y:Int, z:Int)
13.         yp = offsety + (x + x + y + y - z) Shl 2
14.         Return yp
15. End Function
16.
17. Function Iso(x:Float, y:Float, xs:Float, ys:Float)
18.         Local p:Float[] = [x + 0 * xs, y + 1 * ys, x + 1 * xs, y + 0 * ys, x + 1 * xs, y + 0 * ys, x + 2 * xs, y + 1 * ys, x + 2 * xs, y + 1 * ys, x + 1 * xs, y + 2 * ys]
19.         DrawPoly p
20. End Function
21.
22. Graphics 800, 600
23.
24. Repeat
25. Cls
26. xm = MouseX() ; ym = MouseY() ; z = MouseZ()
27. xc = Int((xm + ym + ym - offsety) Shr 5)
28. yc = Int((ym + ym - xm + offsetx) Shr 5)
29.
30.
31. For x = 0 To 25
32.         For y = 0 To 25
33.                 SetColor 255, 255, 255
34.                 Plot px(x, y, z) , py(x, y, z)
35.         Next
36. Next
37.
38. Iso(px(xc, yc, 0) - 208, py(xc, yc, 0) - 96, xs, ys)
39.
40. Iso(px(xc, yc, z) - 208, py(xc, yc, z) - 96, xs, ys)
41.
42. DrawText " " + (xc - 12) + " " + yc + " " + z + " ", 0, 0
43. Flip
44. Until KeyDown(KEY_ESCAPE) Or AppTerminate()