-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidiot.rb
More file actions
145 lines (125 loc) · 4.27 KB
/
idiot.rb
File metadata and controls
145 lines (125 loc) · 4.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env ruby
# dragon
# 2006 drr
# all rights negated
class Idiot
attr_reader :image, :x, :y, :name
def initialize(location, window, name="idiot")
#@image = Magick::Image.read("#{$root_dir}/peices/dragon.png").first
@x = location.split(",").first.to_i
@y = location.split(",").last.to_i
@name = "idiot"
@tiletype = "land"
@font = Gosu::Font.new(window, Gosu::default_font_name, 20)
end
def turn(map, peices)
@map = map
@old_x = @x
@old_y = @y
location = move_spot(@tiletype)
@x = location.split(",").first.to_i
@y = location.split(",").last.to_i
peices.each { |peice| unless peice == self
if peice.x == @x && peice.y == @y
# cancel move
@x = @old_x
@y = @old_y
puts "potential collision between #{self.name} and #{peice.name}"
end
end }
@moving = true
return map
end
def draw(map)
@map = map
unless @moving
@image.draw(@x * @map.tilesize, @y * @map.tilesize, 1,1)
@font.draw(self.name, (@x * @map.tilesize) + 10, (@y * @map.tilesize) + 44, 10, 1.0, 1.0, 0xffffffff)
else
@counta ||= 1
if @counta == 1
#turn
end
@counta += 1
if @old_x > @x
if @old_y > @y
@image.draw(((@old_x * @map.tilesize) - @counta), ((@old_y * @map.tilesize) - @counta), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) - @counta) + 10, ((@old_y * @map.tilesize) - @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
if @old_y < @y
@image.draw(((@old_x * @map.tilesize) - @counta), ((@old_y * @map.tilesize) + @counta), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) - @counta) + 10, ((@old_y * @map.tilesize) + @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
end
if @old_x < @x
if @old_y > @y
@image.draw(((@old_x * @map.tilesize) + @counta), ((@old_y * @map.tilesize) - @counta), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) + @counta) + 10, ((@old_y * @map.tilesize) - @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
if @old_y < @y
@image.draw(((@old_x * @map.tilesize) + @counta), ((@old_y * @map.tilesize) + @counta), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) + @counta) + 10, ((@old_y * @map.tilesize) + @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
end
if @old_x == @x
if @old_y > @y
@image.draw(((@old_x * @map.tilesize)), ((@old_y * @map.tilesize) - @counta), 1,1)
@font.draw(self.name, (@x * @map.tilesize) + 10, ((@old_y * @map.tilesize) - @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
if @old_y < @y
@image.draw(((@old_x * @map.tilesize)), ((@old_y * @map.tilesize) + @counta), 1,1)
@font.draw(self.name, (@x * @map.tilesize) + 10, ((@old_y * @map.tilesize) + @counta) + 44, 10, 1.0, 1.0, 0xffffffff)
end
end
if @old_y == @y
if @old_x > @x
@image.draw(((@old_x * @map.tilesize) - @counta), ((@old_y * @map.tilesize)), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) - @counta) + 10, ((@old_y * @map.tilesize)) + 44, 10, 1.0, 1.0, 0xffffffff)
end
if @old_x < @x
@image.draw(((@old_x * @map.tilesize) + @counta), ((@old_y * @map.tilesize)), 1,1)
@font.draw(self.name, ((@old_x * @map.tilesize) + @counta) + 10, ((@old_y * @map.tilesize)) + 44, 10, 1.0, 1.0, 0xffffffff)
end
end
if @old_x == @x && @old_y == @y
@image.draw(@x * @map.tilesize, @y * @map.tilesize, 1,1)
@font.draw(self.name, (@x * @map.tilesize) + 10, (@y * @map.tilesize) + 44, 10, 1.0, 1.0, 0xffffffff)
end
if @counta == @map.tilesize
@moving = false
@counta = 1
end
end
return map
end
def move_spot(type)
x = @x
y = @y
tile = "crap"
until(tile == type)
x = @x
y = @y
x = x + rand(2)
y = y + rand(2)
x = x - rand(2)
y = y - rand(2)
if @map.valid_spot(x,y)
tile = @map.tile(x,y)
end
end
@x = x
@y = y
return "#{x},#{y}"
end
def random_spot(type)
x = 0
y = 0
tile = @map.tile(x,y)
until(tile == type)
x = rand(@map.tiles_across-1)
y = rand(@map.tiles_across-1)
tile = @map.tile(x,y)
end
return "#{x},#{y}"
end
end