Пример #1
0
 public void draw(SpriteBatch spriteBatch, Sprite sprite, int pixelwidth, int pixelheight, int cellOffsetX, int cellOffsetY)
 {
     int x = (sprite.getPosX() - cellOffsetX) * pixelwidth;
     int y = (sprite.getPosY() - cellOffsetY) * pixelheight;
     int Width = sprite.getWidth() * pixelwidth;
     int Height = sprite.getHeight() * pixelheight;
     Rectangle destination = new Rectangle(x, y, Width, Height);
     x = (sprite.getAnimation().getPosX() * cellWidth) + (sprite.getAnimation().getPosX() * paddingWidth)+1;
     y = (sprite.getAnimation().getPosY() * cellHeight) + (sprite.getAnimation().getPosY() * paddingHeight)+1;
     Width = (sprite.getAnimation().getWidth() * cellWidth)-1;
     Height = (sprite.getAnimation().getHeight() * cellHeight)-1;
     Rectangle source = new Rectangle(x, y, Width, Height);
     spriteBatch.Draw(sheet, destination, source, Color.White);
 }
Пример #2
0
    public void checkObjectCollision(Sprite Object,int x, int y)
    {
        Object.setPosX(Object.getPosX() + x);

        Dictionary<String, Sprite> sprites = map.getSprites();

        foreach(var pair in sprites)
        {
            if (pair.Value.wouldCollide(Object) && pair.Key.ToString().ToLower() != Object.getIdentifier().ToLower())
            {
                Object.setPosX(Object.getPosX() - x);
                break;
            }
        }

        Object.setPosY(Object.getPosY() + y);
        foreach (var pair in sprites)
        {
            if (pair.Value.wouldCollide(Object) && pair.Key.ToString().ToLower() != Object.getIdentifier().ToLower())
            {
                Object.setPosY(Object.getPosY() - y);
                break;
            }
        }
    }