@@ -111,15 +111,7 @@ function snakeblocksline:init(x, y, r)
111
111
firstx = self .x - self .length + 1
112
112
end
113
113
local obj = snakeblock :new (firstx , self .y , self , false , self .quadi )
114
- if self .firstdir == " up" then
115
- obj .speedy = - self .speed
116
- elseif self .firstdir == " down" then
117
- obj .speedy = self .speed
118
- elseif self .firstdir == " left" then
119
- obj .speedx = - self .speed
120
- else
121
- obj .speedx = self .speed
122
- end
114
+ self :setstartdir (obj )
123
115
self .movingchild [1 ] = obj
124
116
self .movingchild [1 ].push = true
125
117
table.insert (objects [" snakeblock" ], obj )
@@ -362,6 +354,7 @@ function snakeblocksline:dorespawn()
362
354
self .movingchild [1 ].dy = false
363
355
self .movingchild [1 ].speedx = self .speed
364
356
self .movingchild [1 ].speedy = 0
357
+ self :setstartdir (self .movingchild [1 ])
365
358
self .movingchild [1 ]:move (self .power )
366
359
self .movingchild [1 ].quadi = self .quadi
367
360
self .movingchild [1 ]:setquad ()
@@ -378,6 +371,21 @@ function snakeblocksline:dorespawn()
378
371
self .movingchild [2 ]:setquad ()
379
372
end
380
373
374
+ function snakeblocksline :setstartdir (obj )
375
+ -- first snake block automatically goes right, adjust it to follow to set starting direction
376
+ obj .speedx = 0
377
+ obj .speedy = 0
378
+ if self .firstdir == " up" then
379
+ obj .speedy = - self .speed
380
+ elseif self .firstdir == " down" then
381
+ obj .speedy = self .speed
382
+ elseif self .firstdir == " left" then
383
+ obj .speedx = - self .speed
384
+ else
385
+ obj .speedx = self .speed
386
+ end
387
+ end
388
+
381
389
function snakeblocksline :link ()
382
390
while # self .r >= 3 do
383
391
for j , w in pairs (outputs ) do
0 commit comments