Merge branch 'fix-lag' into 'master'
Fix lag when monsters try to move in a random direction Closes #25 See merge request ynerant/squirrel-battle!32
This commit was merged in pull request #113.
	This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
 | 
			
		||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
from random import choice
 | 
			
		||||
from random import shuffle
 | 
			
		||||
 | 
			
		||||
from .player import Player
 | 
			
		||||
from ..interfaces import FightingEntity, Map
 | 
			
		||||
@@ -49,9 +49,13 @@ class Monster(FightingEntity):
 | 
			
		||||
            if not moved and self.distance_squared(target) <= 1:
 | 
			
		||||
                self.map.logs.add_message(self.hit(target))
 | 
			
		||||
        else:
 | 
			
		||||
            for _ in range(100):
 | 
			
		||||
                if choice([self.move_up, self.move_down,
 | 
			
		||||
                          self.move_left, self.move_right])():
 | 
			
		||||
            # Move in a random direction
 | 
			
		||||
            # If the direction is not available, try another one
 | 
			
		||||
            moves = [self.move_up, self.move_down,
 | 
			
		||||
                     self.move_left, self.move_right]
 | 
			
		||||
            shuffle(moves)
 | 
			
		||||
            for move in moves:
 | 
			
		||||
                if move():
 | 
			
		||||
                    break
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user