• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

Untitled

a guest Feb 23rd, 2012 32 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. require 'gosu'
2.
3. class Map
4.     def initialize(width, height)
5.         @width = width
6.         @height = height
7.         @origin_x = width / 2
8.         @origin_y = height / 2
9.     end
10.
11.     def transform_x(x, y, z)
12.         cart_x = (x - z) * Math.cos(0.46365)
13.         cart_x + @origin_x
14.     end
15.
16.     def transform_y(x, y, z)
17.         cart_y = y + (x + z) * Math.sin(0.46365)
18.         -cart_y + @origin_y
19.     end
20. end
21.
22. class GameWindow < Gosu::Window
23.     def initialize
24.         super(640, 480, false)
25.         self.caption = "Iso"
26.         @map = Map.new(640, 480)
27.     end
28.
29.     def draw
30.         draw_box(0, 0, 0, 100, 100, 100, Gosu::Color::BLUE)
31.         draw_box(0, 0, 200, 40, 80, 40, Gosu::Color::RED)
32.         draw_axes
33.     end
34.
35.     def draw_axes
36.         draw_line_to(0, 0, 0, 200, 0, 0, Gosu::Color::GREEN)
37.         draw_line_to(0, 0, 0, 0, 200, 0, Gosu::Color::RED)
38.         draw_line_to(0, 0, 0, 0, 0, 200, Gosu::Color::YELLOW)
39.     end
40.
41.     def draw_line_to(x1, y1, z1, x2, y2, z2, color)
42.         draw_line(@map.transform_x(x1, y1, z1),
43.                   @map.transform_y(x1, y1, z1),
44.                   color,
45.                   @map.transform_x(x2, y2, z2),
46.                   @map.transform_y(x2, y2, z2),
47.                   color)
48.     end
49.
50.     def draw_box(x, y, z, width, height, depth, color)
51.         draw_line_to(x, y, z, x+width, y, z, color)
52.         draw_line_to(x, y, z, x, y+depth, z, color)
53.         draw_line_to(x, y, z, x, y, z+height, color)
54.         draw_line_to(x, y+depth, z, x+width, y+depth, z, color)
55.         draw_line_to(x+width, y, z, x+width, y+depth, z, color)
56.         draw_line_to(x, y+depth, z, x, y+depth, z+height, color)
57.         draw_line_to(x, y, z+height, x, y+depth, z+height, color)
58.         draw_line_to(x, y, z+height, x+width, y, z+height, color)
59.         draw_line_to(x, y+depth, z+height, x+width, y+depth, z+height, color)
60.         draw_line_to(x+width, y, z+height, x+width, y+depth, z+height, color)
61.         draw_line_to(x+width, y+depth, z+height, x+width, y+depth, z, color)
62.         draw_line_to(x+width, y, z+height, x+width, y, z, color)
63.     end
64. end
65.
66. window = GameWindow.new
67. window.show
RAW Paste Data
Top